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 #2523

Open
Q1IQ opened this issue Dec 28, 2024 · 0 comments
Open

Missing Table Type Validation in call_indirect Instruction #2523

Q1IQ opened this issue Dec 28, 2024 · 0 comments

Comments

@Q1IQ
Copy link

Q1IQ commented Dec 28, 2024

wasm-interp 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))
)

program.wasm.txt

Environment

  • OS: Ubuntu 20.04
  • CPU: amd64
  • WABT version: 1.0.36
  • Commands:
./wasm-interp --enable-all --run-export=main ./program.wasm

Actual behavior

wasm-interp raises a runtime error about uninitialized table elements instead of reporting a validation error for the incorrect table type. The output from wasm-interp is:

main() => error: uninitialized table element

Expected behavior

The runtime should detect that the table type (externref) is invalid for the call_indirect instruction and raise a validation error. The expected error message should be similar to:

Validation error: call_indirect is only valid when a table has type funcref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants