actually, lets fix it in readAheadCheck

This commit is contained in:
kdeme 2019-05-31 14:43:28 +02:00 committed by zah
parent f40bf032ba
commit ee27111e2b
2 changed files with 13 additions and 14 deletions

View File

@ -109,7 +109,7 @@ proc payloadOffset(self: Rlp): int =
template readAheadCheck(numberOfBytes) =
# important to add nothing to the left side of the equation as `numberOfBytes`
# can in theory be at max size of its type already
if numberOfBytes >= bytes.len - position: eosError()
if numberOfBytes > bytes.len - position - payloadOffset(): eosError()
template nonCanonicalNumberError =
raise newException(MalformedRlpError, "Small number encoded in a non-canonical way")
@ -212,10 +212,6 @@ proc toString*(self: Rlp): string =
let
payloadOffset = payloadOffset()
payloadLen = payloadBytesCount()
remainingBytes = bytes.len - position - payloadOffset
if payloadLen > remainingBytes:
eosError()
result = newString(payloadLen)
for i in 0 ..< payloadLen:
@ -227,13 +223,7 @@ proc toBytes*(self: Rlp): BytesRange =
raise newException(RlpTypeMismatch,
"Bytes expected, but the source RLP in not a blob")
let
payloadLen = payloadBytesCount()
payloadOffset = payloadOffset()
remainingBytes = bytes.len - position - payloadOffset
if payloadLen > remainingBytes:
eosError()
let payloadLen = payloadBytesCount()
if payloadLen > 0:
let

View File

@ -36,7 +36,7 @@
"bytesShouldBeSingleByte01": {
"in": "INVALID",
"out": "8100"
"out": "8101"
},
"bytesShouldBeSingleByte7F": {
@ -82,6 +82,15 @@
"fakelonglistinlist2": {
"in": "INVALID",
"out": "f2ff80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
}
},
"smallblob1byteshort": {
"in": "INVALID",
"out": "82ff"
},
"longblob1byteshort": {
"in": "INVALID",
"out": "b840ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
}
}