Skip to content

Commit dcb6427

Browse files
committed
Fix frame_offset calculation to match actual frame_ref stack changes
1 parent 7898af9 commit dcb6427

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

core/iwasm/interpreter/wasm_loader.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9720,6 +9720,16 @@ preserve_local_for_block(WASMLoaderContext *loader_ctx, uint8 opcode,
97209720

97219721
/* preserve locals before blocks to ensure that "tee/set_local" inside
97229722
blocks will not influence the value of these locals */
9723+
uint32 frame_offset_cell =
9724+
(uint32)(loader_ctx->frame_offset - loader_ctx->frame_offset_bottom);
9725+
uint32 frame_ref_cell =
9726+
(uint32)(loader_ctx->frame_ref - loader_ctx->frame_ref_bottom);
9727+
if (frame_offset_cell < loader_ctx->stack_cell_num
9728+
|| frame_ref_cell < loader_ctx->stack_cell_num) {
9729+
set_error_buf(error_buf, error_buf_size, "stack cell num error");
9730+
return false;
9731+
}
9732+
97239733
while (i < loader_ctx->stack_cell_num) {
97249734
int16 cur_offset = loader_ctx->frame_offset_bottom[i];
97259735
uint8 cur_type = loader_ctx->frame_ref_bottom[i];
@@ -12105,14 +12115,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1210512115
j--;
1210612116
}
1210712117
#endif
12108-
12118+
uint8 *frame_ref_before_pop = loader_ctx->frame_ref;
1210912119
POP_TYPE(
1211012120
wasm_type->types[wasm_type->param_count - i - 1]);
1211112121
#if WASM_ENABLE_FAST_INTERP != 0
1211212122
/* decrease the frame_offset pointer accordingly to keep
1211312123
* consistent with frame_ref stack */
12114-
cell_num = wasm_value_type_cell_num(
12115-
wasm_type->types[wasm_type->param_count - i - 1]);
12124+
cell_num = frame_ref_before_pop - loader_ctx->frame_ref;
1211612125
loader_ctx->frame_offset -= cell_num;
1211712126

1211812127
if (loader_ctx->frame_offset

0 commit comments

Comments
 (0)