Skip to content

Commit

Permalink
Fix negative stability (AFLplusplus#2731)
Browse files Browse the repository at this point in the history
* fix

* FMT
  • Loading branch information
tokatoka authored Nov 26, 2024
1 parent 41c1c54 commit 49d1b18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fuzzers/baby/baby_fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libafl::monitors::SimpleMonitor;
use libafl::{
corpus::{InMemoryCorpus, OnDiskCorpus},
events::SimpleEventManager,
executors::{InProcessExecutor, ExitKind},
executors::{ExitKind, InProcessExecutor},
feedbacks::{CrashFeedback, MaxMapFeedback},
fuzzer::{Fuzzer, StdFuzzer},
generators::RandPrintablesGenerator,
Expand Down
12 changes: 8 additions & 4 deletions libafl/src/stages/calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,19 @@ where
map_first_filled_count, 0,
"The map's filled count must never be 0"
);
// In theory `map_first_filled_count - unstable_entries` could be negative.
// Because `map_first_filled_count` is the filled count of just one single run.
// While the `unstable_entries` is the number of all the unstable entries across multiple runs.
// If the target is very unstable (~100%) then this would hit more edges than `map_first_filled_count`.
// But even in that case, we don't allow negative stability and just show 0% here.
let stable_count: u64 =
map_first_filled_count.saturating_sub(unstable_entries) as u64;
mgr.fire(
state,
Event::UpdateUserStats {
name: Cow::from("stability"),
value: UserStats::new(
UserStatsValue::Ratio(
(map_first_filled_count - unstable_entries) as u64,
map_first_filled_count as u64,
),
UserStatsValue::Ratio(stable_count, map_first_filled_count as u64),
AggregatorOps::Avg,
),
phantom: PhantomData,
Expand Down

0 comments on commit 49d1b18

Please sign in to comment.