Skip to content

proposal: testing: custom mutator support for fuzzing #48815

@s3nt3

Description

@s3nt3

As the official fuzzer implementation provided by golang, the native fuzzer should be well suited for various usage scenarios. However, currently native fuzzers only support general mutation algorithms for built-in types. Therefore, in many cases, the native fuzzer cannot efficiently generate test inputs. For example, when testing a DSL parser, the mutator will generate a large amount of output that cannot pass the syntax or semantic check. A possible solution is to provide support for custom mutators, so that users can implement custom mutators for various fuzz targets and reuse other parts of the native fuzzer.

I tried on the existing code and designed the following interface:

 type CustomMutator interface {
     Marshal() ([]byte, error)
     Unmarshal([]byte) error
     Mutate() error
 }

The object that implements the above interface can be passed as an argument to the testing.F.Fuzz method, and it will call the Mutate method to use the custom mutation algorithm. The Marshal and Unmarshal methods ensure that it can be imported/exported to a corpus file.

I think supporting custom mutator will bring the following benefits:

  • the usage scenarios of native fuzzer are expanded
  • it is more convenient for the community to test and optimize mutation algorithms
  • the interface of custom mutator is very similar to the struct mutation interface mentioned in the draft proposal, so implementing a custom mutator may be a way to support struct mutation

In addition, custom mutator will also bring some side effects, such as the custom mutator code will be instrumented, which may affect performance and the accuracy of coverage statistics.

/cc @jayconrod

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ProposalfuzzIssues related to native fuzzing support

    Type

    No type

    Projects

    Status

    Incoming

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions