Skip to content

Commit 9c3ed19

Browse files
authored
Fix table64 initialization when bulk memory is disabled (#12894)
* Fix table64 initialization when bulk memory is disabled This commit fixes a panic in the host during instantiation when the `bulk_memory` wasm feature is disabled. In this mode the initialization of tables/memories is slightly different and a refactoring for 64-bit support wasn't applied to this code path, meaning that it resulted in a panic instead of properly handling 64-bit tables. * Fix clippy
1 parent 439de7f commit 9c3ed19

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

crates/wasmtime/src/runtime/vm/instance/allocator.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ fn check_table_init_bounds(
508508
let start = const_evaluator
509509
.eval_int(&mut store, context, &segment.offset)
510510
.expect("const expression should be valid");
511-
let start = usize::try_from(start.unwrap_i32().cast_unsigned()).unwrap();
512-
let end = start.checked_add(usize::try_from(segment.elements.len()).unwrap());
511+
let start = get_index(start, module.tables[segment.table_index].idx_type);
512+
let end = start.checked_add(segment.elements.len());
513513

514514
let table = store.instance_mut(instance).get_table(segment.table_index);
515515
match end {
516-
Some(end) if end <= table.size() => {
516+
Some(end) if end <= u64::try_from(table.size())? => {
517517
// Initializer is in bounds
518518
}
519519
_ => {
@@ -564,10 +564,7 @@ async fn initialize_tables(
564564
let start = const_evaluator
565565
.eval_int(&mut store, context, &segment.offset)
566566
.expect("const expression should be valid");
567-
let start = get_index(
568-
start,
569-
store.instance(context.instance).env_module().tables[segment.table_index].idx_type,
570-
);
567+
let start = get_index(start, module.tables[segment.table_index].idx_type);
571568
Instance::table_init_segment(
572569
&mut store,
573570
limiter.as_deref_mut(),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
;;! memory64 = true
2+
;;! reference_types = true
3+
;;! bulk_memory = false
4+
5+
(module $A
6+
(table (export "table") i64 1 funcref)
7+
)
8+
9+
(module
10+
(import "A" "table" (table $t i64 1 funcref))
11+
(func $f)
12+
(elem (i64.const 0) func $f)
13+
)

0 commit comments

Comments
 (0)