diff --git a/types/encoding.go b/types/encoding.go index 59d55169..35ad5935 100644 --- a/types/encoding.go +++ b/types/encoding.go @@ -181,12 +181,12 @@ func (d *Decoder) ReadUint64() uint64 { } // ReadPrefix reads a length prefix from the underlying stream. If the length -// exceeds the number of bytes remaining in the stream, ReadPrefix sets d.Err +// exceeds the maximum number of elements, ReadPrefix sets d.Err // and returns 0. -func (d *Decoder) ReadPrefix(max int64) int { +func (d *Decoder) ReadPrefix(limit int64) int { n := d.ReadUint64() - if n > uint64(max) { - d.SetErr(fmt.Errorf("encoded object contains invalid length prefix (%v elems > %v elems)", n, max)) + if n > uint64(limit) { + d.SetErr(fmt.Errorf("encoded object contains invalid length prefix (%v elems > %v elems)", n, limit)) return 0 } return int(n)