1
1
mirror of https://github.com/wader/fq.git synced 2024-11-22 15:45:45 +03:00

fuzz: make fuzz GROUP=mp4 to fuzz one group

This commit is contained in:
Mattias Wadman 2022-10-10 21:06:01 +02:00
parent e9aa4837e9
commit cef4245b49
2 changed files with 17 additions and 3 deletions

View File

@ -95,10 +95,13 @@ update-gomod:
GOPROXY=direct go get -d github.com/wader/gojq@fq
go mod tidy
# Usage: make fuzz # fuzz all foramts
# Usage: make fuzz GROUP=mp4 # fuzz a group (each format is a group also)
# TODO: as decode recovers panic and "repanics" unrecoverable errors this is a bit hacky at the moment
# fuzz code is not suppose to print to stderr so log to file
# Retrigger:
# try to decode crsash with all formats:
# cat format/testdata/fuzz/FuzzFormats/... | go run dev/fuzzbytes.go | go run . -d raw '. as $b | formats | keys[] as $f | $b | decode($f)'
# convert crash into raw bytes:
# cat format/testdata/fuzz/FuzzFormats/... | go run dev/fuzzbytes.go | fq -d raw 'tobytes | tobase64'
# fq -n '"..." | frombase64 | ...'
.PHONY: fuzz

View File

@ -66,7 +66,7 @@ func (ft *fuzzTest) Readline(opts interp.ReadlineOpts) (string, error) {
func FuzzFormats(f *testing.F) {
if os.Getenv("FUZZTEST") == "" {
f.Skip("run with FUZZTEST=1 do fuzz")
f.Skip("run with FUZZTEST=1 to fuzz")
}
i := 0
@ -103,7 +103,18 @@ func FuzzFormats(f *testing.F) {
}
gi := 0
g := interp.DefaultRegistry.MustAll()
var g decode.Group
if n := os.Getenv("GROUP"); n != "" {
var err error
g, err = interp.DefaultRegistry.FormatGroup(n)
if err != nil {
f.Fatal(err)
}
f.Logf("GROUP=%s", n)
} else {
g = interp.DefaultRegistry.MustAll()
}
f.Fuzz(func(t *testing.T, b []byte) {
fz := &fuzzTest{b: b, f: g[gi]}