Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dummy hotfix for min/max vec lengths during mutation #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sadeli413
Copy link

This adds a naive hotfix for the min/max length constraints for a vec during mutation and (partially) addresses #2.
The downside to my patch is that it may give preferential weight to the far min/max bound.

use lain::prelude::*;
use lain::rand;

#[derive(Debug, Mutatable, NewFuzzed, BinarySerialize)]
struct MyStruct {
    #[lain(min = 5, max = 7)]
    field: Vec<u32>,
}

fn main() {
    let mut mutator = Mutator::new(rand::thread_rng());
    let mut instance = MyStruct::new_fuzzed(&mut mutator, None);

    // Ignore this, initialization is broken atm
    while !(5..=7).contains(&instance.field.len()) {
        mutator = Mutator::new(rand::thread_rng());
        instance = MyStruct::new_fuzzed(&mut mutator, None);
    }

    for _ in 0..1000 {
        instance.mutate(&mut mutator, None);
        assert!((5..=7).contains(&instance.field.len()));
    }
}

@jma-qb
Copy link

jma-qb commented May 16, 2024

Hi, I have a few comments as I also tried to fix this.

@sadeli413
Copy link
Author

Doesn't the patch already fix these three issues?

make sure the max bound is taken into account when growing an empty Vec

The max bound will be constrained by this regardless if the vec is empty or not: https://github.com/AFLplusplus/lain/pull/3/files#diff-79581a1c35413987e75ecf7e6ffa1df8f79c0b2abb9f152fbcefac64056842f5R59

I think you can hit the condition ... with a min size > 0

This makes sure that num_elements will never equal vec.len() if min_size > 0: https://github.com/AFLplusplus/lain/pull/3/files#diff-79581a1c35413987e75ecf7e6ffa1df8f79c0b2abb9f152fbcefac64056842f5R152

you should add a comparison with the min size

The comparison with the min size is already here: https://github.com/AFLplusplus/lain/pull/3/files#diff-79581a1c35413987e75ecf7e6ffa1df8f79c0b2abb9f152fbcefac64056842f5L146-R154

I'm probably missing something so lmk if you see more issues

@jma-qb
Copy link

jma-qb commented May 23, 2024

My bad, you are right and all 3 points I raised were wrong. I ran some tests and there is no issue with the bounds.
But while testing it appears your patch is heavily biased toward generating empty Vecs when the min bound is 0. Could you try confirming it ?

@sadeli413
Copy link
Author

Yep, can confirm. My patch has a bias toward the min and max bounds, since it just chops off values that go over the bounds instead of generating a length between those bounds. This will have to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants