diff --git a/roaring/roaring.go b/roaring/roaring.go index f09667104..d66e7ba61 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -1095,7 +1095,7 @@ func (b *Bitmap) writeToUnoptimized(w io.Writer) (n int64, err error) { // unmarshalPilosaRoaring treats data as being encoded in Pilosa's 64 bit // roaring format and decodes it into b. func (b *Bitmap) unmarshalPilosaRoaring(data []byte) error { - if len(data) < headerBaseSize { + if len(data) <= headerBaseSize { return errors.New("data too small") } diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 7a0a473e0..d2affe3a1 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3312,14 +3312,18 @@ func TestUnmarshalRoaringWithErrors(t *testing.T) { hexString string expectedError string }{ - { // Checks a bitmap without runs and no containers + { // Runs a bitmap without runs and no containers through the official roaring hexString : "3A30000000000000", expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 8", }, - { // Checks a bitmap with runs and no containers + { // Runs a bitmap with runs and no containers through the official roaring hexString : "3B30000000000000", expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 9", }, + { // Runs a bitmap in the Pilosa format through the Pilosa roaring + hexString : "3C30000000000000", + expectedError : "unmarshaling as pilosa roaring: data too small", + }, } for _, loopContainers := range noContainers { zeroContainers, _ := hex.DecodeString(loopContainers.hexString)