Skip to content

Commit

Permalink
rlp: fix string size check in readKind (#15625)
Browse files Browse the repository at this point in the history
Issue found by @guidovranken
  • Loading branch information
fjl authored Dec 11, 2017
1 parent e7610ea commit 2499b1b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rlp/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func readKind(buf []byte) (k Kind, tagsize, contentsize uint64, err error) {
tagsize = 1
contentsize = uint64(b - 0x80)
// Reject strings that should've been single bytes.
if contentsize == 1 && buf[1] < 128 {
if contentsize == 1 && len(buf) > 1 && buf[1] < 128 {
return 0, 0, 0, ErrCanonSize
}
case b < 0xC0:
Expand Down
1 change: 1 addition & 0 deletions rlp/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestSplit(t *testing.T) {
{input: "F90055", err: ErrCanonSize, rest: "F90055"},
{input: "FA0002FFFF", err: ErrCanonSize, rest: "FA0002FFFF"},

{input: "81", err: ErrValueTooLarge, rest: "81"},
{input: "8501010101", err: ErrValueTooLarge, rest: "8501010101"},
{input: "C60607080902", err: ErrValueTooLarge, rest: "C60607080902"},

Expand Down

0 comments on commit 2499b1b

Please sign in to comment.