(f *testing.F)
| 14 | ) |
| 15 | |
| 16 | func FuzzDecodeAll(f *testing.F) { |
| 17 | fuzz.AddFromZip(f, "testdata/decode-regression.zip", fuzz.TypeRaw, false) |
| 18 | fuzz.AddFromZip(f, "testdata/fuzz/decode-corpus-raw.zip", fuzz.TypeRaw, testing.Short()) |
| 19 | fuzz.AddFromZip(f, "testdata/fuzz/decode-corpus-encoded.zip", fuzz.TypeGoFuzz, testing.Short()) |
| 20 | |
| 21 | // compareNonAsm cross-checks the assembly decoder against a non-assembly |
| 22 | // path and requires byte-identical output. On amd64 this disables the BMI2 |
| 23 | // assembly, comparing the BMI2 and non-BMI2 routines. On other architectures |
| 24 | // cpuinfo.HasBMI2 is false so the in-process check is skipped; run this |
| 25 | // fuzzer additionally with -tags=noasm over the shared corpus to cover the |
| 26 | // assembly-vs-generic differential there. |
| 27 | const compareNonAsm = true |
| 28 | |
| 29 | f.Fuzz(func(t *testing.T, b []byte) { |
| 30 | // Just test if we crash... |
| 31 | defer func() { |
| 32 | if r := recover(); r != nil { |
| 33 | rdebug.PrintStack() |
| 34 | t.Fatal(r) |
| 35 | } |
| 36 | }() |
| 37 | |
| 38 | decLow, err := NewReader(nil, WithDecoderLowmem(true), WithDecoderConcurrency(2), WithDecoderMaxMemory(20<<20), WithDecoderMaxWindow(1<<20), IgnoreChecksum(true)) |
| 39 | if err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | defer decLow.Close() |
| 43 | decHi, err := NewReader(nil, WithDecoderLowmem(false), WithDecoderConcurrency(2), WithDecoderMaxMemory(20<<20), WithDecoderMaxWindow(1<<20), IgnoreChecksum(true)) |
| 44 | if err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | defer decHi.Close() |
| 48 | b1, err1 := decLow.DecodeAll(b, make([]byte, 0, len(b))) |
| 49 | b2, err2 := decHi.DecodeAll(b, make([]byte, 0, len(b))) |
| 50 | if err1 != err2 { |
| 51 | if (err1 == nil) != (err2 == nil) { |
| 52 | t.Errorf("err low: %v, hi: %v", err1, err2) |
| 53 | } |
| 54 | } |
| 55 | if err1 != nil { |
| 56 | b1, b2 = b1[:0], b2[:0] |
| 57 | } |
| 58 | if !bytes.Equal(b1, b2) { |
| 59 | t.Fatalf("Output mismatch, low: %v, hi: %v", err1, err2) |
| 60 | } |
| 61 | |
| 62 | if compareNonAsm && cpuinfo.HasBMI2() { |
| 63 | // Decode again with the BMI2 assembly disabled and require identical |
| 64 | // output, exercising the assembly against the non-assembly path. |
| 65 | // Defer the restore so BMI2 is re-enabled on every exit path. |
| 66 | defer cpuinfo.DisableBMI2()() |
| 67 | decRef, errRef := NewReader(nil, WithDecoderLowmem(true), WithDecoderConcurrency(1), WithDecoderMaxMemory(20<<20), WithDecoderMaxWindow(1<<20), IgnoreChecksum(true)) |
| 68 | if errRef != nil { |
| 69 | t.Fatal(errRef) |
| 70 | } |
| 71 | defer decRef.Close() |
| 72 | bRef, errRef := decRef.DecodeAll(b, make([]byte, 0, len(b))) |
| 73 | if (err1 == nil) != (errRef == nil) { |
no test coverage detected
searching dependent graphs…