rust-fuzz / honggfuzz-rs

Fuzz your Rust code with Google-developed Honggfuzz !
https://crates.io/crates/honggfuzz
Apache License 2.0
460 stars 42 forks source link

Crashes not recognized as unique #84

Closed Ikrk closed 1 year ago

Ikrk commented 1 year ago

Hi, I have a minimal code example where I would expect to find three unique crashes. However the fuzzer classifies the bugs as identical and therefore only one unique crash file is saved.

use honggfuzz::fuzz;

const MAGIC_NUMBER: u8 = 254;

fn main() {
    loop {
        fuzz!(|data: &[u8]| {
            if data.len() != 2 {
                return;
            }

            let _ = buggy_math_function(data[0], data[1]);

            panic_function(data[0]);
        });
    }
}

pub fn buggy_math_function(input1: u8, input2: u8) -> u8 {
    // causes div-by-zero if input2 == 254
    // causes subtract with overflow if input2 == 255 because overflow-checks = true for profile.release
    let divisor = MAGIC_NUMBER - input2;
    input1 / divisor
}

pub fn panic_function(input1: u8) {
    // panics if input1 == 97
    if input1 == b'a' {
        panic!("BOOM")
    }
}

My setup:

Any help or hints are appreciated.

Ikrk commented 1 year ago

Changing the panic_function to:

pub fn panic_function(input1: u8) {
        if input1 == b'a' {
            let a = vec![1, 2, 3];
            println!("{:?}", a[4]); // array out of bounds
        }
        if input1 == b'b' {
            std::panic::panic_any(4); // another panic
        }
    }

actually finds three unique crashes. So it seems to be related to how honggfuzz actually calculates the stack signature. AFL on the other hand uses executed edges to decide about crash uniqueness.

Closing the issue as it seems to be related to the upstream project.