From bacbffa6c17cfdd5d5d93cbe309d62ce7695c6f9 Mon Sep 17 00:00:00 2001 From: Nils Bars Date: Tue, 24 Sep 2024 03:31:32 +0200 Subject: [PATCH] Keep num_covered_map_indexes in sync with history map if block listing flaky entries (#2542) --- libafl/src/stages/calibrate.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libafl/src/stages/calibrate.rs b/libafl/src/stages/calibrate.rs index 2db948bc0c..d3c5cea325 100644 --- a/libafl/src/stages/calibrate.rs +++ b/libafl/src/stages/calibrate.rs @@ -212,11 +212,11 @@ where .as_ref() .to_vec(); - let history_map = &mut state + let map_state = state .named_metadata_map_mut() .get_mut::>(&self.map_name) - .unwrap() - .history_map; + .unwrap(); + let history_map = &mut map_state.history_map; if history_map.len() < map_first_len { history_map.resize(map_first_len, O::Entry::default()); @@ -228,6 +228,10 @@ where .enumerate() { if *first != *cur && *history != O::Entry::max_value() { + // If we just hit a history map entry that was not covered before, but is now flagged as flaky, + // we need to make sure the `num_covered_map_indexes` is kept in sync. + map_state.num_covered_map_indexes += + usize::from(*history == O::Entry::default()); *history = O::Entry::max_value(); unstable_entries.push(idx); };