Fix AssertionError on ByteRange slice with nonexistent position

This commit is contained in:
kdeme 2019-10-10 13:14:24 +02:00
parent 9b69910570
commit 903b72a5c8
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
1 changed files with 8 additions and 1 deletions

View File

@ -272,7 +272,14 @@ iterator items*(self: var Rlp): var Rlp =
position = elemEnd
proc listElem*(self: Rlp, i: int): Rlp =
let payload = bytes.slice(position + payloadOffset())
let
payloadOffset = payloadOffset()
# This will only check if there is some data, not if it is correct according
# to list length. Could also run here payloadBytesCount() instead.
if position + payloadOffset + 1 > bytes.len: eosError()
let payload = bytes.slice(position + payloadOffset)
result = rlpFromBytes payload
var pos = 0
while pos < i and result.hasData: