A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Fix table64 initialization when bulk memory is disabled (#12894)
Alex Crichton9c3ed1991763
diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator.rs b/crates/wasmtime/src/runtime/vm/instance/allocator.rsindex 99acc3029e..5475a02451 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator.rs@@ -508,12 +508,12 @@ fn check_table_init_bounds(let start = const_evaluator.eval_int(&mut store, context, &segment.offset).expect("const expression should be valid");- let start = usize::try_from(start.unwrap_i32().cast_unsigned()).unwrap();- let end = start.checked_add(usize::try_from(segment.elements.len()).unwrap());+ let start = get_index(start, module.tables[segment.table_index].idx_type);+ let end = start.checked_add(segment.elements.len());let table = store.instance_mut(instance).get_table(segment.table_index);match end {- Some(end) if end <= table.size() => {+ Some(end) if end <= u64::try_from(table.size())? => {// Initializer is in bounds}_ => {@@ -564,10 +564,7 @@ async fn initialize_tables(let start = const_evaluator.eval_int(&mut store, context, &segment.offset).expect("const expression should be valid");- let start = get_index(- start,- store.instance(context.instance).env_module().tables[segment.table_index].idx_type,- );+ let start = get_index(start, module.tables[segment.table_index].idx_type);Instance::table_init_segment(&mut store,limiter.as_deref_mut(),diff --git a/tests/misc_testsuite/memory64/tables-without-bulk-memory.wast b/tests/misc_testsuite/memory64/tables-without-bulk-memory.wastnew file mode 100644index 0000000000..d23f7019bf--- /dev/null+++ b/tests/misc_testsuite/memory64/tables-without-bulk-memory.wast@@ -0,0 +1,13 @@+;;! memory64 = true+;;! reference_types = true+;;! bulk_memory = false++(module $A+ (table (export "table") i64 1 funcref)+)++(module+ (import "A" "table" (table $t i64 1 funcref))+ (func $f)+ (elem (i64.const 0) func $f)+)