diff options
author | Felix Lange <fjl@twurst.com> | 2015-07-18 07:47:17 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-07-18 07:47:17 +0800 |
commit | cefd948267c6d16b317f7c15feb653a7725a3f1b (patch) | |
tree | 5fccf3189e1decc3b7c58ae9ff2d1a5c866fd0dc /rlp/decode.go | |
parent | 593b1b65e76bf1f92249078e45a97ee21b58778c (diff) | |
download | go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.tar go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.tar.gz go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.tar.bz2 go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.tar.lz go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.tar.xz go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.tar.zst go-tangerine-cefd948267c6d16b317f7c15feb653a7725a3f1b.zip |
rlp: reject trailing data when using DecodeBytes
Diffstat (limited to 'rlp/decode.go')
-rw-r--r-- | rlp/decode.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/rlp/decode.go b/rlp/decode.go index 4462d4be4..f17690522 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -110,9 +110,17 @@ func Decode(r io.Reader, val interface{}) error { // DecodeBytes parses RLP data from b into val. // Please see the documentation of Decode for the decoding rules. +// The input must contain exactly one value and no trailing data. func DecodeBytes(b []byte, val interface{}) error { // TODO: this could use a Stream from a pool. - return NewStream(bytes.NewReader(b), uint64(len(b))).Decode(val) + r := bytes.NewReader(b) + if err := NewStream(r, uint64(len(b))).Decode(val); err != nil { + return err + } + if r.Len() > 0 { + return ErrMoreThanOneValue + } + return nil } type decodeError struct { @@ -517,6 +525,10 @@ var ( ErrElemTooLarge = errors.New("rlp: element is larger than containing list") ErrValueTooLarge = errors.New("rlp: value size exceeds available input length") + // This error is reported by DecodeBytes if the slice contains + // additional data after the first RLP value. + ErrMoreThanOneValue = errors.New("rlp: input contains more than one value") + // internal errors errNotInList = errors.New("rlp: call of ListEnd outside of any list") errNotAtEOL = errors.New("rlp: call of ListEnd not positioned at EOL") |