A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Add OOM test for component Linker::instantiate_async (#13049)
Nick Fitzgerald2d443eaa9a03
diff --git a/crates/fuzzing/tests/oom/component_linker.rs b/crates/fuzzing/tests/oom/component_linker.rsnew file mode 100644index 0000000000..3da84a4a96--- /dev/null+++ b/crates/fuzzing/tests/oom/component_linker.rs@@ -0,0 +1,43 @@+#![cfg(arc_try_new)]++use wasmtime::component::{Component, Linker};+use wasmtime::{Config, Engine, Result, Store};+use wasmtime_fuzzing::oom::OomTest;++#[tokio::test]+async fn component_linker_instantiate_async() -> Result<()> {+ let component_bytes = {+ let mut config = Config::new();+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ Component::new(+ &engine,+ r#"+ (component+ (core module $m+ (func (export "id") (param i32) (result i32) (local.get 0))+ )+ (core instance $i (instantiate $m))+ (func (export "id") (param "x" s32) (result s32)+ (canon lift (core func $i "id"))+ )+ )+ "#,+ )?+ .serialize()?+ };+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ let component = unsafe { Component::deserialize(&engine, &component_bytes)? };+ let linker = Linker::<()>::new(&engine);++ OomTest::new()+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let _instance = linker.instantiate_async(&mut store, &component).await?;+ Ok(())+ })+ .await+}diff --git a/crates/fuzzing/tests/oom/main.rs b/crates/fuzzing/tests/oom/main.rsindex 6c77aeb01a..6a9435be3a 100644--- a/crates/fuzzing/tests/oom/main.rs+++ b/crates/fuzzing/tests/oom/main.rs@@ -6,6 +6,7 @@ mod boxed;mod btree_map;mod caller;mod component_func;+mod component_linker;mod config;mod engine;mod entity_set;diff --git a/crates/wasmtime/src/runtime/component/linker.rs b/crates/wasmtime/src/runtime/component/linker.rsindex c11d2b3734..c86ac766b7 100644--- a/crates/wasmtime/src/runtime/component/linker.rs+++ b/crates/wasmtime/src/runtime/component/linker.rs@@ -177,7 +177,7 @@ impl<T: 'static> Linker<T> {engine: &self.engine,types: component.types(),strings: &self.strings,- imported_resources: Default::default(),+ imported_resources: try_new::<Arc<_>>(Default::default())?,};// Walk over the component's list of import names and use that to lookup@@ -267,7 +267,11 @@ impl<T: 'static> Linker<T> {assert_eq!(i, idx);}Ok(unsafe {- InstancePre::new_unchecked(component.clone(), Arc::new(imports), imported_resources)+ InstancePre::new_unchecked(+ component.clone(),+ try_new::<Arc<_>>(imports)?,+ imported_resources,+ )})}