From 6945f7c572449bd86a78acaf4add373609536cca Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Feb 2026 10:57:46 -0800 Subject: [PATCH] Fix fuzzing with `stream` Fallout from #2437 in fuzzing where it needs to not be generated any more. --- Cargo.lock | 1 + crates/wit-smith/Cargo.toml | 1 + crates/wit-smith/src/lib.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index cafb36e158..0f6b3025c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3197,6 +3197,7 @@ dependencies = [ "indexmap 2.10.0", "log", "semver", + "wasmparser 0.244.0", "wit-component 0.244.0", "wit-parser 0.244.0", ] diff --git a/crates/wit-smith/Cargo.toml b/crates/wit-smith/Cargo.toml index 34f8ff526a..05765692b0 100644 --- a/crates/wit-smith/Cargo.toml +++ b/crates/wit-smith/Cargo.toml @@ -19,3 +19,4 @@ log = { workspace = true } semver = { workspace = true } wit-component = { workspace = true } wit-parser = { workspace = true } +wasmparser = { workspace = true } diff --git a/crates/wit-smith/src/lib.rs b/crates/wit-smith/src/lib.rs index 6078287fb0..ebc0e09fa2 100644 --- a/crates/wit-smith/src/lib.rs +++ b/crates/wit-smith/src/lib.rs @@ -42,5 +42,18 @@ pub fn smith(config: &Config, u: &mut Unstructured<'_>) -> Result> { } let pkg = last.unwrap(); - Ok(wit_component::encode(&resolve, pkg).expect("failed to encode WIT document")) + let wasm = wit_component::encode(&resolve, pkg).expect("failed to encode WIT document"); + + // Handle disallowing `stream` here vs not generating it to start + // with as it's a bit easier to handle. + if let Err(e) = wasmparser::Validator::new_with_features(wasmparser::WasmFeatures::all()) + .validate_all(&wasm) + { + if e.to_string() + .contains("`stream` is not valid at this time") + { + return Err(arbitrary::Error::IncorrectFormat); + } + } + Ok(wasm) }