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

View File

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