diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs index 00a5885c6f..1339431427 100644 --- a/crates/environ/src/module_environ.rs +++ b/crates/environ/src/module_environ.rs @@ -607,7 +607,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { let memory_index = MemoryIndex::from_u32(memory_index); let mut offset_expr_reader = offset_expr.get_binary_reader(); let (base, offset) = match offset_expr_reader.read_operator()? { - Operator::I32Const { value } => (None, value as u64), + Operator::I32Const { value } => (None, (value as u32).into()), Operator::I64Const { value } => (None, value as u64), Operator::GlobalGet { global_index } => { (Some(GlobalIndex::from_u32(global_index)), 0) diff --git a/tests/all/memory.rs b/tests/all/memory.rs index 4e29202001..fa2cbadd88 100644 --- a/tests/all/memory.rs +++ b/tests/all/memory.rs @@ -642,3 +642,21 @@ fn shared_memory_wait_notify() -> Result<()> { Ok(()) } + +#[test] +#[cfg_attr(miri, ignore)] +fn init_with_negative_segment() -> Result<()> { + let engine = Engine::default(); + let module = Module::new( + &engine, + r#" + (module + (memory 65536) + (data (i32.const 0x8000_0000) "x") + ) + "#, + )?; + let mut store = Store::new(&engine, ()); + Instance::new(&mut store, &module, &[])?; + Ok(()) +}