prevent panic in Bitmap.UnmarshalBinary when there is no data

This commit is contained in:
Yuce Tekol 2018-11-15 22:06:21 +03:00
parent faac64dc99
commit 70f85211d9
No known key found for this signature in database
GPG key ID: CB59E46D2FB90573
3 changed files with 9 additions and 3 deletions

4
api.go
View file

@ -268,6 +268,10 @@ func setUpImportOptions(opts ...ImportOption) (*ImportOptions, error) {
// of the rows in this shard of this field concatenated together in one long
// bitmap.
func (api *API) ImportRoaring(ctx context.Context, indexName, fieldName string, shard uint64, remote bool, data []byte, opts ...ImportOption) (err error) {
if len(data) == 0 {
return errors.New("no data to import")
}
if err = api.validate(apiField); err != nil {
return errors.Wrap(err, "validating api method")
}

View file

@ -25,6 +25,7 @@ import (
"hash"
"io"
"io/ioutil"
"math"
"os"
"sort"
"sync"
@ -33,9 +34,6 @@ import (
"unsafe"
"github.com/cespare/xxhash"
"math"
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/pql"

View file

@ -3465,6 +3465,10 @@ func readOfficialHeader(buf []byte) (size uint32, containerTyper func(index uint
// UnmarshalBinary decodes b from a binary-encoded byte slice. data can be in
// either official roaring format or Pilosa's roaring format.
func (b *Bitmap) UnmarshalBinary(data []byte) error {
if data == nil {
// Nothing to unmarshal
return nil
}
fileMagic := uint32(binary.LittleEndian.Uint16(data[0:2]))
if fileMagic == magicNumber { // if pilosa roaring
return errors.Wrap(b.unmarshalPilosaRoaring(data), "unmarshaling as pilosa roaring")