Skip to content

Commit c7d25df

Browse files
authored
Handle OOM in InstancePre::instantiate (#12853)
1 parent cda1136 commit c7d25df

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#![cfg(arc_try_new)]
2+
3+
use wasmtime::{Config, Engine, Linker, Module, Result, Store};
4+
use wasmtime_fuzzing::oom::OomTest;
5+
6+
#[test]
7+
fn instance_pre_instantiate() -> Result<()> {
8+
let module_bytes = {
9+
let mut config = Config::new();
10+
config.concurrency_support(false);
11+
let engine = Engine::new(&config)?;
12+
let module = Module::new(
13+
&engine,
14+
r#"
15+
(module
16+
(import "module" "func" (func (param i32) (result i32)))
17+
18+
(memory (export "memory") 1)
19+
(data (i32.const 0) "a")
20+
21+
(table (export "table") 1 funcref)
22+
(elem (i32.const 0) func 1)
23+
24+
(func (export "func") (param i32) (result i32)
25+
(call 0 (local.get 0))
26+
)
27+
)
28+
"#,
29+
)?;
30+
module.serialize()?
31+
};
32+
33+
let mut config = Config::new();
34+
config.enable_compiler(false);
35+
config.concurrency_support(false);
36+
37+
let engine = Engine::new(&config)?;
38+
39+
let mut linker = Linker::<()>::new(&engine);
40+
linker.func_wrap("module", "func", |x: i32| x * 2)?;
41+
42+
let module = unsafe { Module::deserialize(&engine, &module_bytes)? };
43+
let instance_pre = linker.instantiate_pre(&module)?;
44+
45+
OomTest::new().test(|| {
46+
let mut store = Store::try_new(&engine, ())?;
47+
let _ = instance_pre.instantiate(&mut store)?;
48+
Ok(())
49+
})
50+
}

crates/fuzzing/tests/oom/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod func_type;
1212
mod hash_map;
1313
mod hash_set;
1414
mod index_map;
15+
mod instance_pre;
1516
mod linker;
1617
mod module;
1718
mod primary_map;

0 commit comments

Comments
 (0)