From 37ade17e2a2c90d4c7a63c3b899cd5a02f494353 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 13 Dec 2022 14:04:56 -0600 Subject: [PATCH] Allow at least 1 page of memory when disallowing traps (#5421) This commit fixes configuration of the pooling instance allocator when traps are disallowed while fuzzing to ensure that there's at least one page of memory. The support in `wasm-smith` currently forcibly creates a 1-page memory which was previously invalid in the pooling instance allocator under the generated configuration, so this commit updates the configuration generated to ensure that it can fit the generated module. --- crates/fuzzing/src/generators/config.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/fuzzing/src/generators/config.rs b/crates/fuzzing/src/generators/config.rs index 91c325390c..30de3d3165 100644 --- a/crates/fuzzing/src/generators/config.rs +++ b/crates/fuzzing/src/generators/config.rs @@ -311,6 +311,20 @@ impl<'a> Arbitrary<'a> for Config { cfg.max_memory_pages = pooling.instance_memory_pages; } + // If traps are disallowed then memories must have at least one page + // of memory so if we still are only allowing 0 pages of memory then + // increase that to one here. + if cfg.disallow_traps { + if pooling.instance_memory_pages == 0 { + pooling.instance_memory_pages = 1; + cfg.max_memory_pages = 1; + } + // .. additionally update tables + if pooling.instance_table_elements == 0 { + pooling.instance_table_elements = 1; + } + } + // Forcibly don't use the `CustomUnaligned` memory configuration // with the pooling allocator active. if let MemoryConfig::CustomUnaligned = config.wasmtime.memory_config {