(
engine: &Engine,
bytes: &[u8],
known_valid: KnownValid,
config: &generators::Config,
)
| 323 | } |
| 324 | |
| 325 | fn compile_module( |
| 326 | engine: &Engine, |
| 327 | bytes: &[u8], |
| 328 | known_valid: KnownValid, |
| 329 | config: &generators::Config, |
| 330 | ) -> Option<Module> { |
| 331 | log_wasm(bytes); |
| 332 | |
| 333 | match config.compile(engine, bytes) { |
| 334 | Ok(module) => Some(module), |
| 335 | Err(_) if known_valid == KnownValid::No => None, |
| 336 | Err(e) => { |
| 337 | if let generators::InstanceAllocationStrategy::Pooling(c) = &config.wasmtime.strategy { |
| 338 | // When using the pooling allocator, accept failures to compile |
| 339 | // when arbitrary table element limits have been exceeded as |
| 340 | // there is currently no way to constrain the generated module |
| 341 | // table types. |
| 342 | let string = format!("{e:?}"); |
| 343 | if string.contains("minimum element size") { |
| 344 | return None; |
| 345 | } |
| 346 | |
| 347 | // Allow modules-failing-to-compile which exceed the requested |
| 348 | // size for each instance. This is something that is difficult |
| 349 | // to control and ensure it always succeeds, so we simply have a |
| 350 | // "random" instance size limit and if a module doesn't fit we |
| 351 | // move on to the next fuzz input. |
| 352 | if string.contains("instance allocation for this module requires") { |
| 353 | return None; |
| 354 | } |
| 355 | |
| 356 | // If the pooling allocator is more restrictive on the number of |
| 357 | // tables and memories than we allowed wasm-smith to generate |
| 358 | // then allow compilation errors along those lines. |
| 359 | if c.max_tables_per_module < (config.module_config.config.max_tables as u32) |
| 360 | && string.contains("defined tables count") |
| 361 | && string.contains("exceeds the per-instance limit") |
| 362 | { |
| 363 | return None; |
| 364 | } |
| 365 | |
| 366 | if c.max_memories_per_module < (config.module_config.config.max_memories as u32) |
| 367 | && string.contains("defined memories count") |
| 368 | && string.contains("exceeds the per-instance limit") |
| 369 | { |
| 370 | return None; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | panic!("failed to compile module: {e:?}"); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /// Create a Wasmtime [`Instance`] from a [`Module`] and fill in all imports |
| 380 | /// with dummy values (e.g., zeroed values, immediately-trapping functions). |
no test coverage detected