Skip to content

Commit 3ec9e05

Browse files
authored
Fail if non-funcref table used in call_indirect (#157)
1 parent 1300341 commit 3ec9e05

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

crates/wasmparser/src/operators_validator.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,19 @@ impl OperatorValidator {
501501
table_index: u32,
502502
resources: &impl WasmModuleResources,
503503
) -> OperatorValidatorResult<()> {
504-
if resources.table_at(table_index).is_none() {
505-
return Err(OperatorValidatorError::new(
506-
"unknown table: table index out of bounds",
507-
));
504+
match resources.table_at(table_index) {
505+
None => {
506+
return Err(OperatorValidatorError::new(
507+
"unknown table: table index out of bounds",
508+
));
509+
}
510+
Some(tab) => {
511+
if tab.element_type != Type::FuncRef {
512+
return Err(OperatorValidatorError::new(
513+
"indirect calls must go through a table of funcref",
514+
));
515+
}
516+
}
508517
}
509518
let ty = func_type_at(&resources, index)?;
510519
self.pop_operand(Some(Type::I32))?;

tests/local/table-funcref.wast

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(assert_malformed
2+
(module
3+
(type (func (result i32)))
4+
(func $main (result i32)
5+
i32.const 0
6+
call_indirect (type 0)
7+
)
8+
(table (;0;) 1 externref)
9+
)
10+
"indirect calls must go through a table of funcref"
11+
)

0 commit comments

Comments
 (0)