(f *testing.F)
| 90 | } |
| 91 | |
| 92 | func FuzzDecoder(f *testing.F) { |
| 93 | fuzz.AddFromZip(f, "testdata/fuzz/decode-corpus-raw.zip", fuzz.TypeRaw, testing.Short()) |
| 94 | fuzz.AddFromZip(f, "testdata/fuzz/decode-corpus-encoded.zip", fuzz.TypeGoFuzz, testing.Short()) |
| 95 | //fuzz.AddFromZip(f, "testdata/fuzz/decode-oss.zip", fuzz.TypeOSSFuzz, false) |
| 96 | |
| 97 | brLow := newBytesReader(nil) |
| 98 | brHi := newBytesReader(nil) |
| 99 | f.Fuzz(func(t *testing.T, b []byte) { |
| 100 | // Just test if we crash... |
| 101 | defer func() { |
| 102 | if r := recover(); r != nil { |
| 103 | rdebug.PrintStack() |
| 104 | t.Fatal(r) |
| 105 | } |
| 106 | }() |
| 107 | brLow.Reset(b) |
| 108 | brHi.Reset(b) |
| 109 | decLow, err := NewReader(brLow, WithDecoderLowmem(true), WithDecoderConcurrency(2), WithDecoderMaxMemory(20<<20), WithDecoderMaxWindow(1<<20), IgnoreChecksum(true), WithDecodeBuffersBelow(8<<10)) |
| 110 | if err != nil { |
| 111 | t.Fatal(err) |
| 112 | } |
| 113 | defer decLow.Close() |
| 114 | |
| 115 | // Test with high memory, but sync decoding |
| 116 | decHi, err := NewReader(brHi, WithDecoderLowmem(false), WithDecoderConcurrency(1), WithDecoderMaxMemory(20<<20), WithDecoderMaxWindow(1<<20), IgnoreChecksum(true), WithDecodeBuffersBelow(8<<10)) |
| 117 | if err != nil { |
| 118 | t.Fatal(err) |
| 119 | } |
| 120 | defer decHi.Close() |
| 121 | |
| 122 | if debugDecoder { |
| 123 | fmt.Println("LOW CONCURRENT") |
| 124 | } |
| 125 | b1, err1 := io.ReadAll(decLow) |
| 126 | |
| 127 | if debugDecoder { |
| 128 | fmt.Println("HI NOT CONCURRENT") |
| 129 | } |
| 130 | b2, err2 := io.ReadAll(decHi) |
| 131 | if err1 != err2 { |
| 132 | if (err1 == nil) != (err2 == nil) { |
| 133 | t.Errorf("err low concurrent: %v, hi: %v", err1, err2) |
| 134 | } |
| 135 | } |
| 136 | if err1 != nil { |
| 137 | b1, b2 = b1[:0], b2[:0] |
| 138 | } |
| 139 | if !bytes.Equal(b1, b2) { |
| 140 | t.Fatalf("Output mismatch, low concurrent: %v, hi: %v", err1, err2) |
| 141 | } |
| 142 | }) |
| 143 | } |
| 144 | |
| 145 | func FuzzNoBMI2Dec(f *testing.F) { |
| 146 | if !cpuinfo.HasBMI2() { |
no test coverage detected
searching dependent graphs…