Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Table Type Validation in call_indirect Instruction #3993

Open
Q1IQ opened this issue Dec 30, 2024 · 1 comment · May be fixed by #3999
Open

Missing Table Type Validation in call_indirect Instruction #3993

Q1IQ opened this issue Dec 30, 2024 · 1 comment · May be fixed by #3999

Comments

@Q1IQ
Copy link

Q1IQ commented Dec 30, 2024

Subject of the issue

iwasm fails to validate the type of the table used in the call_indirect instruction. According to the WebAssembly specification, the table associated with call_indirect must have a funcref type.

Test case

(module
  (type (func (param i32 i32) (result i32)))

  (func $func1 (type 0) (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.add)

  (func $func2 (type 0) (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.sub)

  (table 2 externref)
  (elem (i32.const 0) externref (ref.null extern) (ref.null extern))

  (func $main (result i32)
    i32.const 0x12341234
    i32.const 0x1234
    i32.const 1
    call_indirect (type 0)
    )

  (export "main" (func $main))
)

Your environment

  • OS: Ubuntu 20.04
  • CPU: amd64
  • WAMR version: iwasm 2.2.0
  • Commands:
iwasm  --interp -f main ./program.wasm
iwasm --fast-jit -f main ./program.wasm
iwasm --llvm-jit -f main ./program.wasm
iwasm --multi-tier-jit -f main./program.wasm

Actual behavior

The iwasm proceeds to execute the module without raising any validation error, despite the table having an invalid type (externref) for use in the call_indirect instruction. The observed output in all execution modes is:

0x12342468:i32

Expected behavior

The WebAssembly specification mandates that the table used in the call_indirect instruction must be of type funcref. Tables of type externref cannot hold function references and are invalid for call_indirect. The runtime should fail validation and report an error similar to:

Validation error: call_indirect is only valid when a table has type funcref
@TianlongLiang
Copy link
Collaborator

Thanks for reporting this issue, I will take a look, and keep you updated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants