Closed epilys closed 3 years ago
r? @fitzgen
In Rust, the byte array can be exposed as a mutable slice of length
max_len
. In the C API, the user must return the actual length used by the array without any guarantee thatlen <= max_len
. I have added two options in the mutator declaration macro, either provide a mutableVec<u8>
and then trim the vector if its length is more thanmax_len
before copying it back into the C API's slice, or use a custom structBuffer
that works like aVec
but ignores any attempts at adding more bytes if the final length surpassesmax_len
.Buffer
is not a very clean solution, but at least it prevents copying in each mutation step.
I would prefer to more closely match the C API.
Buffer
is roughly a whole copy of std::vec::Vec
, and I don't think maintaining that is the best use of our (this crate's maintainers) resources.
I would prefer to give custom mutators the &mut [u8]
slice created from the data and size, the max length, and the seed, and then expect it to return a usize
new length, and assert that the returned length is less than or equal the max length. Then, if users want to layer Buffer
-style APIs on top of that, they have access to everything they need to do so.
Closing in favor of #79.
This adds a new macro that defines a custom mutator macro for libfuzzer.
Custom mutator
The mutator receives a mutable C array of bytes that is afterwards fed into the fuzzer. The user can use libfuzzer's standard mutator by calling the
llvm_fuzzer_mutate
wrapper function.Handling of the C byte array
In Rust, the byte array can be exposed as a mutable slice of length
max_len
. In the C API, the user must return the actual length used by the array without any guarantee thatlen <= max_len
. I have added two options in the mutator declaration macro, either provide a mutableVec<u8>
and then trim the vector if its length is more thanmax_len
before copying it back into the C API's slice, or use a custom structBuffer
that works like aVec
but ignores any attempts at adding more bytes if the final length surpassesmax_len
.Buffer
is not a very clean solution, but at least it prevents copying in each mutation step.Next steps
If the
Arbritary
trait provides a method to turn objects back into bytes (like mentioned in rust-fuzz/arbitrary/issues/44) the macro can take adata: &mut T
argument so that the user can work directly on an object rather than raw bytes.