• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// +build gofuzz
2
3package snappy
4
5import (
6	"bytes"
7)
8
9func FuzzRoundTrip(data []byte) int {
10	if len(data) > 1234567 {
11		return 0
12	}
13	encoded := Encode(nil, data)
14	decoded, err := Decode(nil, encoded)
15	if err != nil {
16		panic("Error decoding snappy-encoded")
17	}
18	if !bytes.Equal(data, decoded) {
19		panic("Different result on roundtrip encode/decode")
20	}
21	return 1
22}
23
24func FuzzDecode(data []byte) int {
25	if n, _ := DecodedLen(data); n > 1234567 {
26		return 0
27	}
28	_, err := Decode(nil, data)
29	if err != nil {
30		return 0
31	}
32	return 1
33}
34