Skip to content

Commit c97d0fa

Browse files
authored
Allow MinimizerScheduler to not cleanup metadata after use (#1658)
* Allow MinimizerScheduler to not cleanup the metadata after use. * Fix constructor * cargo fmt and fix docstring.
1 parent 6089cc2 commit c97d0fa

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

libafl/src/schedulers/minimizer.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl Default for TopRatedsMetadata {
7373
pub struct MinimizerScheduler<CS, F, M> {
7474
base: CS,
7575
skip_non_favored_prob: u64,
76+
remove_metadata: bool,
7677
phantom: PhantomData<(F, M)>,
7778
}
7879

@@ -293,7 +294,7 @@ where
293294
old_meta.refcnt() <= 0
294295
};
295296

296-
if must_remove {
297+
if must_remove && self.remove_metadata {
297298
drop(old.metadata_map_mut().remove::<M>());
298299
}
299300
}
@@ -304,7 +305,7 @@ where
304305
*meta.refcnt_mut() = new_favoreds.len() as isize;
305306
}
306307

307-
if new_favoreds.is_empty() {
308+
if new_favoreds.is_empty() && self.remove_metadata {
308309
drop(
309310
state
310311
.corpus()
@@ -368,10 +369,25 @@ where
368369

369370
/// Creates a new [`MinimizerScheduler`] that wraps a `base` [`Scheduler`]
370371
/// and has a default probability to skip non-faved [`Testcase`]s of [`DEFAULT_SKIP_NON_FAVORED_PROB`].
372+
/// This will remove the metadata `M` when it is no longer needed, after consumption. This might
373+
/// for example be a `MapIndexesMetadata`.
371374
pub fn new(base: CS) -> Self {
372375
Self {
373376
base,
374377
skip_non_favored_prob: DEFAULT_SKIP_NON_FAVORED_PROB,
378+
remove_metadata: true,
379+
phantom: PhantomData,
380+
}
381+
}
382+
383+
/// Creates a new [`MinimizerScheduler`] that wraps a `base` [`Scheduler`]
384+
/// and has a default probability to skip non-faved [`Testcase`]s of [`DEFAULT_SKIP_NON_FAVORED_PROB`].
385+
/// This method will prevent the metadata `M` from being removed at the end of scoring.
386+
pub fn non_metadata_removing(base: CS) -> Self {
387+
Self {
388+
base,
389+
skip_non_favored_prob: DEFAULT_SKIP_NON_FAVORED_PROB,
390+
remove_metadata: false,
375391
phantom: PhantomData,
376392
}
377393
}
@@ -382,6 +398,7 @@ where
382398
Self {
383399
base,
384400
skip_non_favored_prob,
401+
remove_metadata: true,
385402
phantom: PhantomData,
386403
}
387404
}

0 commit comments

Comments
 (0)