diff --git a/bin/bytes.go b/bin/bytes.go index 8869c7dcc1..ffaaf1f829 100644 --- a/bin/bytes.go +++ b/bin/bytes.go @@ -48,7 +48,7 @@ func decodeBytes(b []byte) (n int, v []byte, err error) { if len(b[1:]) < int(vLen) { return 0, nil, io.ErrUnexpectedEOF } - if vLen >= maxSmallStringLength { + if vLen > maxSmallStringLength { return 0, nil, errors.New("invalid length") } return nearestPaddedValueLength(int(vLen) + 1), b[1 : vLen+1], nil diff --git a/bin/bytes_test.go b/bin/bytes_test.go index 5fd7d97733..cff791c5f5 100644 --- a/bin/bytes_test.go +++ b/bin/bytes_test.go @@ -23,6 +23,7 @@ func TestBytesDecodeEncode(t *testing.T) { 0x20, 0x75, 0x70, 0x2c, 0x20, 0x4e, 0x65, 0x6f, }, + bytes.Repeat([]byte{1}, 253), } { buf := encodeBytes(nil, b) if len(buf)%4 != 0 { diff --git a/bin/string.go b/bin/string.go index d21156624e..4104a7bb5d 100644 --- a/bin/string.go +++ b/bin/string.go @@ -53,7 +53,7 @@ func decodeString(b []byte) (n int, v string, err error) { if len(b) < (int(strLen) + 1) { return 0, "", io.ErrUnexpectedEOF } - if strLen >= maxSmallStringLength { + if strLen > maxSmallStringLength { return 0, "", errors.New("invalid length") } return nearestPaddedValueLength(int(strLen) + 1), string(b[1 : strLen+1]), nil diff --git a/bin/string_test.go b/bin/string_test.go index 02223d03c0..1a794c0a95 100644 --- a/bin/string_test.go +++ b/bin/string_test.go @@ -18,6 +18,7 @@ func TestStringDecodeEncode(t *testing.T) { "ba", "what are you doing?", "кек", + strings.Repeat("a", 253), } { buf := encodeString(nil, s) if len(buf)%4 != 0 {