Skip to content

Commit

Permalink
Merge pull request #3198 from steemit/20181206-fc-unpack-fixes-stable
Browse files Browse the repository at this point in the history
FC unpack fixes (stable)
  • Loading branch information
sgerbino authored Dec 10, 2018
2 parents a82e698 + c58bf22 commit 71aa014
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 190 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/include/steem/chain/steem_object_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace fc
s.write( (const char*)&id._id, sizeof(id._id) );
}
template<typename Stream, typename T>
inline void unpack( Stream& s, chainbase::oid<T>& id )
inline void unpack( Stream& s, chainbase::oid<T>& id, uint32_t )
{
s.read( (char*)&id._id, sizeof(id._id));
}
Expand Down
33 changes: 20 additions & 13 deletions libraries/fc/include/fc/container/flat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ namespace fc {
}
}
template<typename Stream, typename T>
inline void unpack( Stream& s, flat_set<T>& value ) {
unsigned_int size; unpack( s, size );
inline void unpack( Stream& s, flat_set<T>& value, uint32_t depth ) {
depth++;
FC_ASSERT( depth <= MAX_RECURSION_DEPTH );
unsigned_int size; unpack( s, size, depth );
value.clear();
FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
for( uint32_t i = 0; i < size.value; ++i )
{
T tmp;
fc::raw::unpack( s, tmp );
fc::raw::unpack( s, tmp, depth );
value.insert( std::move(tmp) );
}
}
Expand All @@ -41,16 +42,17 @@ namespace fc {
}
}
template<typename Stream, typename K, typename V, typename... A>
inline void unpack( Stream& s, flat_map<K,V,A...>& value )
inline void unpack( Stream& s, flat_map<K,V,A...>& value, uint32_t depth )
{
unsigned_int size; unpack( s, size );
depth++;
FC_ASSERT( depth <= MAX_RECURSION_DEPTH );
unsigned_int size; unpack( s, size, depth );
value.clear();
FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
for( uint32_t i = 0; i < size.value; ++i )
{
std::pair<K,V> tmp;
fc::raw::unpack( s, tmp );
fc::raw::unpack( s, tmp, depth );
value.insert( std::move(tmp) );
}
}
Expand All @@ -71,13 +73,18 @@ namespace fc {
}

template<typename Stream, typename T, typename A>
void unpack( Stream& s, bip::vector<T,A>& value ) {
void unpack( Stream& s, bip::vector<T,A>& value, uint32_t depth ) {
depth++;
FC_ASSERT( depth <= MAX_RECURSION_DEPTH );
unsigned_int size;
unpack( s, size );
value.resize( size );
unpack( s, size, depth );
if( !std::is_fundamental<T>::value ) {
for( auto& item : value )
unpack( s, item );
for ( size_t i = 0; i < size.value; i++ )
{
T tmp;
unpack( s, tmp, depth );
value.emplace_back( std::move( tmp ) );
}
} else {
s.read( (char*)value.data(), value.size() );
}
Expand Down
10 changes: 7 additions & 3 deletions libraries/fc/include/fc/container/flat_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ namespace fc {
template<typename Stream, typename T>
void pack( Stream& s, const flat_set<T>& value );
template<typename Stream, typename T>
void unpack( Stream& s, flat_set<T>& value );
void unpack( Stream& s, flat_set<T>& value, uint32_t depth = 0 );
template<typename Stream, typename K, typename... V>
void pack( Stream& s, const flat_map<K,V...>& value );
template<typename Stream, typename K, typename... V>
void unpack( Stream& s, flat_map<K,V...>& value ) ;
void unpack( Stream& s, flat_map<K,V...>& value, uint32_t depth = 0 ) ;
template<typename Stream, typename K, typename... V>
void pack( Stream& s, const flat_map<K,V...>& value );
template<typename Stream, typename K, typename V, typename... A>
void unpack( Stream& s, flat_map<K,V,A...>& value, uint32_t depth = 0 );


template<typename Stream, typename T, typename A>
void pack( Stream& s, const bip::vector<T,A>& value );
template<typename Stream, typename T, typename A>
void unpack( Stream& s, bip::vector<T,A>& value );
void unpack( Stream& s, bip::vector<T,A>& value, uint32_t depth = 0 );
} // namespace raw

} // fc
5 changes: 3 additions & 2 deletions libraries/fc/include/fc/fixed_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ namespace fc {
}

template<typename Stream, typename Storage>
inline void unpack( Stream& s, fc::fixed_string<Storage>& u ) {
inline void unpack( Stream& s, fc::fixed_string<Storage>& u, uint32_t depth ) {
depth++;
unsigned_int size;
fc::raw::unpack( s, size );
fc::raw::unpack( s, size, depth );
if( size.value > 0 ) {
if( size.value > sizeof(Storage) ) {
s.read( (char*)&u.data, sizeof(Storage) );
Expand Down
16 changes: 11 additions & 5 deletions libraries/fc/include/fc/interprocess/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,18 @@ namespace fc {
}
}
template<typename Stream, typename T, typename... A>
inline void unpack( Stream& s, bip::vector<T,A...>& value ) {
inline void unpack( Stream& s, bip::vector<T,A...>& value, uint32_t depth = 0 ) {
depth++;
FC_ASSERT( depth <= MAX_RECURSION_DEPTH );
unsigned_int size;
unpack( s, size );
value.clear(); value.resize(size);
for( auto& item : value )
fc::raw::unpack( s, item );
unpack( s, size, depth );
value.clear();
for ( size_t i = 0; i < size.value; i++ )
{
T tmp;
fc::raw::unpack( s, tmp, depth );
value.emplace_back( std::move( tmp ) );
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions libraries/fc/include/fc/io/enum_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ namespace fc
}

template<typename Stream, typename IntType, typename EnumType>
inline void unpack( Stream& s, fc::enum_type<IntType,EnumType>& tp )
inline void unpack( Stream& s, fc::enum_type<IntType,EnumType>& tp, uint32_t depth )
{
depth++;
FC_ASSERT( depth <= MAX_RECURSION_DEPTH );
IntType t;
fc::raw::unpack( s, t );
fc::raw::unpack( s, t, depth );
tp = t;
}
}
Expand Down
Loading

0 comments on commit 71aa014

Please sign in to comment.