1 #![cfg(arc_try_new)] 2 3 use wasmtime::{Config, Engine, Module, Result}; 4 use wasmtime_fuzzing::oom::OomTest; 5 6 #[test] module_deserialize() -> Result<()>7fn module_deserialize() -> 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 let engine = Engine::new(&config)?; 37 38 OomTest::new() 39 // NB: We use `postcard` to deserialize module metadata, and it will 40 // return a `postcard::Error::SerdeDeCustom` when we generate an 41 // `OutOfMemory` error during deserialization. That is then converted 42 // into a `wasmtime::Error`, and in the process we will attempt to box 43 // that into an `Error` trait object. There is no good way to avoid all 44 // this, so just allow allocation attempts after OOM here. 45 .allow_alloc_after_oom(true) 46 .test(|| unsafe { 47 let _ = Module::deserialize(&engine, &module_bytes)?; 48 Ok(()) 49 }) 50 } 51