-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add crash input generation to wasmi_fuzz * generate crash reports in `translate` and `diferential` fuzzers
- Loading branch information
Showing
6 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use core::fmt::Write as _; | ||
use sha2::{Digest, Sha256}; | ||
use std::fs; | ||
|
||
/// Writes `.wasm` and `.wat` files for `target` with `wasm` contents. | ||
/// | ||
/// Returns the `hex` encoded string of the SHA-2 of the `wasm` input upon success. | ||
/// | ||
/// # Errors | ||
/// | ||
/// - If hex encoding fails. | ||
/// - If converting `.wasm` to `.wat` fails. | ||
/// - If writing the `.wasm` or `.wat` files fails. | ||
pub fn generate_crash_inputs(target: &str, wasm: &[u8]) -> Result<String, anyhow::Error> { | ||
let mut sha2 = Sha256::default(); | ||
sha2.update(wasm); | ||
let hash: [u8; 32] = sha2.finalize().into(); | ||
let hash_str = hash_str(hash)?; | ||
let wat = wasmprinter::print_bytes(wasm)?; | ||
let file_path = format!("fuzz/crash-inputs/{target}/crash-{hash_str}"); | ||
fs::write(format!("{file_path}.wasm"), wasm)?; | ||
fs::write(format!("{file_path}.wat"), wat)?; | ||
Ok(hash_str) | ||
} | ||
|
||
/// Returns the `hex` string of the `[u8; 32]` hash. | ||
fn hash_str(hash: [u8; 32]) -> Result<String, anyhow::Error> { | ||
let mut s = String::new(); | ||
for byte in hash { | ||
write!(s, "{byte:02X}")?; | ||
} | ||
Ok(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
pub mod config; | ||
mod crash_inputs; | ||
mod error; | ||
#[cfg(feature = "differential")] | ||
pub mod oracle; | ||
mod value; | ||
|
||
pub use self::{ | ||
config::{FuzzSmithConfig, FuzzWasmiConfig}, | ||
crash_inputs::generate_crash_inputs, | ||
error::{FuzzError, TrapCode}, | ||
value::{FuzzVal, FuzzValType}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters