From d24a15794775413e164e86e0ef0307a55fb6f78d Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Mon, 17 Jun 2019 15:58:20 -0500 Subject: [PATCH] Addressed review feedback --- roaring/fuzz_test.go | 2 +- roaring/roaring.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/roaring/fuzz_test.go b/roaring/fuzz_test.go index b11d00337..69362d947 100644 --- a/roaring/fuzz_test.go +++ b/roaring/fuzz_test.go @@ -30,7 +30,7 @@ func TestUnmarshalBinary(t *testing.T) { { cr : []byte("<0\x000\x00\x00\x00\x00000000000000" + "0"), //"<000000000000000" - expected : "unmarshaling as pilosa roaring: too big", + expected : "unmarshaling as pilosa roaring: Maximum operation size exceeded", }, } diff --git a/roaring/roaring.go b/roaring/roaring.go index db2910a8e..e10793915 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -3944,7 +3944,7 @@ func (op *op) WriteTo(w io.Writer) (n int64, err error) { } var minOpSize = 13 -var maxOpN = 1000000 +var maxBatchSize = 1<<59 // UnmarshalBinary decodes data into an op. func (op *op) UnmarshalBinary(data []byte) error { @@ -3962,7 +3962,9 @@ func (op *op) UnmarshalBinary(data []byte) error { _, _ = h.Write(data[0:9]) if op.typ > 1 { - if maxOpN < int(op.value){ + // This ensures that in doing 13+op.value*8, the max int won't be exceeded and a wrap around case + // (resulting in a negative value) won't occur in the slice indexing while writing + if int(op.value) > maxBatchSize { return fmt.Errorf("Maximum operation size exceeded") } if len(data) < int(13+op.value*8) {