diff options
Diffstat (limited to 'projects/go-snappy/fuzz.go')
-rw-r--r-- | projects/go-snappy/fuzz.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/projects/go-snappy/fuzz.go b/projects/go-snappy/fuzz.go new file mode 100644 index 000000000..6722fd02d --- /dev/null +++ b/projects/go-snappy/fuzz.go @@ -0,0 +1,33 @@ +// +build gofuzz + +package snappy + +import ( + "bytes" +) + +func FuzzRoundTrip(data []byte) int { + if len(data) > 1234567 { + return 0 + } + encoded := Encode(nil, data) + decoded, err := Decode(nil, encoded) + if err != nil { + panic("Error decoding snappy-encoded") + } + if !bytes.Equal(data, decoded) { + panic("Different result on roundtrip encode/decode") + } + return 1 +} + +func FuzzDecode(data []byte) int { + if n, _ := DecodedLen(data); n > 1234567 { + return 0 + } + _, err := Decode(nil, data) + if err != nil { + return 0 + } + return 1 +} |