| 1 |
package fse |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"fmt" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/klauspost/compress/internal/fuzz" |
| 9 |
) |
| 10 |
|
| 11 |
func FuzzCompress(f *testing.F) { |
| 12 |
fuzz.AddFromZip(f, "testdata/fse_compress.zip", fuzz.TypeGoFuzz, false) |
| 13 |
f.Fuzz(func(t *testing.T, buf0 []byte) { |
| 14 |
var s, s2 Scratch |
| 15 |
b, err := Compress(buf0, &s) |
| 16 |
if err != nil || b == nil { |
| 17 |
return |
| 18 |
} |
| 19 |
err = s.validateNorm() |
| 20 |
if err != nil { |
| 21 |
return |
| 22 |
} |
| 23 |
//Decompress |
| 24 |
got, err := Decompress(b, &s2) |
| 25 |
if err != nil || len(got) == 0 { |
| 26 |
return |
| 27 |
} |
| 28 |
if !bytes.Equal(buf0, got) { |
| 29 |
t.Fatal(fmt.Sprintln("FuzzCompress output mismatch\n", len(got), "org: \n", len(buf0))) |
| 30 |
} |
| 31 |
}) |
| 32 |
} |
| 33 |
|
| 34 |
func FuzzDecompress(f *testing.F) { |
| 35 |
// Input is mixed, but TypeGoFuzz will fall back to raw input. |
| 36 |
fuzz.AddFromZip(f, "testdata/fse_decompress.zip", fuzz.TypeGoFuzz, false) |
| 37 |
f.Fuzz(func(t *testing.T, buf0 []byte) { |
| 38 |
var s2 Scratch |
| 39 |
s2.DecompressLimit = 128 << 10 |
| 40 |
//Decompress |
| 41 |
got, err := Decompress(buf0, &s2) |
| 42 |
if err != nil || len(got) == 0 { |
| 43 |
return |
| 44 |
} |
| 45 |
}) |
| 46 |
} |