wabt
wabt copied to clipboard
Missing Table Type Validation in call_indirect Instruction
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))
)
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