Powerschedule::RAND (#596)

This commit is contained in:
Dongjia Zhang 2022-04-07 21:00:59 +09:00 committed by GitHub
parent e7a06fb30c
commit fa69b9eff9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View File

@ -314,7 +314,7 @@ fn fuzz(
)?;
let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::RAND);
// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(StdWeightedScheduler::new());

View File

@ -132,6 +132,7 @@ impl PowerScheduleMetadata {
#[allow(missing_docs)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub enum PowerSchedule {
RAND,
EXPLORE,
EXPLOIT,
FAST,

View File

@ -192,7 +192,7 @@ where
// COE and Fast schedule are fairly different from what are described in the original thesis,
// This implementation follows the changes made in this pull request https://github.com/AFLplusplus/AFLplusplus/pull/568
match psmeta.strat() {
PowerSchedule::EXPLORE => {
PowerSchedule::EXPLORE | PowerSchedule::RAND => {
// Nothing happens in EXPLORE
}
PowerSchedule::EXPLOIT => {

View File

@ -4,6 +4,7 @@ use alloc::string::{String, ToString};
use core::{fmt::Debug, marker::PhantomData};
use crate::{
bolts::rands::Rand,
corpus::{Corpus, PowerScheduleTestcaseMetaData},
executors::{Executor, HasObservers},
fuzzer::Evaluator,
@ -16,7 +17,7 @@ use crate::{
TestcaseScore,
},
stages::{MutationalStage, Stage},
state::{HasClientPerfMonitor, HasCorpus, HasMetadata},
state::{HasClientPerfMonitor, HasCorpus, HasMetadata, HasRand},
Error,
};
/// The mutational stage using power schedules
@ -47,7 +48,7 @@ where
M: Mutator<I, S>,
O: MapObserver,
OT: ObserversTuple<I, S>,
S: HasClientPerfMonitor + HasCorpus<I> + HasMetadata,
S: HasClientPerfMonitor + HasCorpus<I> + HasMetadata + HasRand,
Z: Evaluator<E, EM, I, S>,
{
/// The mutator, added to this stage
@ -66,6 +67,15 @@ where
#[allow(clippy::cast_sign_loss)]
fn iterations(&self, state: &mut S, corpus_idx: usize) -> Result<usize, Error> {
// Update handicap
let use_random = state
.metadata_mut()
.get_mut::<PowerScheduleMetadata>()
.ok_or_else(|| Error::KeyNotFound("PowerScheduleMetadata not found".to_string()))?
.strat() == PowerSchedule::RAND;
if use_random {
return Ok(1 + state.rand_mut().below(128) as usize)
}
let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut();
let score = F::compute(&mut *testcase, state)? as usize;
let tcmeta = testcase
@ -151,7 +161,7 @@ where
M: Mutator<I, S>,
O: MapObserver,
OT: ObserversTuple<I, S>,
S: HasClientPerfMonitor + HasCorpus<I> + HasMetadata,
S: HasClientPerfMonitor + HasCorpus<I> + HasMetadata + HasRand,
Z: Evaluator<E, EM, I, S>,
{
#[inline]