Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Zero length binary values should not be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
vcabbage committed Jul 16, 2019
1 parent de9a8ae commit ad1b5de
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ func readBinary(r *buffer) ([]byte, error) {
return nil, errorErrorf("type code %#02x is not a recognized binary type", type_)
}

if length == 0 {
// An empty value and a nil value are distinct,
// ensure that the returned value is not nil in this case.
return make([]byte, 0), nil
}

buf, ok := r.next(length)
if !ok {
return nil, errorNew("invalid length")
Expand Down

0 comments on commit ad1b5de

Please sign in to comment.