From ad1b5de89c76150682c92e06cba5a7024f122f14 Mon Sep 17 00:00:00 2001 From: Kale Blankenship Date: Mon, 15 Jul 2019 15:07:46 -0700 Subject: [PATCH] Zero length binary values should not be nil --- decode.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/decode.go b/decode.go index 83d60559..fd9db8db 100644 --- a/decode.go +++ b/decode.go @@ -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")