From 7f1763e466abd0b8cb73c9c3b7da2312ef989b9b Mon Sep 17 00:00:00 2001 From: Seebs Date: Tue, 25 Jun 2019 14:29:25 -0500 Subject: [PATCH] address fuzz testing for new op types The new op type code changed the failure mode for one of the fuzz test issues -- and the fuzz test revealed a bug in the code. Fixed the code, updated the test to expect the newer, better, message. Also fixed capitalization on the old message. --- roaring/fuzz_test.go | 2 +- roaring/roaring.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/roaring/fuzz_test.go b/roaring/fuzz_test.go index e56d3f0ce..da74202f0 100644 --- a/roaring/fuzz_test.go +++ b/roaring/fuzz_test.go @@ -30,7 +30,7 @@ func TestUnmarshalBinary(t *testing.T) { { // Checks for int overflow cr: []byte("<0\x000\x00\x00\x00\x00000000000000" + "0"), //"<000000000000000" - expected: "unmarshaling as pilosa roaring: Maximum operation size exceeded", + expected: "unmarshaling as pilosa roaring: unknown op type: 48", }, { // The next 5 check for malformed bitmaps cr: []byte("<0\x0000000000000000000" + diff --git a/roaring/roaring.go b/roaring/roaring.go index 28892af6a..ab48cf338 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -4306,11 +4306,13 @@ func (op *op) UnmarshalBinary(data []byte) error { _, _ = h.Write(data[0:9]) switch op.typ { + case 0, 1: + // nothing to do, just being not-default case 2, 3: // 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 op.value > maxBatchSize { - return fmt.Errorf("Maximum operation size exceeded") + return fmt.Errorf("maximum operation size exceeded") } if len(data) < int(13+op.value*8) { return fmt.Errorf("op data truncated - expected %d, got %d", 13+op.value*8, len(data)) @@ -4330,6 +4332,8 @@ func (op *op) UnmarshalBinary(data []byte) error { op.roaring = data[17 : 17+op.value] _, _ = h.Write(data[13 : 17+op.value]) // op.value = 0 + default: + return fmt.Errorf("unknown op type: %d", op.typ) } if chk := binary.LittleEndian.Uint32(data[9:13]); chk != h.Sum32() { return fmt.Errorf("checksum mismatch: type %d, exp=%08x, got=%08x", op.typ, h.Sum32(), chk)