diff --git a/libdevcore/RLP.cpp b/libdevcore/RLP.cpp index 25e843c77..846664cfd 100644 --- a/libdevcore/RLP.cpp +++ b/libdevcore/RLP.cpp @@ -166,6 +166,9 @@ unsigned RLP::length() const { if ((int)m_data.size() <= n - c_rlpDataIndLenZero) BOOST_THROW_EXCEPTION(BadRLP()); + if ((int)m_data.size() > 1) + if (m_data[1] == 0) + BOOST_THROW_EXCEPTION(BadRLP()); for (int i = 0; i < n - c_rlpDataIndLenZero; ++i) ret = (ret << 8) | m_data[i + 1]; } @@ -175,6 +178,9 @@ unsigned RLP::length() const { if ((int)m_data.size() <= n - c_rlpListIndLenZero) BOOST_THROW_EXCEPTION(BadRLP()); + if ((int)m_data.size() > 1) + if (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 c99d1a358..ac5e2ef1e 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -308,7 +308,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.