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

[0.38.0] Fix a possible panic with null-containing element segments #4456

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/runtime/src/table.rs
Expand Up @@ -280,7 +280,9 @@ impl Table {
};

for (item, slot) in items.zip(elements) {
*slot = item as usize;
unsafe {
*slot = TableElement::FuncRef(item).into_table_value();
}
}
Ok(())
}
Expand Down
25 changes: 25 additions & 0 deletions tests/all/table.rs
@@ -1,3 +1,4 @@
use anyhow::Result;
use wasmtime::*;

#[test]
Expand Down Expand Up @@ -50,3 +51,27 @@ fn copy_wrong() {
"tables do not have the same element type"
);
}

#[test]
fn null_elem_segment_works_with_imported_table() -> Result<()> {
let mut store = Store::<()>::default();
let ty = TableType::new(ValType::FuncRef, 1, None);
let table = Table::new(&mut store, ty, Val::FuncRef(None))?;
let module = Module::new(
store.engine(),
r#"
(module
(import "" "" (table (;0;) 1 funcref))
(func
i32.const 0
table.get 0
drop
)
(start 0)
(elem (;0;) (i32.const 0) funcref (ref.null func))
)
"#,
)?;
Instance::new(&mut store, &module, &[table.into()])?;
Ok(())
}