Add knobs to limit memories/tables in a Store
Fuzzing has turned up that module linking can create large amounts of tables and memories in addition to instances. For example if N instances are allowed and M tables are allowed per-instance, then currently wasmtime allows MxN tables (which is quite a lot). This is causing some wasm-smith-generated modules to exceed resource limits while fuzzing! This commits adds corresponding `max_tables` and `max_memories` functions to sit alongside the `max_instances` configuration. Additionally fuzzing now by default configures all of these to a somewhat low value to avoid too much resource usage while fuzzing.
This commit is contained in:
@@ -218,6 +218,81 @@ fn limit_instances() -> Result<()> {
|
||||
)?;
|
||||
let store = Store::new(&engine);
|
||||
let err = Instance::new(&store, &module, &[]).err().unwrap();
|
||||
assert!(err.to_string().contains("instance limit of 10 exceeded"));
|
||||
assert!(
|
||||
err.to_string().contains("resource limit exceeded"),
|
||||
"bad error: {}",
|
||||
err
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limit_memories() -> Result<()> {
|
||||
let mut config = Config::new();
|
||||
config.wasm_module_linking(true);
|
||||
config.wasm_multi_memory(true);
|
||||
config.max_memories(10);
|
||||
let engine = Engine::new(&config);
|
||||
let module = Module::new(
|
||||
&engine,
|
||||
r#"
|
||||
(module
|
||||
(module $m0
|
||||
(memory 1 1)
|
||||
(memory 1 1)
|
||||
(memory 1 1)
|
||||
(memory 1 1)
|
||||
(memory 1 1)
|
||||
)
|
||||
|
||||
(instance (instantiate $m0))
|
||||
(instance (instantiate $m0))
|
||||
(instance (instantiate $m0))
|
||||
(instance (instantiate $m0))
|
||||
)
|
||||
"#,
|
||||
)?;
|
||||
let store = Store::new(&engine);
|
||||
let err = Instance::new(&store, &module, &[]).err().unwrap();
|
||||
assert!(
|
||||
err.to_string().contains("resource limit exceeded"),
|
||||
"bad error: {}",
|
||||
err
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limit_tables() -> Result<()> {
|
||||
let mut config = Config::new();
|
||||
config.wasm_module_linking(true);
|
||||
config.max_tables(10);
|
||||
let engine = Engine::new(&config);
|
||||
let module = Module::new(
|
||||
&engine,
|
||||
r#"
|
||||
(module
|
||||
(module $m0
|
||||
(table 1 1 funcref)
|
||||
(table 1 1 funcref)
|
||||
(table 1 1 funcref)
|
||||
(table 1 1 funcref)
|
||||
(table 1 1 funcref)
|
||||
)
|
||||
|
||||
(instance (instantiate $m0))
|
||||
(instance (instantiate $m0))
|
||||
(instance (instantiate $m0))
|
||||
(instance (instantiate $m0))
|
||||
)
|
||||
"#,
|
||||
)?;
|
||||
let store = Store::new(&engine);
|
||||
let err = Instance::new(&store, &module, &[]).err().unwrap();
|
||||
assert!(
|
||||
err.to_string().contains("resource limit exceeded"),
|
||||
"bad error: {}",
|
||||
err
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user