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.
This commit is contained in:
Seebs 2019-06-25 14:29:25 -05:00 • committed by Matt Jaffee
parent c19b7af0d0
commit 7f1763e466
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 6 additions and 2 deletions

View file

@ -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" +

View file

@ -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)