Skip to content

Commit

Permalink
fuzz: add Decoder fuzzing
Browse files Browse the repository at this point in the history
This uses the spec tests as seeding value.
  • Loading branch information
Jorropo committed Jun 8, 2022
1 parent 714f5c0 commit 376e246
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,36 @@ func TestSpecVectors(t *testing.T) {
})
}
}

func FuzzDecode(f *testing.F) {
files, err := filepath.Glob("spec/tests/*.csv")
if err != nil {
f.Fatal(err)
}
for _, fname := range files {
func() {
file, err := os.Open(fname)
if err != nil {
f.Fatal(err)
}
defer file.Close()
reader := csv.NewReader(file)
reader.LazyQuotes = false
reader.FieldsPerRecord = 2
reader.TrimLeadingSpace = true

values, err := reader.ReadAll()
if err != nil {
f.Fatal(err)
}

for _, tc := range values[1:] {
f.Add(tc[1])
}
}()
}

f.Fuzz(func(_ *testing.T, data string) {
Decode(data)
})
}

0 comments on commit 376e246

Please sign in to comment.