Skip to content

interp: checked wrong reftype popping block/loop parameters #4646

@XeniaLu

Description

@XeniaLu

When a block/loop has multiple different reference parameters, the reftype is not updated to each parameter when compared to the popped parameter value from the stack, leading to unexpected type mismatch exception.

Test case

  (i32.const 10)
  (struct.new $struct_a ...)
  (i32.const 20)
  (struct.new $struct_b ...)

  (block (param i32 (ref $struct_a) i32 (ref $struct_b)) (result (ref $struct_c)) ... )

Your environment

  • Host OS: Linux
  • WAMR 2.4.2, x86-64, classic-interp

Steps to reproduce

Load a module with such block / loop instructions.

Expected behavior

Load successfully.

Actual behavior

Error loading wasm module: WASM module load failed: type mismatch: expect (ref ht) but got other

Extra Info

Only in this block:

/* Pass parameters to block */
if (BLOCK_HAS_PARAM(block_type)) {

was the wasm_ref_type a.k.a. loader_ctx->ref_type_tmp set properly:

#if WASM_ENABLE_GC != 0
if (wasm_is_type_multi_byte_type(func_type->types[i])) {
bh_assert(func_type->ref_type_maps[j].index == i);
ref_type = func_type->ref_type_maps[j].ref_type;
bh_memcpy_s(&wasm_ref_type, sizeof(WASMRefType),
ref_type,
wasm_reftype_struct_size(ref_type));
j++;
}
#endif

But not in this block (earlier):

/* Pop block parameters from stack */
if (BLOCK_HAS_PARAM(block_type)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions