Skip to content

Commit 1f94cd4

Browse files
authored
wasm loader: Fix push_frame_offset when pushing v128 type (bytecodealliance#3588)
Fixes issue bytecodealliance#3580.
1 parent e3074dc commit 1f94cd4

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9315,6 +9315,8 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
93159315
bool disable_emit, int16 operand_offset,
93169316
char *error_buf, uint32 error_buf_size)
93179317
{
9318+
uint32 cell_num_to_push, i;
9319+
93189320
if (type == VALUE_TYPE_VOID)
93199321
return true;
93209322

@@ -9341,21 +9343,24 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
93419343
if (is_32bit_type(type))
93429344
return true;
93439345

9344-
if (ctx->p_code_compiled == NULL) {
9345-
if (!check_offset_push(ctx, error_buf, error_buf_size))
9346-
return false;
9347-
}
9346+
cell_num_to_push = wasm_value_type_cell_num(type) - 1;
9347+
for (i = 0; i < cell_num_to_push; i++) {
9348+
if (ctx->p_code_compiled == NULL) {
9349+
if (!check_offset_push(ctx, error_buf, error_buf_size))
9350+
return false;
9351+
}
93489352

9349-
ctx->frame_offset++;
9350-
if (!disable_emit) {
9351-
ctx->dynamic_offset++;
9352-
if (ctx->dynamic_offset > ctx->max_dynamic_offset) {
9353-
ctx->max_dynamic_offset = ctx->dynamic_offset;
9354-
if (ctx->max_dynamic_offset >= INT16_MAX) {
9355-
goto fail;
9353+
ctx->frame_offset++;
9354+
if (!disable_emit) {
9355+
ctx->dynamic_offset++;
9356+
if (ctx->dynamic_offset > ctx->max_dynamic_offset) {
9357+
ctx->max_dynamic_offset = ctx->dynamic_offset;
9358+
if (ctx->max_dynamic_offset >= INT16_MAX)
9359+
goto fail;
93569360
}
93579361
}
93589362
}
9363+
93599364
return true;
93609365

93619366
fail:

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,6 +4869,8 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
48694869
bool disable_emit, int16 operand_offset,
48704870
char *error_buf, uint32 error_buf_size)
48714871
{
4872+
uint32 cell_num_to_push, i;
4873+
48724874
if (type == VALUE_TYPE_VOID)
48734875
return true;
48744876

@@ -4893,19 +4895,23 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
48934895
if (is_32bit_type(type))
48944896
return true;
48954897

4896-
if (ctx->p_code_compiled == NULL) {
4897-
if (!check_offset_push(ctx, error_buf, error_buf_size))
4898-
return false;
4899-
}
4898+
cell_num_to_push = wasm_value_type_cell_num(type) - 1;
4899+
for (i = 0; i < cell_num_to_push; i++) {
4900+
if (ctx->p_code_compiled == NULL) {
4901+
if (!check_offset_push(ctx, error_buf, error_buf_size))
4902+
return false;
4903+
}
49004904

4901-
ctx->frame_offset++;
4902-
if (!disable_emit) {
4903-
ctx->dynamic_offset++;
4904-
if (ctx->dynamic_offset > ctx->max_dynamic_offset) {
4905-
ctx->max_dynamic_offset = ctx->dynamic_offset;
4906-
bh_assert(ctx->max_dynamic_offset < INT16_MAX);
4905+
ctx->frame_offset++;
4906+
if (!disable_emit) {
4907+
ctx->dynamic_offset++;
4908+
if (ctx->dynamic_offset > ctx->max_dynamic_offset) {
4909+
ctx->max_dynamic_offset = ctx->dynamic_offset;
4910+
bh_assert(ctx->max_dynamic_offset < INT16_MAX);
4911+
}
49074912
}
49084913
}
4914+
49094915
return true;
49104916
}
49114917

0 commit comments

Comments
 (0)