rust-fuzz / libfuzzer

Rust bindings and utilities for LLVM’s libFuzzer
Apache License 2.0
210 stars 44 forks source link

Soundness issue in rust_fuzzer_custom_mutator #113

Closed gigaroby closed 1 year ago

gigaroby commented 1 year ago

While conducting an internal unsafe review @cramertj found issues in rust_fuzzer_custom_mutator:

This function should also be unsafe since it makes assumptions about $data, $size, and $max_size when calling from_raw_parts_mut. Additionally, as far as I can tell, there is no guarantee here that data has been initialized up to max_size, so it's not safe to use with from_raw_parts_mut, as this would allow the user to read from uninitialized memory. Misoptimizations seem unlikely to be an issue in practice due to the FFI boundary, however.

https://github.com/rust-fuzz/libfuzzer/blob/c9c43f308b98a03b295e6a2e81089950b42c6ee1/src/lib.rs#L464-L485