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

@ -5078,8 +5078,14 @@ wasm_loader_push_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf,
#endif
check_stack_and_return:
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;
if (ctx->max_stack_cell_num > UINT16_MAX) {
set_error_buf(error_buf, error_buf_size,
"operand stack depth limit exceeded");
return false;
}
}
return true;
}
@ -5154,8 +5160,14 @@ 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;
if (ctx->max_csp_num > UINT16_MAX) {
set_error_buf(error_buf, error_buf_size,
"label stack depth limit exceeded");
return false;
}
}
return true;
fail:
return false;