Refine the stack frame size check in interpreter (#1730)

Limit max_stack_cell_num/max_csp_num to be no larger than UINT16_MAX,
and don't check all_cell_num in interpreter again.

And refine some codes in interpreter.
This commit is contained in:
Wenyong Huang
2022-11-22 15:32:48 +08:00
committed by GitHub
parent 656a8427e6
commit da7117a092
4 changed files with 84 additions and 64 deletions

View File

@ -3594,8 +3594,10 @@ wasm_loader_push_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf,
return false;
*ctx->frame_ref++ = type;
ctx->stack_cell_num++;
if (ctx->stack_cell_num > ctx->max_stack_cell_num)
if (ctx->stack_cell_num > ctx->max_stack_cell_num) {
ctx->max_stack_cell_num = ctx->stack_cell_num;
bh_assert(ctx->max_stack_cell_num <= UINT16_MAX);
}
return true;
}
@ -3661,8 +3663,10 @@ wasm_loader_push_frame_csp(WASMLoaderContext *ctx, uint8 label_type,
#endif
ctx->frame_csp++;
ctx->csp_num++;
if (ctx->csp_num > ctx->max_csp_num)
if (ctx->csp_num > ctx->max_csp_num) {
ctx->max_csp_num = ctx->csp_num;
bh_assert(ctx->max_csp_num <= UINT16_MAX);
}
return true;
fail:
return false;