Merge branch 'master' of https://github.com/pilosa/pilosa into fuzz-roaring

This commit is contained in:
shaqque 2019-06-25 11:22:47 -05:00
commit 7ba9e18a51
2 changed files with 22 additions and 2 deletions

View file

@ -57,6 +57,15 @@ func TestUnmarshalBinary(t *testing.T) {
cr: []byte("<0\x00\x02\x03\x00\x00\x00쳫\v\x00d9\v\x00\x009\v"), //<0쳫 d9 9
expected: "unmarshaling as pilosa roaring: malformed bitmap, key-cardinality not provided for 0 containers",
},
{ // Checks for incomplete offset in readWithRuns
cr: []byte(";0\x000\v00000"), //";00 00000"
expected: "reading offsets from official roaring format: offset incomplete: len=10",
},
{ // Checks for incomplete offset in readOffsets
cr: []byte(":0\x000\x03\x00\x00\x00000000000000" +
"\x00"), //:0000000000000
expected: "reading offsets from official roaring format: offset incomplete: len=1",
},
}
for _, crash := range confirmedCrashers {

View file

@ -4576,7 +4576,10 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
// Read container offsets and attach data.
if haveRuns {
readWithRuns(b, data, pos, keyN)
err := readWithRuns(b, data, pos, keyN)
if err != nil {
return errors.Wrap(err, "reading offsets from official roaring format")
}
} else {
err := readOffsets(b, data, pos, keyN)
if err != nil {
@ -4590,6 +4593,10 @@ func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) error {
citer, _ := b.Containers.Iterator(0)
for i, buf := 0, data[pos:]; i < int(keyN); i, buf = i+1, buf[4:] {
// Verify the offset is fully formed
if len(buf) < 4 {
return fmt.Errorf("offset incomplete: len=%d", len(buf))
}
offset := binary.LittleEndian.Uint32(buf[0:4])
// Verify the offset is within the bounds of the input data.
if int(offset) >= len(data) {
@ -4611,7 +4618,10 @@ func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) error {
return nil
}
func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) {
func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) error {
if len(data) < pos+runCountHeaderSize {
return fmt.Errorf("offset incomplete: len=%d", len(data))
}
citer, _ := b.Containers.Iterator(0)
for i := 0; i < int(keyN); i++ {
citer.Next()
@ -4634,6 +4644,7 @@ func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) {
pos += bitmapN * 8
}
}
return nil
}
// handledIter and handledIters are wrappers around Bitmap Container iterators