| 1 |
package xpress |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
// FuzzXpressPlain runs the fuzzed input through both decompressors and asserts |
| 8 |
// that neither panics and that neither ever produces more than MaxSize |
| 9 |
// bytes of output. The seed corpus is the compressed side of the MS-XCA |
| 10 |
// test vectors. |
| 11 |
func FuzzXpressPlain(f *testing.F) { |
| 12 |
for _, v := range xpressVectors { |
| 13 |
f.Add(v.data) |
| 14 |
} |
| 15 |
f.Fuzz(func(t *testing.T, data []byte) { |
| 16 |
pre := make([]byte, len(data)&(MaxSize-1)) |
| 17 |
out, err := AppendDecompressed(pre, data) |
| 18 |
if len(out)-len(pre) > MaxSize { |
| 19 |
t.Fatalf("plain LZ77: %d bytes of output exceeds MaxSize", len(out)) |
| 20 |
} |
| 21 |
if err != nil && len(out) != len(pre) { |
| 22 |
t.Fatalf("plain LZ77: error, but output modified %d != %d", len(out), len(pre)) |
| 23 |
} |
| 24 |
}) |
| 25 |
} |
| 26 |
|
| 27 |
// FuzzXpressHuffman is for the Huffman variant, which |
| 28 |
// requires the uncompressed size as a separate argument. |
| 29 |
func FuzzXpressHuffman(f *testing.F) { |
| 30 |
for _, v := range xpressVectors { |
| 31 |
f.Add(v.data, len(v.expected)) |
| 32 |
} |
| 33 |
f.Fuzz(func(t *testing.T, data []byte, dsize int) { |
| 34 |
pre := make([]byte, dsize&(MaxSize-1)) |
| 35 |
out, err := AppendHDecompressed(pre, data, dsize) |
| 36 |
if len(out)-len(pre) > MaxSize { |
| 37 |
t.Fatalf("LZ77+Huffman: %d bytes of output exceeds MaxSize", len(out)) |
| 38 |
} |
| 39 |
if err != nil && len(out) != len(pre) { |
| 40 |
t.Fatalf("LZ77+Huff: error, but output modified %d != %d", len(out), len(pre)) |
| 41 |
} |
| 42 |
}) |
| 43 |
} |