Browse Source

RLP length with first zeros

cl-refactor
winsvega 10 years ago
parent
commit
a90c45a3ee
  1. 4
      libdevcore/RLP.cpp
  2. 2
      libdevcore/RLP.h

4
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];

2
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.

Loading…
Cancel
Save