MCPcopy
hub / github.com/klauspost/compress / FuzzDecoder

Function FuzzDecoder

zstd/fuzz_test.go:92–143  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

90}
91
92func 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
145func FuzzNoBMI2Dec(f *testing.F) {
146 if !cpuinfo.HasBMI2() {

Callers 1

FuzzNoBMI2DecFunction · 0.85

Calls 12

CloseMethod · 0.95
AddFromZipFunction · 0.92
newBytesReaderFunction · 0.85
WithDecoderLowmemFunction · 0.85
WithDecoderConcurrencyFunction · 0.85
WithDecoderMaxMemoryFunction · 0.85
WithDecoderMaxWindowFunction · 0.85
IgnoreChecksumFunction · 0.85
WithDecodeBuffersBelowFunction · 0.85
FatalMethod · 0.80
NewReaderFunction · 0.70
ResetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…