diff --git a/libraries/chain/include/golos/chain/steem_object_types.hpp b/libraries/chain/include/golos/chain/steem_object_types.hpp index 69cd50c4b0..9e7aa6a0f4 100644 --- a/libraries/chain/include/golos/chain/steem_object_types.hpp +++ b/libraries/chain/include/golos/chain/steem_object_types.hpp @@ -172,7 +172,7 @@ namespace fc { } template - inline void unpack(Stream &s, chainbase::object_id &id) { + inline void unpack(Stream &s, chainbase::object_id &id, uint32_t = 0) { s.read((char *)&id._id, sizeof(id._id)); } } @@ -189,16 +189,16 @@ namespace fc { } template - inline void unpack(const golos::chain::buffer_type &raw, T &v) { + inline void unpack(const golos::chain::buffer_type &raw, T &v, uint32_t depth = 0) { datastream ds(raw.data(), raw.size()); - unpack(ds, v); + unpack(ds, v, depth); } template - inline T unpack(const golos::chain::buffer_type &raw) { + inline T unpack(const golos::chain::buffer_type &raw, uint32_t depth = 0) { T v; datastream ds(raw.data(), raw.size()); - unpack(ds, v); + unpack(ds, v, depth); return v; } } diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index c76404f7f4..545d55c44c 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -314,5 +314,97 @@ BOOST_FIXTURE_TEST_SUITE(serialization_tests, clean_database_fixture) FC_LOG_AND_RETHROW(); } +BOOST_AUTO_TEST_CASE(unpack_clear_test) { try { + std::stringstream ss1; + std::stringstream ss2; + + signed_block b1; + + for (int i = 0; i < 10; i++) { + signed_transaction tx; + + vote_operation op; + op.voter = "alice"; + op.author = "bob"; + op.permlink = "permlink1"; + op.weight = STEEMIT_100_PERCENT; + tx.operations.push_back(op); + + vote_operation op2; + op2.voter = "charlie"; + op2.author = "sam"; + op2.permlink = "permlink2"; + op2.weight = STEEMIT_100_PERCENT; + tx.operations.push_back(op2); + + tx.ref_block_num = 1000; + tx.ref_block_prefix = 1000000000; + tx.expiration = fc::time_point_sec(1514764800 + i); + + b1.transactions.push_back(tx); + } + + signed_block b2; + + for (int i = 0; i < 20; i++) { + signed_transaction tx; + vote_operation op; + op.voter = "dave"; + op.author = "greg"; + op.permlink = "foobar"; + op.weight = STEEMIT_100_PERCENT/2; + tx.ref_block_num = 4000; + tx.ref_block_prefix = 4000000000; + tx.expiration = fc::time_point_sec(1714764800 + i); + tx.operations.push_back(op); + + b2.transactions.push_back(tx); + } + + fc::raw::pack(ss2, b2); + fc::raw::pack(ss1, b1); + + signed_block unpacked_block; + fc::raw::unpack(ss2, unpacked_block); + + // This operation should completely overwrite signed block 'b2' + fc::raw::unpack(ss1, unpacked_block); + + BOOST_REQUIRE(b1.transactions.size() == unpacked_block.transactions.size()); + for (size_t i = 0; i < unpacked_block.transactions.size(); i++) { + signed_transaction tx = unpacked_block.transactions[i]; + BOOST_REQUIRE(unpacked_block.transactions[i].operations.size() == b1.transactions[i].operations.size()); + + vote_operation op = tx.operations[0].get(); + BOOST_REQUIRE(op.voter == "alice"); + BOOST_REQUIRE(op.author == "bob"); + BOOST_REQUIRE(op.permlink == "permlink1"); + BOOST_REQUIRE(op.weight == STEEMIT_100_PERCENT); + + vote_operation op2 = tx.operations[1].get(); + BOOST_REQUIRE(op2.voter == "charlie"); + BOOST_REQUIRE(op2.author == "sam"); + BOOST_REQUIRE(op2.permlink == "permlink2"); + BOOST_REQUIRE(op2.weight == STEEMIT_100_PERCENT); + + BOOST_REQUIRE(tx.ref_block_num == 1000); + BOOST_REQUIRE(tx.ref_block_prefix == 1000000000); + BOOST_REQUIRE(tx.expiration == fc::time_point_sec(1514764800 + i)); + } +} FC_LOG_AND_RETHROW(); } + +BOOST_AUTO_TEST_CASE(unpack_recursion_test) { try { + std::stringstream ss; + int recursion_level = 100000; + uint64_t allocation_per_level = 500000; + for (int i = 0; i < recursion_level; i++) { + fc::raw::pack(ss, unsigned_int(allocation_per_level)); + fc::raw::pack(ss, static_cast(variant::array_type)); + } + std::vector v; + STEEMIT_REQUIRE_THROW(fc::raw::unpack(ss, v), fc::assert_exception); +} FC_LOG_AND_RETHROW(); } + + BOOST_AUTO_TEST_SUITE_END() #endif diff --git a/thirdparty/fc b/thirdparty/fc index afa113d86e..ca64acb909 160000 --- a/thirdparty/fc +++ b/thirdparty/fc @@ -1 +1 @@ -Subproject commit afa113d86e1e7ba91c62e9fe256de921f375b608 +Subproject commit ca64acb909f6c9fabdca1b07e0729eb2181e5eaf