diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index 34a0fc65f..a538fac21 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -242,7 +242,9 @@ public: AllowNonCanon = 1, ThrowOnFail = 4, FailIfTooBig = 8, + FailIfTooSmall = 16, Strict = ThrowOnFail | FailIfTooBig, + VeryStrict = ThrowOnFail | FailIfTooBig | FailIfTooSmall, LaisezFaire = AllowNonCanon }; @@ -269,7 +271,7 @@ public: template _N toHash(int _flags = Strict) const { - if (!isData() || (length() > _N::size && (_flags & FailIfTooBig))) + if (!isData() || (length() > _N::size && (_flags & FailIfTooBig)) || (length() < _N::size && (_flags & FailIfTooSmall))) if (_flags & ThrowOnFail) BOOST_THROW_EXCEPTION(BadCast()); else diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 345e379af..96689326d 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -40,7 +40,7 @@ Transaction::Transaction(bytesConstRef _rlpData, CheckSignature _checkSig) m_gasPrice = rlp[field = 1].toInt(); m_gas = rlp[field = 2].toInt(); m_type = rlp[field = 3].isEmpty() ? ContractCreation : MessageCall; - m_receiveAddress = rlp[field = 3].toHash
(); + m_receiveAddress = rlp[field = 3].isEmpty() ? Address() : rlp[field = 3].toHash
(RLP::VeryStrict); m_value = rlp[field = 4].toInt(); m_data = rlp[field = 5].toBytes(); byte v = rlp[field = 6].toInt() - 27; diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index ff6939a5f..71d381030 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -475,11 +475,11 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun } catch (Exception const& _e) { - BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e)); + BOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e)); } catch (std::exception const& _e) { - BOOST_ERROR("Failed test with Exception: " << _e.what()); + BOOST_ERROR("Failed filling test with Exception: " << _e.what()); } break; } diff --git a/test/transaction.cpp b/test/transaction.cpp index 7bd8ac20c..6ebe62754 100644 --- a/test/transaction.cpp +++ b/test/transaction.cpp @@ -51,7 +51,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) catch(...) { BOOST_CHECK_MESSAGE(o.count("transaction") == 0, "A transaction object should not be defined because the RLP is invalid!"); - return; + continue; } BOOST_REQUIRE(o.count("transaction") > 0); @@ -108,6 +108,11 @@ BOOST_AUTO_TEST_CASE(TransactionTest) dev::test::executeTests("ttTransactionTest", "/TransactionTests", dev::test::doTransactionTests); } +BOOST_AUTO_TEST_CASE(ttWrongRLPTransaction) +{ + dev::test::executeTests("ttWrongRLPTransaction", "/TransactionTests", dev::test::doTransactionTests); +} + BOOST_AUTO_TEST_CASE(tt10mbDataField) { dev::test::executeTests("tt10mbDataField", "/TransactionTests", dev::test::doTransactionTests);