cargo-fuzz icon indicating copy to clipboard operation
cargo-fuzz copied to clipboard

Fuzzing fixed-size array causes compile error

Open huxi opened this issue 6 years ago • 0 comments

#![no_main]
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: [u8; 16]| {
   // fuzzed code goes here
});

causes the following error:

error[E0463]: can't find crate for `arbitrary`
 --> fuzz_targets/fuzz_target_1.rs:4:1
  |
4 | / fuzz_target!(|data: [u8; 16]| {
5 | |    // fuzzed code goes here
6 | | });
  | |___^ can't find crate
  |
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

I tried to fix this by adding the missing crate to fuzz/Cargo.toml.

[dependencies.arbitrary]
version = "0.2"

but this caused the following error:

error[E0308]: mismatched types
 --> fuzz_targets/fuzz_target_1.rs:4:1
  |
4 | / fuzz_target!(|data: [u8; 16]| {
5 | |    // fuzzed code goes here
6 | | });
  | |___^ expected enum `arbitrary::BufferError`, found &str
  |
  = note: expected type `std::result::Result<_, arbitrary::BufferError>`
             found type `std::result::Result<_, &str>`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

To fix the problem, I had to switch back to the 0.1 version of the arbitrary crate.

[dependencies.arbitrary]
# breaks with 0.2
version = "0.1"

I think the dependency should be automatically included instead.

huxi avatar Aug 05 '19 19:08 huxi