@@ -67,7 +67,10 @@ set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
67
67
static bool
68
68
is_32bit_type (uint8 type )
69
69
{
70
- if (type == VALUE_TYPE_I32 || type == VALUE_TYPE_F32
70
+ if (type == VALUE_TYPE_I32
71
+ || type == VALUE_TYPE_F32
72
+ /* the operand stack is in polymorphic state */
73
+ || type == VALUE_TYPE_ANY
71
74
#if WASM_ENABLE_REF_TYPES != 0
72
75
|| type == VALUE_TYPE_FUNCREF || type == VALUE_TYPE_EXTERNREF
73
76
#endif
@@ -4237,7 +4240,7 @@ wasm_loader_pop_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf,
4237
4240
ctx -> frame_ref -- ;
4238
4241
ctx -> stack_cell_num -- ;
4239
4242
4240
- if (is_32bit_type (type ) || * ctx -> frame_ref == VALUE_TYPE_ANY )
4243
+ if (is_32bit_type (type ))
4241
4244
return true;
4242
4245
4243
4246
ctx -> frame_ref -- ;
@@ -6351,13 +6354,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
6351
6354
case WASM_OP_BR_TABLE :
6352
6355
{
6353
6356
uint8 * ret_types = NULL ;
6354
- uint32 ret_count = 0 ;
6357
+ uint32 ret_count = 0 , depth = 0 ;
6355
6358
#if WASM_ENABLE_FAST_INTERP == 0
6356
- uint8 * p_depth_begin , * p_depth ;
6357
- uint32 depth , j ;
6358
6359
BrTableCache * br_table_cache = NULL ;
6359
-
6360
- p_org = p - 1 ;
6360
+ uint8 * p_depth_begin , * p_depth , * p_opcode = p - 1 ;
6361
+ uint32 j ;
6361
6362
#endif
6362
6363
6363
6364
read_leb_uint32 (p , p_end , count );
@@ -6366,6 +6367,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
6366
6367
#endif
6367
6368
POP_I32 ();
6368
6369
6370
+ /* Get each depth and check it */
6371
+ p_org = p ;
6372
+ for (i = 0 ; i <= count ; i ++ ) {
6373
+ read_leb_uint32 (p , p_end , depth );
6374
+ bh_assert (loader_ctx -> csp_num > 0 );
6375
+ bh_assert (loader_ctx -> csp_num - 1 >= depth );
6376
+ (void )depth ;
6377
+ }
6378
+ p = p_org ;
6379
+
6369
6380
#if WASM_ENABLE_FAST_INTERP == 0
6370
6381
p_depth_begin = p_depth = p ;
6371
6382
#endif
@@ -6391,8 +6402,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
6391
6402
error_buf , error_buf_size ))) {
6392
6403
goto fail ;
6393
6404
}
6394
- * p_org = EXT_OP_BR_TABLE_CACHE ;
6395
- br_table_cache -> br_table_op_addr = p_org ;
6405
+ * p_opcode = EXT_OP_BR_TABLE_CACHE ;
6406
+ br_table_cache -> br_table_op_addr = p_opcode ;
6396
6407
br_table_cache -> br_count = count ;
6397
6408
/* Copy previous depths which are one byte */
6398
6409
for (j = 0 ; j < i ; j ++ ) {
@@ -6623,8 +6634,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
6623
6634
&& !cur_block -> is_stack_polymorphic ));
6624
6635
6625
6636
if (available_stack_cell > 0 ) {
6626
- if (is_32bit_type (* (loader_ctx -> frame_ref - 1 ))
6627
- || * (loader_ctx -> frame_ref - 1 ) == VALUE_TYPE_ANY ) {
6637
+ if (is_32bit_type (* (loader_ctx -> frame_ref - 1 ))) {
6628
6638
loader_ctx -> frame_ref -- ;
6629
6639
loader_ctx -> stack_cell_num -- ;
6630
6640
#if WASM_ENABLE_FAST_INTERP != 0
0 commit comments