Skip to content
Merged
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
30 changes: 30 additions & 0 deletions projects/goipp/fuzzer/fuzz_round_trip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Fuzz target for goipp's EncodeBytes + DecodeBytes round-trip consistency.
*/
package fuzzer

import (
"testing"

"github.com/OpenPrinting/goipp"
)

func FuzzRoundTrip(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
var m goipp.Message
if err := m.DecodeBytes(data); err != nil {
t.Skip()
}

encoded, err := m.EncodeBytes()
if err != nil {
t.Errorf("Failed to encode: %v", err)
return
}

var m2 goipp.Message
if err := m2.DecodeBytes(encoded); err != nil {
t.Errorf("Failed to decode re-encoded: %v", err)
}
})
}
7 changes: 7 additions & 0 deletions projects/goipp/oss_fuzz_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mkdir -p $SRC/goipp/fuzzer
cp $SRC/fuzzing/projects/goipp/fuzzer/fuzz_decode_bytes.go $SRC/goipp/fuzzer/
cp $SRC/fuzzing/projects/goipp/fuzzer/fuzz_decode_bytes_ex.go $SRC/goipp/fuzzer/
cp $SRC/fuzzing/projects/goipp/fuzzer/fuzz_round_trip.go $SRC/goipp/fuzzer/

# seed corpus for FuzzDecodeBytes
mkdir -p $WORK/fuzz_decode_bytes_corpus
Expand All @@ -15,6 +16,11 @@ mkdir -p $WORK/fuzz_decode_bytes_ex_corpus
cp $SRC/fuzzing/projects/goipp/seeds/fuzz_decode_bytes_ex_seed_corpus/* $WORK/fuzz_decode_bytes_ex_corpus/
zip -r $OUT/fuzz_decode_bytes_ex_seed_corpus.zip fuzz_decode_bytes_ex_corpus/

# seed corpus for FuzzRoundTrip
mkdir -p $WORK/fuzz_round_trip_corpus
cp $SRC/fuzzing/projects/goipp/seeds/fuzz_round_trip_seed_corpus/* $WORK/fuzz_round_trip_corpus/
zip -r $OUT/fuzz_round_trip_seed_corpus.zip fuzz_round_trip_corpus/


# build dependencies and fiuzzers
cd $SRC/goipp
Expand All @@ -24,3 +30,4 @@ go get github.com/AdamKorcz/go-118-fuzz-build/testing

compile_native_go_fuzzer github.com/OpenPrinting/goipp/fuzzer FuzzDecodeBytes fuzz_decode_bytes
compile_native_go_fuzzer github.com/OpenPrinting/goipp/fuzzer FuzzDecodeBytesEx fuzz_decode_bytes_ex
compile_native_go_fuzzer github.com/OpenPrinting/goipp/fuzzer FuzzRoundTrip fuzz_round_trip
Binary file not shown.
Binary file not shown.