Skip to content

Commit

Permalink
Merge pull request #15 from pmezard/fix-decoding-error
Browse files Browse the repository at this point in the history
decode: reject strings with negative length
  • Loading branch information
zeebo committed Aug 18, 2015
2 parents fb5f6a1 + b49e5f9 commit a0e3ea0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Casey Bodley <[email protected]>
Conrad Pankoff <[email protected]>
Cenk Alti <[email protected]>
Jan Winkelmann <[email protected]>
Patrick Mézard <[email protected]>
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},
{`d-1:`, new(interface{}), nil, true},
}

for i, tt := range decodeCases {
Expand Down

0 comments on commit a0e3ea0

Please sign in to comment.