Set the number of stacked mutations in MOpt mutator (#587)

* max_stack_pow

* fix

* fix

* fmt

* rename
This commit is contained in:
Dongjia Zhang 2022-04-03 09:25:59 +09:00 committed by GitHub
parent 1167389149
commit 034a4870e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 56 additions and 19 deletions

View File

@ -145,7 +145,7 @@ pub fn main() {
.expect("Failed to generate the initial corpus"); .expect("Failed to generate the initial corpus");
// Setup a mutational stage with a basic bytes mutator // Setup a mutational stage with a basic bytes mutator
let mutator = StdScheduledMutator::with_max_iterations( let mutator = StdScheduledMutator::with_max_stack_pow(
tuple_list!( tuple_list!(
GramatronRandomMutator::new(&generator), GramatronRandomMutator::new(&generator),
GramatronRandomMutator::new(&generator), GramatronRandomMutator::new(&generator),

View File

@ -145,8 +145,8 @@ pub fn main() {
.expect("Failed to create the Executor"); .expect("Failed to create the Executor");
// Setup a mutational stage with a basic bytes mutator // Setup a mutational stage with a basic bytes mutator
let mutator = StdScheduledMutator::with_max_iterations(havoc_mutations(), 2); let mutator = StdScheduledMutator::with_max_stack_pow(havoc_mutations(), 2);
let grimoire_mutator = StdScheduledMutator::with_max_iterations( let grimoire_mutator = StdScheduledMutator::with_max_stack_pow(
tuple_list!( tuple_list!(
GrimoireExtensionMutator::new(), GrimoireExtensionMutator::new(),
GrimoireRecursiveReplacementMutator::new(), GrimoireRecursiveReplacementMutator::new(),

View File

@ -141,7 +141,7 @@ pub fn main() {
.expect("Failed to generate the initial corpus"); .expect("Failed to generate the initial corpus");
// Setup a mutational stage with a basic bytes mutator // Setup a mutational stage with a basic bytes mutator
let mutator = StdScheduledMutator::with_max_iterations( let mutator = StdScheduledMutator::with_max_stack_pow(
tuple_list!( tuple_list!(
NautilusRandomMutator::new(&context), NautilusRandomMutator::new(&context),
NautilusRandomMutator::new(&context), NautilusRandomMutator::new(&context),

View File

@ -116,7 +116,7 @@ pub fn main() {
.expect("Failed to create the Executor"); .expect("Failed to create the Executor");
// Setup a mutational stage with a basic bytes mutator // Setup a mutational stage with a basic bytes mutator
let mutator = StdScheduledMutator::with_max_iterations(encoded_mutations(), 2); let mutator = StdScheduledMutator::with_max_stack_pow(encoded_mutations(), 2);
let mut stages = tuple_list!(StdMutationalStage::new(mutator)); let mut stages = tuple_list!(StdMutationalStage::new(mutator));
println!("Decoder {:?} ...", &encoder_decoder); println!("Decoder {:?} ...", &encoder_decoder);

View File

@ -306,7 +306,12 @@ fn fuzz(
let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new()))); let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new())));
// Setup a MOPT mutator // Setup a MOPT mutator
let mutator = StdMOptMutator::new(&mut state, havoc_mutations().merge(tokens_mutations()), 5)?; let mutator = StdMOptMutator::new(
&mut state,
havoc_mutations().merge(tokens_mutations()),
7,
5,
)?;
let power = let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST); StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);

View File

@ -277,7 +277,12 @@ fn fuzz(
let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new()))); let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new())));
// Setup a MOPT mutator // Setup a MOPT mutator
let mutator = StdMOptMutator::new(&mut state, havoc_mutations().merge(tokens_mutations()), 5)?; let mutator = StdMOptMutator::new(
&mut state,
havoc_mutations().merge(tokens_mutations()),
7,
5,
)?;
let power = let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST); StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);

View File

@ -290,7 +290,12 @@ fn fuzz(
let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new()))); let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new())));
// Setup a MOPT mutator // Setup a MOPT mutator
let mutator = StdMOptMutator::new(&mut state, havoc_mutations().merge(tokens_mutations()), 5)?; let mutator = StdMOptMutator::new(
&mut state,
havoc_mutations().merge(tokens_mutations()),
7,
5,
)?;
let power = let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST); StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);

View File

@ -367,7 +367,12 @@ fn fuzz_binary(
let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new()))); let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new())));
// Setup a MOPT mutator // Setup a MOPT mutator
let mutator = StdMOptMutator::new(&mut state, havoc_mutations().merge(tokens_mutations()), 5)?; let mutator = StdMOptMutator::new(
&mut state,
havoc_mutations().merge(tokens_mutations()),
7,
5,
)?;
let power = let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST); StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);
@ -572,12 +577,17 @@ fn fuzz_text(
let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new()))); let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new())));
// Setup a MOPT mutator // Setup a MOPT mutator
let mutator = StdMOptMutator::new(&mut state, havoc_mutations().merge(tokens_mutations()), 5)?; let mutator = StdMOptMutator::new(
&mut state,
havoc_mutations().merge(tokens_mutations()),
7,
5,
)?;
let power = let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST); StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);
let grimoire_mutator = StdScheduledMutator::with_max_iterations( let grimoire_mutator = StdScheduledMutator::with_max_stack_pow(
tuple_list!( tuple_list!(
GrimoireExtensionMutator::new(), GrimoireExtensionMutator::new(),
GrimoireRecursiveReplacementMutator::new(), GrimoireRecursiveReplacementMutator::new(),

View File

@ -306,7 +306,12 @@ fn fuzz(
let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new()))); let i2s = StdMutationalStage::new(StdScheduledMutator::new(tuple_list!(I2SRandReplace::new())));
// Setup a MOPT mutator // Setup a MOPT mutator
let mutator = StdMOptMutator::new(&mut state, havoc_mutations().merge(tokens_mutations()), 5)?; let mutator = StdMOptMutator::new(
&mut state,
havoc_mutations().merge(tokens_mutations()),
7,
5,
)?;
let power = let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST); StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::FAST);

View File

@ -369,6 +369,7 @@ where
mode: MOptMode, mode: MOptMode,
finds_before: usize, finds_before: usize,
mutations: MT, mutations: MT,
max_stack_pow: u64,
phantom: PhantomData<(I, S)>, phantom: PhantomData<(I, S)>,
} }
@ -531,7 +532,12 @@ where
S: HasRand + HasMetadata + HasCorpus<I> + HasSolutions<I>, S: HasRand + HasMetadata + HasCorpus<I> + HasSolutions<I>,
{ {
/// Create a new [`StdMOptMutator`]. /// Create a new [`StdMOptMutator`].
pub fn new(state: &mut S, mutations: MT, swarm_num: usize) -> Result<Self, Error> { pub fn new(
state: &mut S,
mutations: MT,
max_stack_pow: u64,
swarm_num: usize,
) -> Result<Self, Error> {
if !state.has_metadata::<MOpt>() { if !state.has_metadata::<MOpt>() {
state.add_metadata::<MOpt>(MOpt::new(mutations.len(), swarm_num)?); state.add_metadata::<MOpt>(MOpt::new(mutations.len(), swarm_num)?);
} }
@ -539,6 +545,7 @@ where
mode: MOptMode::Pilotfuzzing, mode: MOptMode::Pilotfuzzing,
finds_before: 0, finds_before: 0,
mutations, mutations,
max_stack_pow,
phantom: PhantomData, phantom: PhantomData,
}) })
} }
@ -637,7 +644,7 @@ where
{ {
/// Compute the number of iterations used to apply stacked mutations /// Compute the number of iterations used to apply stacked mutations
fn iterations(&self, state: &mut S, _: &I) -> u64 { fn iterations(&self, state: &mut S, _: &I) -> u64 {
1 << (1 + state.rand_mut().below(6)) 1 << (1 + state.rand_mut().below(self.max_stack_pow))
} }
/// Get the next mutation to apply /// Get the next mutation to apply

View File

@ -109,7 +109,7 @@ where
S: HasRand, S: HasRand,
{ {
mutations: MT, mutations: MT,
max_iterations: u64, max_stack_pow: u64,
phantom: PhantomData<(I, S)>, phantom: PhantomData<(I, S)>,
} }
@ -173,7 +173,7 @@ where
{ {
/// Compute the number of iterations used to apply stacked mutations /// Compute the number of iterations used to apply stacked mutations
fn iterations(&self, state: &mut S, _: &I) -> u64 { fn iterations(&self, state: &mut S, _: &I) -> u64 {
1 << (1 + state.rand_mut().below(self.max_iterations)) 1 << (1 + state.rand_mut().below(self.max_stack_pow))
} }
/// Get the next mutation to apply /// Get the next mutation to apply
@ -193,16 +193,16 @@ where
pub fn new(mutations: MT) -> Self { pub fn new(mutations: MT) -> Self {
StdScheduledMutator { StdScheduledMutator {
mutations, mutations,
max_iterations: 6, max_stack_pow: 7,
phantom: PhantomData, phantom: PhantomData,
} }
} }
/// Create a new [`StdScheduledMutator`] instance specifying mutations and the maximun number of iterations /// Create a new [`StdScheduledMutator`] instance specifying mutations and the maximun number of iterations
pub fn with_max_iterations(mutations: MT, max_iterations: u64) -> Self { pub fn with_max_stack_pow(mutations: MT, max_stack_pow: u64) -> Self {
StdScheduledMutator { StdScheduledMutator {
mutations, mutations,
max_iterations, max_stack_pow,
phantom: PhantomData, phantom: PhantomData,
} }
} }