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

Fix memory initialization when offset is negative #7559

Merged
merged 1 commit into from
Nov 20, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/environ/src/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/all/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}