Skip to content

Numeric BitFlipMutator only flips 1/8th of bits #3851

Description

@stuxnot

Hi!

Thank you for all your work on LibAFL!

While looking at the numeric mutators, I noticed that the BitFlipMutator uses size_of::<I>() as the upper bound for the flipped bits index, but afaik size_of returns the byte size of the type.

let offset = state.rand_mut().choose(0..size_of::<I>()).unwrap();
input.flip_bit_at(offset);

This would make the mutator only ever flip 1/8th of the possible bits (assuming all bits are used).

Since I was implementing Numeric for a custom type, I'd love to see a fix that extends Numeric with a bits() method instead of multiplying the result of size_of by eight.

I'd be more than happy to create a PR for whatever solution you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions