MCPcopy Create free account
hub / github.com/MultiFuzz/MultiFuzz / extend_input_by_rand

Function extend_input_by_rand

hail-fuzz/src/mutations.rs:31–50  ·  view source on GitHub ↗

Extend an input by a random number of bytes exponentially distributed.

(
    rng: &mut R,
    factor: f64,
    dict: DictionaryRef,
    input: &mut Vec<u8>,
    extension_limit: usize,
)

Source from the content-addressed store, hash-verified

29
30/// Extend an input by a random number of bytes exponentially distributed.
31pub(crate) fn extend_input_by_rand<R: Rng>(
32 rng: &mut R,
33 factor: f64,
34 dict: DictionaryRef,
35 input: &mut Vec<u8>,
36 extension_limit: usize,
37) -> Extension {
38 // Small chance try a large extension up to the maximum limit.
39 if rng.gen_bool(0.001) {
40 return extend_input_by(rng, dict, input, extension_limit);
41 }
42
43 let dist = rand_distr::Exp::<f64>::new(LENGTH_EXTENSION_LAMBDA).unwrap();
44 let base = (1 + (factor * dist.sample(rng).floor()) as usize).max(4);
45
46 // Unless the input is small, avoid the extension from being more than twice the input length.
47 let max_extension = (2 * input.len()).max(MIN_EXTENSION_LIMIT * (factor.floor() as usize));
48 let amount = base.min(max_extension).min(extension_limit);
49 extend_input_by(rng, dict, input, amount)
50}
51
52#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize)]
53pub enum Extension {

Callers 1

extend_current_inputMethod · 0.85

Calls 2

extend_input_byFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected