@@ -49,9 +49,9 @@ namespace eosio { namespace chain {
49
49
);
50
50
}
51
51
52
- abi_serializer::abi_serializer ( const abi_def& abi ) {
52
+ abi_serializer::abi_serializer ( const abi_def& abi, const fc::microseconds& max_serialization_time ) {
53
53
configure_built_in_types ();
54
- set_abi (abi);
54
+ set_abi (abi, max_serialization_time );
55
55
}
56
56
57
57
void abi_serializer::configure_built_in_types () {
@@ -97,7 +97,8 @@ namespace eosio { namespace chain {
97
97
built_in_types.emplace (" extended_asset" , pack_unpack<extended_asset>());
98
98
}
99
99
100
- void abi_serializer::set_abi (const abi_def& abi) {
100
+ void abi_serializer::set_abi (const abi_def& abi, const fc::microseconds& max_serialization_time) {
101
+ const fc::time_point deadline = fc::time_point::now () + max_serialization_time;
101
102
typedefs.clear ();
102
103
structs.clear ();
103
104
actions.clear ();
@@ -108,8 +109,8 @@ namespace eosio { namespace chain {
108
109
structs[st.name ] = st;
109
110
110
111
for ( const auto & td : abi.types ) {
111
- FC_ASSERT (is_type (td.type ), " invalid type" , (" type" ,td.type ));
112
- FC_ASSERT (!is_type (td.new_type_name ), " type already exists" , (" new_type_name" ,td.new_type_name ));
112
+ FC_ASSERT (_is_type (td.type , 0 , deadline, max_serialization_time ), " invalid type" , (" type" ,td.type ));
113
+ FC_ASSERT (!_is_type (td.new_type_name , 0 , deadline, max_serialization_time ), " type already exists" , (" new_type_name" ,td.new_type_name ));
113
114
typedefs[td.new_type_name ] = td.type ;
114
115
}
115
116
@@ -132,7 +133,7 @@ namespace eosio { namespace chain {
132
133
FC_ASSERT ( tables.size () == abi.tables .size () );
133
134
FC_ASSERT ( error_messages.size () == abi.error_messages .size () );
134
135
135
- validate ();
136
+ validate (max_serialization_time );
136
137
}
137
138
138
139
bool abi_serializer::is_builtin_type (const type_name& type)const {
@@ -176,12 +177,12 @@ namespace eosio { namespace chain {
176
177
}
177
178
}
178
179
179
- bool abi_serializer::_is_type (const type_name& rtype, size_t recursion_depth, const fc::time_point& deadline)const {
180
+ bool abi_serializer::_is_type (const type_name& rtype, size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const {
180
181
FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
181
182
if ( ++recursion_depth > max_recursion_depth) return false ;
182
183
auto type = fundamental_type (rtype);
183
184
if ( built_in_types.find (type) != built_in_types.end () ) return true ;
184
- if ( typedefs.find (type) != typedefs.end () ) return _is_type (typedefs.find (type)->second , recursion_depth, deadline);
185
+ if ( typedefs.find (type) != typedefs.end () ) return _is_type (typedefs.find (type)->second , recursion_depth, deadline, max_serialization_time );
185
186
if ( structs.find (type) != structs.end () ) return true ;
186
187
return false ;
187
188
}
@@ -192,7 +193,7 @@ namespace eosio { namespace chain {
192
193
return itr->second ;
193
194
}
194
195
195
- void abi_serializer::validate ()const {
196
+ void abi_serializer::validate (const fc::microseconds& max_serialization_time )const {
196
197
const fc::time_point deadline = fc::time_point::now () + max_serialization_time;
197
198
for ( const auto & t : typedefs ) { try {
198
199
vector<type_name> types_seen{t.first , t.second };
@@ -205,7 +206,7 @@ namespace eosio { namespace chain {
205
206
}
206
207
} FC_CAPTURE_AND_RETHROW ( (t) ) }
207
208
for ( const auto & t : typedefs ) { try {
208
- FC_ASSERT (is_type (t.second ), " " , (" type" ,t.second ) );
209
+ FC_ASSERT (_is_type (t.second , 0 , deadline, max_serialization_time ), " " , (" type" ,t.second ) );
209
210
} FC_CAPTURE_AND_RETHROW ( (t) ) }
210
211
for ( const auto & s : structs ) { try {
211
212
if ( s.second .base != type_name () ) {
@@ -221,17 +222,17 @@ namespace eosio { namespace chain {
221
222
}
222
223
for ( const auto & field : s.second .fields ) { try {
223
224
FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
224
- FC_ASSERT (is_type (field.type ) );
225
+ FC_ASSERT (_is_type (field.type , 0 , deadline, max_serialization_time ) );
225
226
} FC_CAPTURE_AND_RETHROW ( (field) ) }
226
227
} FC_CAPTURE_AND_RETHROW ( (s) ) }
227
228
for ( const auto & a : actions ) { try {
228
229
FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
229
- FC_ASSERT (is_type (a.second ), " " , (" type" ,a.second ) );
230
+ FC_ASSERT (_is_type (a.second , 0 , deadline, max_serialization_time ), " " , (" type" ,a.second ) );
230
231
} FC_CAPTURE_AND_RETHROW ( (a) ) }
231
232
232
233
for ( const auto & t : tables ) { try {
233
234
FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
234
- FC_ASSERT (is_type (t.second ), " " , (" type" ,t.second ) );
235
+ FC_ASSERT (_is_type (t.second , 0 , deadline, max_serialization_time ), " " , (" type" ,t.second ) );
235
236
} FC_CAPTURE_AND_RETHROW ( (t) ) }
236
237
}
237
238
@@ -369,7 +370,7 @@ namespace eosio { namespace chain {
369
370
{ try {
370
371
FC_ASSERT ( ++recursion_depth < max_recursion_depth, " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
371
372
FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
372
- if ( !is_type (type) ) {
373
+ if ( !_is_type (type, recursion_depth, deadline, max_serialization_time ) ) {
373
374
return var.as <bytes>();
374
375
}
375
376
0 commit comments