Skip to content

Commit

Permalink
decode: reject strings with negative length
Browse files Browse the repository at this point in the history
Found running go-fuzz.
  • Loading branch information
pmezard committed Aug 16, 2015
1 parent fb5f6a1 commit 6312312
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ func (d *Decoder) decodeString(v reflect.Value) error {
if err != nil {
return err
}
if l < 0 {
return fmt.Errorf("invalid negative string length: %d", l)
}

//read exactly l bytes out and make our string
buf := make([]byte, l)
Expand Down
1 change: 1 addition & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestDecode(t *testing.T) {
{`di5ei2ee`, new(interface{}), nil, true},
{`d3:fooe`, new(interface{}), nil, true},
{`l3:foo3:bar`, new(interface{}), nil, true},
{`d3:000d3:000ld-6:`, new(interface{}), nil, true},
}

for i, tt := range decodeCases {
Expand Down

0 comments on commit 6312312

Please sign in to comment.