Skip to content

Commit f983d80

Browse files
committed
Make input loading fallible in SyncFromDiskStage
1 parent c0e32cd commit f983d80

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

libafl/src/stages/sync.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ use core::{marker::PhantomData, time::Duration};
88
use std::path::{Path, PathBuf};
99

1010
use libafl_bolts::{
11-
Named, current_time,
11+
current_time,
1212
fs::find_new_files_rec,
1313
shmem::{ShMem, ShMemProvider},
14+
Named,
1415
};
1516
use serde::{Deserialize, Serialize};
1617

1718
use crate::{
18-
Error, HasMetadata, HasNamedMetadata,
1919
corpus::{Corpus, CorpusId, HasCurrentCorpusId},
20-
events::{Event, EventConfig, EventFirer, EventWithStats, llmp::LlmpEventConverter},
20+
events::{llmp::LlmpEventConverter, Event, EventConfig, EventFirer, EventWithStats},
2121
executors::{Executor, ExitKind, HasObservers},
2222
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor, HasObjective},
2323
inputs::{Input, InputConverter},
@@ -26,6 +26,7 @@ use crate::{
2626
HasCorpus, HasCurrentTestcase, HasExecutions, HasRand, HasSolutions,
2727
MaybeHasClientPerfMonitor, Stoppable,
2828
},
29+
Error, HasMetadata, HasNamedMetadata,
2930
};
3031

3132
/// Default name for `SyncFromDiskStage`; derived from AFL++
@@ -75,7 +76,7 @@ impl<CB, E, EM, I, S, Z> Named for SyncFromDiskStage<CB, E, EM, I, S, Z> {
7576

7677
impl<CB, E, EM, I, S, Z> Stage<E, EM, S, Z> for SyncFromDiskStage<CB, E, EM, I, S, Z>
7778
where
78-
CB: FnMut(&mut Z, &mut S, &Path) -> Result<I, Error>,
79+
CB: FnMut(&mut Z, &mut S, &Path) -> Result<Option<I>, Error>,
7980
Z: Evaluator<E, EM, I, S>,
8081
S: HasCorpus<I>
8182
+ HasRand
@@ -134,6 +135,9 @@ where
134135
.unwrap()
135136
.left_to_sync
136137
.retain(|p| p != &path);
138+
let Some(input) = input else {
139+
continue;
140+
};
137141
log::debug!("Syncing and evaluating {path:?}");
138142
fuzzer.evaluate_input(state, executor, manager, &input)?;
139143
}
@@ -174,7 +178,7 @@ impl<CB, E, EM, I, S, Z> SyncFromDiskStage<CB, E, EM, I, S, Z> {
174178
}
175179

176180
/// Function type when the callback in `SyncFromDiskStage` is not a lambda
177-
pub type SyncFromDiskFunction<I, S, Z> = fn(&mut Z, &mut S, &Path) -> Result<I, Error>;
181+
pub type SyncFromDiskFunction<I, S, Z> = fn(&mut Z, &mut S, &Path) -> Result<Option<I>, Error>;
178182

179183
impl<E, EM, I, S, Z> SyncFromDiskStage<SyncFromDiskFunction<I, S, Z>, E, EM, I, S, Z>
180184
where
@@ -185,12 +189,15 @@ where
185189
/// Creates a new [`SyncFromDiskStage`] invoking `Input::from_file` to load inputs
186190
#[must_use]
187191
pub fn with_from_file(sync_dirs: Vec<PathBuf>, interval: Duration) -> Self {
188-
fn load_callback<I, S, Z>(_: &mut Z, _: &mut S, p: &Path) -> Result<I, Error>
192+
fn load_callback<I, S, Z>(_: &mut Z, _: &mut S, p: &Path) -> Result<Option<I>, Error>
189193
where
190194
I: Input,
191195
S: HasCorpus<I>,
192196
{
193-
Input::from_file(p)
197+
match Input::from_file(p) {
198+
Err(err) => Err(err),
199+
Ok(input) => Ok(Some(input)),
200+
}
194201
}
195202
Self {
196203
interval,

0 commit comments

Comments
 (0)