gofuzz: presence of an interface value always panics

Hello there, thank you for this project!

I am currently looking at using it to fuzz inputs to https://github.com/census-instrumentation/opencensus-service

However, if a struct has a field with a value whose type is an interface, regardless of if that field is set or not. For example

type A struct {
            Name string
            Debug bool
            Err error
}
a := new(A)
f.Fuzz(a)

gofuzz will always crash with

On no value set

panic: Can't handle <nil>: interface [recovered]
	panic: Can't handle <nil>: interface

On value set

panic: Can't handle &errors.errorString{s:"Foo"}: interface [recovered]
	panic: Can't handle &errors.errorString{s:"Foo"}: interface

Perhaps we could skip trying to mutate interface values that we don’t know about and let tests proceed normally, otherwise it becomes unproductive to debug this cryptic error.

Thank you.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 13
  • Comments: 20

Most upvoted comments

Any update? This makes this infeasible to use for any testing using protobuf enums

BTW go has built-in fuzzing now: https://go.dev/doc/fuzz/

It does, but the fuzzing it does is limited, and I still rely on gofuzz. For instance, since Go 1.18’s fuzzer doesn’t fuzz structs, I still do:

func FuzzWithStruct(f *testing.F) {
	f.Add([]byte("seed"))
	f.Fuzz(func(t *testing.T, data []byte) {
		// Set up
		fuzzer := fuzz.NewFromGoFuzz(data)
		testSet := map[PIIField]struct{}{}
		fuzzer.Fuzz(&testSet)

		t.Logf("Set: %+v", testSet)

		// Test
		_ = doThingWithSet(testSet)

		// Verify
		// The point of the fuzz is just to ensure method does not panic
	})
}