Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Replace sha1 with sha256 in Windows input-tester (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzybkr authored Oct 8, 2020
1 parent ed370a0 commit 1c5be99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
17 changes: 2 additions & 15 deletions src/agent/Cargo.lock

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

4 changes: 2 additions & 2 deletions src/agent/input-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ atexit = { path = "../atexit" }
coverage = { path = "../coverage" }
debugger = { path = "../debugger" }
fnv = "1.0"
hex = "0.4"
log = "0.4"
num_cpus = "1.13"
rayon = "1.3"
sha-1 = "0.9"
uuid = { version = "0.8", features = ["serde", "v4"] }
sha2 = "0.9"
win-util = { path = "../win-util" }

[dependencies.winapi]
Expand Down
18 changes: 6 additions & 12 deletions src/agent/input-tester/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use std::{
collections::HashMap,
fs,
io::{Read, Write},
io::Write,
path::{Path, PathBuf},
sync::Arc,
time::Duration,
Expand All @@ -23,7 +23,7 @@ use coverage::AppCoverageBlocks;
use log::{error, info, trace, warn};
use num_cpus;
use rayon::{prelude::*, ThreadPoolBuilder};
use sha1::{Digest, Sha1};
use sha2::{Digest, Sha256};

use crate::{
appverifier::{self, AppVerifierController, AppVerifierState},
Expand Down Expand Up @@ -450,18 +450,12 @@ fn most_serious_exception(result: &DebuggerResult) -> &Exception {
a_throw.unwrap_or(&result.exceptions[0])
}

/// Read the file and hash the file contents using sha1.
/// We don't have security concerns, so a collision attack is a non-issue. Also, both git and
/// libfuzzer use sha1, so it's still a reasonable choice.
///
/// Read the file and hash the file contents using sha2.
/// Returns the digest of the hash as a string in lowercase hex.
fn hash_file_contents(file: impl AsRef<Path>) -> Result<String> {
let mut file = fs::File::open(file.as_ref())
.with_context(|| format!("opening {} to hash", file.as_ref().display()))?;
let mut data = Vec::new();
file.read_to_end(&mut data)?;
let digest = Sha1::digest(&data);
Ok(format!("{:040x}", &digest))
let data = fs::read(file.as_ref())?;
let digest = Sha256::digest(&data);
Ok(hex::encode(&digest[..]))
}

/// Copy file to directory, but hash the file contents to use as the filename
Expand Down

0 comments on commit 1c5be99

Please sign in to comment.