Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try out go fuzzing beta #39

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build gofuzzbeta

package rjson

import (
"io/ioutil"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func FuzzMe(f *testing.F) {
corpusDir := filepath.FromSlash(`testdata/fuzz/corpus`)
dir, err := ioutil.ReadDir(corpusDir)
require.NoError(f, err)
for _, info := range dir {
if info.IsDir() {
continue
}
dd, err := ioutil.ReadFile(filepath.Join(corpusDir, info.Name()))
require.NoError(f, err)
f.Add(string(dd))
}

f.Fuzz(func(t *testing.T, data string) {
for _, fd := range fuzzers {
d := make([]byte, len(data))
copy(d, data)
_, err := fd.fn(d)
require.NoError(t, err)
}
})
}
22 changes: 15 additions & 7 deletions script/fuzz
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ set -e
CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")"
make -s bin/go-fuzz bin/go-fuzz-build bin/jq
PATH="$(pwd)/bin:$PATH"
pkg="github.com/willabides/rjson"

mkdir -p tmp
GOBIN="$(pwd)/bin" GO111MODULE=off go get golang.org/dl/gotip

# make a list of all dependencies outside of this repo so they won't be instrumented by go-fuzz
preservers="$(go list -f '{{ join .Deps "\n" }}' | grep -v rjson | tr '\n' ',')"
if ! gotip version; then
gotip download dev.fuzz
fi

go get github.com/dvyukov/go-fuzz@6a8e9d1f241
trap "go mod tidy" EXIT
fuzz_cache_dir="$(gotip env GOCACHE)/fuzz/$pkg/FuzzMe"

go-fuzz-build -o tmp/fuzz-rjson.zip -preserve "$preservers"
cp_cache() {
mkdir -p testdata/corpus
if [ -d "$fuzz_cache_dir" ]; then
cp -r "$fuzz_cache_dir" testdata/corpus
fi
}

go-fuzz -dup -bin tmp/fuzz-rjson.zip -procs 4 -workdir testdata/fuzz
trap "cp_cache" EXIT

gotip test -run '^$' -fuzz FuzzMe -v "$@" .
27 changes: 1 addition & 26 deletions script/fuzz-timeout
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,4 @@ set -e

CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")"

timeout="$1"

if [ -z "$timeout" ]; then
echo 'usage: script/fuzz-timeout <timeout in seconds>'
exit 2
fi

make -s bin/go-fuzz bin/go-fuzz-build bin/jq
PATH="$(pwd)/bin:$PATH"

mkdir -p tmp

go get github.com/dvyukov/go-fuzz@6a8e9d1f241
trap "go mod tidy" EXIT

go-fuzz-build -o tmp/fuzz-rjson.zip

go-fuzz -dup -bin tmp/fuzz-rjson.zip -workdir testdata/fuzz &

pid=$!

sleep "$timeout"

kill -2 $pid

echo "done"
script/fuzz -fuzztime "${1}s"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("\":T4\":T4\x9dǂ@TE88\x02\x00\"\":\x00\xff")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[\x00\x80D")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[73<<<<<<@,0\x15")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"\x00\x00\x00 \x00\x00w0")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("\t\xa4\u007f\x00\x88\xa0\xab\x8dU~~~~~~~\x8d\u007f\u007f\xe3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\r\x00\x00\x00\u007f\x00\x00\x000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("\"w\\uAw\\l00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7E3,0\x03\xce\xcd\xf6\x16WD7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[{\x05B:\"")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string(" \"\u007f\xffzbe{\": \xa5\xa5\xa5\xa5\xa5\x00\x00\x00\x80!@ \"\u007f\xff{\":")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[3E,,3E7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\":88\x02\x00\"\x03\x00\x00\":V4\x9d\xa4\xa2@5E88\x02\x00\"\":\x00\xff")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"w\\u0\xf9l00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[0,\x00],@?")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"0y@\x00\x00\x00w0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\r\x00\x10\x00\u007f\x00\x00\x000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[t,3E0D7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,3E0\x03\xce\xcd\xf6\x19WD7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("\x88\xf7\x95[\v\v\v\v\v\v\v{\"\"\x00@'\x00\x00AAAAA\xf5?u9\xfc[")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[ \xa3\xa3#\xa3 ,[64 ,[73 ,[73 ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\":8,\"8:T4\x9d\xa4\x82\x1b2E88\x02\x00\"\":2E8\" ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[\n\x80K")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[73,,0,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,3E0D7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\":8,\"\":T4\x9d\xa4\x82\x1b2E88\x02\x00\"\":2E88 ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[\xff\xff\x00\x0007D")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,3E0}\xbdp\x00\n")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\r0\x000\x00\x00\x00\x000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[763E0D7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("-㈴Y\x8d\x82\"")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[5,[5,[5,[5,[5,[T,[5,[5,,[5\xf1\xcc\xf5(>>|p\xfa[5,[\u007f\xff<<<<<,[5,[5,[5,[5,[5,[5,[5,[5,[1,[5,[5,[5,[5,[5,[5,[5,[5,[5,[5,[<[5,[T,[,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[-@370h,")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("}\xf9\xf9\xf9\xf9\xf9\xf9\xf9\xf9\xf9\xf9\xf9\xf9\xf9\x17\xfa\xf9\xf9\xf9\xf9\xf9\xf9\xf9 [\x00\x80D")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[\xbd\xbd\x80\x00\x01yO\xd3_\x9f\x00\x00N\xe7'tǪ\r\xb6\xa0\xb72 ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[3\x00\x02D\x00\x02D7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,3?0}\xbdp\x00\n")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\":8,\"R:T,\"\":T4\x9d88\x02\x00\"\":2E8\x82\x82")

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[3\x00d\x1a\x0077")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("n[0?)D")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[71;\x8b\t\xa3\xa3\xa3\xa3\xa3\xa3\xa3 ,[64 ,[73 ,[73 ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7000000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,@,0,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"w\\u\xf6Al0\xf6\xf60\x0e")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,3E07,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{p:'\xa5\xa5\xa5\xa5\xa5\x00\x00\x00\x00\x00\x00\x00{\": \xa5\xa5\xa5\"\u007f\xffzbe\xdd\xdc")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,3E6,,")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\";:\n\xff\"\"\xe8\x03\x00\x00\":T4\x9d\xa4\x82@5e885\x00\"\":\x00\xff")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[7 ,2E0\xb72")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[77,2E@@@")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\":\n\xff\"\"\xe8\x03\x00\x00\":T4\x9d\xa4\x82@5E88\x02\x00\"\":\x00\xff")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[7 \n3\x005\x00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"w\\u55555R50\x85,\xee[e5\xaau\xf9l00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,370E,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[000\xc3\xc30\x1f0 \u007f\xff7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"w\xf65\xf6\xf6\xf6\\\xf6lA000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\x00\x00\xff\u007f\xff\xff\xff,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"G\":[23054625156548201125,51565654820118201125,34015654820118201125,23024625156548201125,44236316680908201125,41565482011820101125,44236316680908201125,41565482011820101125,35156540432630423631]}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\":\xa5\xa5\xa5 \xa5\xa5\v\x14\x80 \x00\x00\"!\u007f\xff\u007f\x00e")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("\"㈴Y\x8d\x82-")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{ 8,\"2\x00\x00\x00\x104\x104\x9d\xa4\x82E88\x00\x00\x00 :2\x00\x00\x16\"")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"w\\5\xf6Al0\xf6\xf6\xf6\xf600")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[{76[{763E03E0DE0D7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[[7,370\x00,")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("\x01\x00\x00\x007\x00,\xe83")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[5'73\n\x005\x00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"w\\u0Al00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[77,2E0D\xff")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[7E,27@@@")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[1\xbd\xbd\xbd\xbd\xbd")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\")[7.5\x00")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\":8,\"\b:T4\x9d\xa4\x82\x1b2E87\xf4\x00\"\":2\x018\" ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"\\uD343\\uD342\\uD343\\uD333\\tD343\\uD343\\uD433\\uD342\\uD343\\uA433\\uD343\\uD343\\uD342\\uD344\\uA433\\uD343\\uD343\\uD343\\uD433\\uD343\\uD343\\uD433\\uD342\\uD343\\uA433\\uD343\\uD343\\uD343\\uD433\\uD342\\uD343\\uA343\\uD433\\uD")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"\xce\xe8\xce\xce\xce\"4\xa4\x82\x1b2b88\x02\x00\"\"\xceT\x9d4\xa4\x82\x1b E88\x01\xde\"\":2 ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("[\"\"\xe8\xce\xce\xce\xce4\xa4\x82\x1b2b88\x02\x00\"\"\xceT\x9d4\xa4\x82\x1b E88\x01\xde\"\":2 ")
Loading