Skip to content

Commit 02683d2

Browse files
authored
Improve stack consistency by ensuring sufficient space for dummy offsets (#4011)
One more corner case: if the `frame_offset` increases and becomes equal to the `frame_offset_boundary` after the last assignment within the for loop.
1 parent a653746 commit 02683d2

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

core/iwasm/interpreter/wasm_loader.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11228,21 +11228,23 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1122811228
uint32 cell_num =
1122911229
wasm_value_type_cell_num(func_type->types[i]);
1123011230
if (i >= available_params) {
11231+
/* make sure enough space */
11232+
if (loader_ctx->p_code_compiled == NULL) {
11233+
loader_ctx->frame_offset += cell_num;
11234+
if (!check_offset_push(loader_ctx, error_buf,
11235+
error_buf_size))
11236+
goto fail;
11237+
/* for following dummy value assignemnt */
11238+
loader_ctx->frame_offset -= cell_num;
11239+
}
11240+
1123111241
/* If there isn't enough data on stack, push a dummy
1123211242
* offset to keep the stack consistent with
1123311243
* frame_ref.
1123411244
* Since the stack is already in polymorphic state,
1123511245
* the opcode will not be executed, so the dummy
1123611246
* offset won't cause any error */
11237-
uint32 n;
11238-
11239-
for (n = 0; n < cell_num; n++) {
11240-
if (loader_ctx->p_code_compiled == NULL) {
11241-
if (!check_offset_push(loader_ctx,
11242-
error_buf,
11243-
error_buf_size))
11244-
goto fail;
11245-
}
11247+
for (uint32 n = 0; n < cell_num; n++) {
1124611248
*loader_ctx->frame_offset++ = 0;
1124711249
}
1124811250
}

0 commit comments

Comments
 (0)