Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.