Make load_initial_inputs work for arbitrary inputs (#121)

This commit is contained in:
Max Ammann 2021-05-24 14:03:32 +02:00 committed by GitHub
parent c94cb53236
commit 1089c93577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,9 +23,6 @@ use crate::{
Error, Error,
}; };
#[cfg(feature = "std")]
use crate::inputs::bytes::BytesInput;
/// The maximum size of a testcase /// The maximum size of a testcase
pub const DEFAULT_MAX_SIZE: usize = 1_048_576; pub const DEFAULT_MAX_SIZE: usize = 1_048_576;
@ -349,12 +346,13 @@ where
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl<C, FT, R, SC> StdState<C, FT, BytesInput, R, SC> impl<C, FT, I, R, SC> StdState<C, FT, I, R, SC>
where where
C: Corpus<BytesInput>, C: Corpus<I>,
I: Input,
R: Rand, R: Rand,
FT: FeedbackStatesTuple, FT: FeedbackStatesTuple,
SC: Corpus<BytesInput>, SC: Corpus<I>,
{ {
/// loads inputs from a directory /// loads inputs from a directory
fn load_from_directory<E, EM, Z>( fn load_from_directory<E, EM, Z>(
@ -365,7 +363,7 @@ where
in_dir: &Path, in_dir: &Path,
) -> Result<(), Error> ) -> Result<(), Error>
where where
Z: Evaluator<E, EM, BytesInput, Self>, Z: Evaluator<E, EM, I, Self>,
{ {
for entry in fs::read_dir(in_dir)? { for entry in fs::read_dir(in_dir)? {
let entry = entry?; let entry = entry?;
@ -380,8 +378,7 @@ where
if attr.is_file() && attr.len() > 0 { if attr.is_file() && attr.len() > 0 {
println!("Loading file {:?} ...", &path); println!("Loading file {:?} ...", &path);
let bytes = fs::read(&path)?; let input = I::from_file(&path)?;
let input = BytesInput::new(bytes);
let (is_interesting, _) = fuzzer.evaluate_input(self, executor, manager, input)?; let (is_interesting, _) = fuzzer.evaluate_input(self, executor, manager, input)?;
if !is_interesting { if !is_interesting {
println!("File {:?} was not interesting, skipped.", &path); println!("File {:?} was not interesting, skipped.", &path);
@ -403,8 +400,8 @@ where
in_dirs: &[PathBuf], in_dirs: &[PathBuf],
) -> Result<(), Error> ) -> Result<(), Error>
where where
Z: Evaluator<E, EM, BytesInput, Self>, Z: Evaluator<E, EM, I, Self>,
EM: EventManager<E, BytesInput, Self, Z>, EM: EventManager<E, I, Self, Z>,
{ {
for in_dir in in_dirs { for in_dir in in_dirs {
self.load_from_directory(fuzzer, executor, manager, in_dir)?; self.load_from_directory(fuzzer, executor, manager, in_dir)?;