diff --git a/fuzzgen/src/main/kotlin/software/amazon/smithy/rust/codegen/fuzz/FuzzHarnessBuildPlugin.kt b/fuzzgen/src/main/kotlin/software/amazon/smithy/rust/codegen/fuzz/FuzzHarnessBuildPlugin.kt index fd804e811e..d098e30dcf 100644 --- a/fuzzgen/src/main/kotlin/software/amazon/smithy/rust/codegen/fuzz/FuzzHarnessBuildPlugin.kt +++ b/fuzzgen/src/main/kotlin/software/amazon/smithy/rust/codegen/fuzz/FuzzHarnessBuildPlugin.kt @@ -102,6 +102,7 @@ class FuzzHarnessBuildPlugin : SmithyBuildPlugin { target } + println("creating the driver...") createDriver(model, context.fileManifest, fuzzSettings) targets.forEach { @@ -133,11 +134,12 @@ fun corpus( val protocolTests = operations.flatMap { it.getTrait()?.testCases ?: listOf() } val out = ArrayNode.builder() protocolTests.forEach { testCase -> + println(testCase.bodyMediaType) val body: List = when (testCase.bodyMediaType.orNull()) { "application/cbor" -> { - println("base64 decoding first") - Base64.getDecoder().decode(testCase.body.orNull())?.map { NumberNode.from(it) } + println("base64 decoding first (v2)") + Base64.getDecoder().decode(testCase.body.orNull())?.map { NumberNode.from(it.toUByte().toInt()) } } else -> testCase.body.orNull()?.chars()?.toList()?.map { c -> NumberNode.from(c) } } ?: listOf() diff --git a/rust-runtime/aws-smithy-fuzz/README.md b/rust-runtime/aws-smithy-fuzz/README.md index aba273d17f..46dbc7970c 100644 --- a/rust-runtime/aws-smithy-fuzz/README.md +++ b/rust-runtime/aws-smithy-fuzz/README.md @@ -7,8 +7,8 @@ AWS Smithy fuzz contains a set of utilities for writing fuzz tests against smith 2. Install the AFL runtime: `cargo afl config --build` 2. Install the smithy CLI: 2. Install aws-smithy-fuzz: - 3. Locally: `cargo afl install --path .` - 4. From crates.io: cargo afl install aws-smithy-fuzz + - Locally: `cargo afl install --path .` + - From crates.io: cargo afl install aws-smithy-fuzz ## Usage This contains a library + a CLI tool to fuzz smithy servers. The library allows setting up a given Smithy server implementation as a `cdylib`. This allows two different versions two by dynamically linked at runtime and executed by the fuzzer. diff --git a/rust-runtime/aws-smithy-fuzz/src/lib.rs b/rust-runtime/aws-smithy-fuzz/src/lib.rs index 4f8458b494..e23864fc2c 100644 --- a/rust-runtime/aws-smithy-fuzz/src/lib.rs +++ b/rust-runtime/aws-smithy-fuzz/src/lib.rs @@ -164,7 +164,6 @@ fn assert_ready(mut future: F) -> F::Output { #[cfg(test)] mod test { - use crate::types::FuzzResult; use crate::{make_target, Body}; use http::Request; use std::error::Error; diff --git a/rust-runtime/aws-smithy-fuzz/src/main.rs b/rust-runtime/aws-smithy-fuzz/src/main.rs index eebcc98ce0..7e9c14a1d2 100644 --- a/rust-runtime/aws-smithy-fuzz/src/main.rs +++ b/rust-runtime/aws-smithy-fuzz/src/main.rs @@ -643,6 +643,21 @@ fn replay( FuzzResult { result: String }, } + impl Display for CrashResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CrashResult::Panic { message } => { + f.pad("The process paniced!\n")?; + for line in message.lines() { + write!(f, " {}\n", line)?; + } + Ok(()) + } + CrashResult::FuzzResult { result } => f.pad(result), + } + } + } + for library in &config.targets { let result = Command::new(env::current_exe().unwrap()) .arg("invoke-test-case") @@ -667,17 +682,24 @@ fn replay( test_case: String, results: HashMap, } + impl Display for Results { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let test_case = &self.test_case; + write!(f, "Test case: {test_case}\n")?; + for (target, result) in &self.results { + write!(f, " target: {target}\n{:>2}", result)?; + } + Ok(()) + } + } + let results = Results { + test_case: format!("{:#?}", http_request.unwrap()), + results, + }; if json { - println!( - "{}", - serde_json::to_string(&Results { - test_case: format!("{:#?}", http_request.unwrap()), - results - }) - .unwrap() - ); + println!("{}", serde_json::to_string(&results).unwrap()); } else { - println!("{:#?}\n----", results); + println!("{}\n----", results); } } } diff --git a/rust-runtime/aws-smithy-fuzz/src/types.rs b/rust-runtime/aws-smithy-fuzz/src/types.rs index fe25638ebb..64b4dfcec8 100644 --- a/rust-runtime/aws-smithy-fuzz/src/types.rs +++ b/rust-runtime/aws-smithy-fuzz/src/types.rs @@ -101,7 +101,10 @@ impl Debug for TryString<'_> { let try_cbor = cbor_diag::parse_bytes(self.0); let str_rep = match try_cbor { Ok(repr) => repr.to_diag_pretty(), - Err(e) => String::from_utf8_lossy(self.0).to_string(), + Err(e) => { + eprintln!("not cbor: {}", e); + String::from_utf8_lossy(self.0).to_string() + } }; write!(f, "\"{}\"", str_rep) }