Implemented previous fixes not present

This commit is contained in:
Ashley Svetlik 2019-06-19 13:38:23 -05:00
parent 8c264d9249
commit 2df44eecfd
2 changed files with 7 additions and 1 deletions

View file

@ -30,7 +30,7 @@ func TestUnmarshalBinary(t *testing.T) {
{
cr : []byte("<0\x000\x00\x00\x00\x00000000000000" +
"0"), //"<000000000000000"
expected : "unmarshaling as pilosa roaring: too big",
expected : "unmarshaling as pilosa roaring: Maximum operation size exceeded",
},
}

View file

@ -3944,6 +3944,7 @@ func (op *op) WriteTo(w io.Writer) (n int64, err error) {
}
var minOpSize = 13
var maxBatchSize = uint64(1<<59)
// UnmarshalBinary decodes data into an op.
func (op *op) UnmarshalBinary(data []byte) error {
@ -3961,6 +3962,11 @@ func (op *op) UnmarshalBinary(data []byte) error {
_, _ = h.Write(data[0:9])
if op.typ > 1 {
// 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")
}
if len(data) < int(13+op.value*8) {
return fmt.Errorf("op data truncated - expected %d, got %d", 13+op.value*8, len(data))
}