Skip to content

Commit

Permalink
Use xxhash64 instead of md5
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed Dec 5, 2024
1 parent a83bd48 commit 3502538
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 12 deletions.
101 changes: 100 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ libc = { version = "0.2.153", optional = true }
semver = { version = "1.0.23", optional = true }
strip-ansi-escapes = { version = "0.2.0", optional = true }
time-humanize = { version = "0.1.3", optional = true }
twox-hash = { version = "2.0.1", optional = true }

[features]
default = ["cli"]
Expand All @@ -40,6 +41,7 @@ cli = [
"libc",
"time-humanize",
"cargo_metadata",
"twox-hash",
]
coverage = ["fork", "libc"]

Expand Down
8 changes: 4 additions & 4 deletions src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
};
use strip_ansi_escapes::strip_str;
use twox_hash::XxHash64;

/// Main logic for managing fuzzers and the fuzzing process in ziggy.
/// ## Initial minimization logic
Expand Down Expand Up @@ -341,10 +342,9 @@ impl Fuzz {
);
}
// Hash the file to get its file name
let hasher = process::Command::new("md5sum").arg(file).output().unwrap();
let hash_vec = hasher.stdout.split(|&b| b == b' ').next().unwrap_or(&[]);
let hash = std::str::from_utf8(hash_vec).unwrap_or_default();
let _ = fs::copy(file, format!("{}/corpus/{hash}", self.output_target()));
let bytes = fs::read(file).unwrap_or_default();
let hash = XxHash64::oneshot(0, &bytes);
let _ = fs::copy(file, format!("{}/corpus/{hash:x}", self.output_target()));
}
}
last_synced_created_time = newest_time;
Expand Down
11 changes: 4 additions & 7 deletions src/bin/cargo-ziggy/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
process, thread,
time::Duration,
};
use twox_hash::XxHash64;

impl Minimize {
pub fn minimize(&mut self) -> Result<(), anyhow::Error> {
Expand Down Expand Up @@ -58,13 +59,9 @@ impl Minimize {
// We rename every file to its md5 hash
let min_entries = fs::read_dir(self.output_corpus())?;
for file in min_entries.flatten() {
let hasher = process::Command::new("md5sum")
.arg(file.path())
.output()
.unwrap();
let hash_vec = hasher.stdout.split(|&b| b == b' ').next().unwrap_or(&[]);
let hash = std::str::from_utf8(hash_vec).unwrap_or_default();
let _ = fs::rename(file.path(), format!("{}/{hash}", self.output_corpus()));
let bytes = fs::read(file.path()).unwrap_or_default();
let hash = XxHash64::oneshot(0, &bytes);
let _ = fs::rename(file.path(), format!("{}/{hash:x}", self.output_corpus()));
}

let min_entries_hashed = fs::read_dir(self.output_corpus())?;
Expand Down

0 comments on commit 3502538

Please sign in to comment.