From a90c45a3ee4c937bac25b9dd4aace1160b9c3cc8 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 16 Apr 2015 16:32:15 +0300 Subject: [PATCH] RLP length with first zeros --- libdevcore/RLP.cpp | 4 ++-- libdevcore/RLP.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdevcore/RLP.cpp b/libdevcore/RLP.cpp index 994aac265..2a1c34030 100644 --- a/libdevcore/RLP.cpp +++ b/libdevcore/RLP.cpp @@ -149,7 +149,7 @@ unsigned RLP::length() const return n - c_rlpDataImmLenStart; else if (n < c_rlpListStart) { - if ((int)m_data.size() <= n - c_rlpDataIndLenZero) + if ((int)m_data.size() <= n - c_rlpDataIndLenZero || m_data[1] == 0) BOOST_THROW_EXCEPTION(BadRLP()); for (int i = 0; i < n - c_rlpDataIndLenZero; ++i) ret = (ret << 8) | m_data[i + 1]; @@ -158,7 +158,7 @@ unsigned RLP::length() const return n - c_rlpListStart; else { - if ((int)m_data.size() <= n - c_rlpListIndLenZero) + if ((int)m_data.size() <= n - c_rlpListIndLenZero || m_data[1] == 0) BOOST_THROW_EXCEPTION(BadRLP()); for (int i = 0; i < n - c_rlpListIndLenZero; ++i) ret = (ret << 8) | m_data[i + 1]; diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index caaf10b6a..7e765d395 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -303,7 +303,7 @@ private: /// Single-byte data payload. bool isSingleByte() const { return !isNull() && m_data[0] < c_rlpDataImmLenStart; } - /// @returns the bytes used to encode the length of the data. Valid for all types. + /// @returns the amount of bytes used to encode the length of the data. Valid for all types. unsigned lengthSize() const { if (isData() && m_data[0] > c_rlpDataIndLenZero) return m_data[0] - c_rlpDataIndLenZero; if (isList() && m_data[0] > c_rlpListIndLenZero) return m_data[0] - c_rlpListIndLenZero; return 0; } /// @returns the size in bytes of the payload, as given by the RLP as opposed to as inferred from m_data.