You may have tried to fuzz a function that takes a struct as a parameter. The direct way of doing this does not work, because the Go fuzzing framework

Search code, repositories, users, issues, pull requests...

submited by
Style Pass
2024-06-07 05:00:10

You may have tried to fuzz a function that takes a struct as a parameter. The direct way of doing this does not work, because the Go fuzzing framework is limited to string, []byte, int, int8, int16, int32/rune, int64, uint, uint8/byte, uint16, uint32, uint64, float32, float64, or bool.

Below you will find two examples using the broken direct method, and one working example using go-fuzz-all to fuzz a function that takes a struct.

If your function takes multiple arguments, create a single struct that contains each argument as a struct field, and fuzz using that type.

fuzzing.Fuzz is called to set up fuzzer. Provide a function fuzzTarget that is called for each iteration of the fuzz test. It should be safe to call from multiple threads and fast.

Leave a Comment