diff --git a/go.mod b/go.mod index 7d12202..edcc13d 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/gohugoio/hashstructure go 1.18 + +require github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..32d02fe --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= diff --git a/hashstructure_fuzz_test.go b/hashstructure_fuzz_test.go new file mode 100644 index 0000000..bb449b0 --- /dev/null +++ b/hashstructure_fuzz_test.go @@ -0,0 +1,40 @@ +package hashstructure + +import ( + "testing" + "time" + + fuzz "github.com/AdaLogics/go-fuzz-headers" +) + +func FuzzHash(f *testing.F) { + type Test struct { + Str string + Int int + In64 int64 + Float64 float64 + MapStr map[string]string + MapStruct map[string]Test + SliceStr []string + SliceStrSet []string `hash:"set"` + SliceByte []byte + StrPtr *string + IntPtr *int + Time time.Time + Duration time.Duration + UUID string `hash:"ignore"` + } + + f.Fuzz(func(t *testing.T, data []byte) { + fuzzConsumer := fuzz.NewConsumer(data) + targetStruct := &Test{} + err := fuzzConsumer.GenerateStruct(targetStruct) + if err != nil { + return + } + _, err = Hash(targetStruct, nil) + if err != nil { + t.Fatal(err) + } + }) +}