Skip to content

Commit

Permalink
fix(bin): handle strings with 253 len
Browse files Browse the repository at this point in the history
Fix #106
  • Loading branch information
ernado committed Jan 4, 2021
1 parent de6ce25 commit 9f36bd1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bin/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bin/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bin/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9f36bd1

Please sign in to comment.