|
| 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 | +} |
0 commit comments