From 21c3c3946d3253c5166e958453bb1324063208d3 Mon Sep 17 00:00:00 2001 From: kdeme Date: Fri, 14 Jun 2019 10:50:17 +0200 Subject: [PATCH] Fix another Assertion + change error pragma to fatal --- eth/common/eth_types.nim | 10 +++++++--- eth/rlp.nim | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/eth/common/eth_types.nim b/eth/common/eth_types.nim index 1e494fb..f66c82a 100644 --- a/eth/common/eth_types.nim +++ b/eth/common/eth_types.nim @@ -230,7 +230,11 @@ proc read*(rlp: var Rlp, T: typedesc[StUint]): T {.inline.} = if rlp.isBlob: let bytes = rlp.toBytes if bytes.len > 0: - result.initFromBytesBE(bytes.toOpenArray) + # be sure the amount of bytes matches the size of the stint + if bytes.len <= sizeof(result): + result.initFromBytesBE(bytes.toOpenArray) + else: + raise newException(RlpTypeMismatch, "Unsigned integer expected, but the source RLP has the wrong length") else: result = 0.to(T) else: @@ -250,13 +254,13 @@ proc append*(rlpWriter: var RlpWriter, value: StUint) = proc read*(rlp: var Rlp, T: typedesc[Stint]): T {.inline.} = # The Ethereum Yellow Paper defines the RLP serialization only # for unsigned integers: - {.error: "RLP serialization of signed integers is not allowed".} + {.fatal: "RLP serialization of signed integers is not allowed".} discard proc append*(rlpWriter: var RlpWriter, value: Stint) = # The Ethereum Yellow Paper defines the RLP serialization only # for unsigned integers: - {.error: "RLP serialization of signed integers is not allowed".} + {.fatal: "RLP serialization of signed integers is not allowed".} discard proc read*(rlp: var Rlp, t: var Transaction, _: type EthAddress): EthAddress {.inline.} = diff --git a/eth/rlp.nim b/eth/rlp.nim index 96e5129..51c46be 100644 --- a/eth/rlp.nim +++ b/eth/rlp.nim @@ -320,7 +320,7 @@ proc readImpl[R, E](rlp: var Rlp, T: type array[R, E]): T = var bytes = rlp.toBytes if result.len != bytes.len: - raise newException(RlpTypeMismatch, "Fixed-size array expected, but the source RLP contains a blob of different lenght") + raise newException(RlpTypeMismatch, "Fixed-size array expected, but the source RLP contains a blob of different length") copyMem(addr result[0], bytes.baseAddr, bytes.len)