MCPcopy
hub / github.com/tinylib/msgp / addFuzzDataFromZip

Function addFuzzDataFromZip

msgp/fuzz_test.go:229–270  ·  view source on GitHub ↗

addFuzzDataFromZip will read the supplied zip and add all as corpus for f. Byte slices only.

(f *testing.F, filename string)

Source from the content-addressed store, hash-verified

227// addFuzzDataFromZip will read the supplied zip and add all as corpus for f.
228// Byte slices only.
229func addFuzzDataFromZip(f *testing.F, filename string) {
230 file, err := os.Open(filename)
231 if err != nil {
232 f.Fatal(err)
233 }
234 fi, err := file.Stat()
235 if fi == nil {
236 return
237 }
238
239 if err != nil {
240 f.Fatal(err)
241 }
242 zr, err := zip.NewReader(file, fi.Size())
243 if err != nil {
244 f.Fatal(err)
245 }
246 for _, file := range zr.File {
247 rc, err := file.Open()
248 if err != nil {
249 f.Fatal(err)
250 }
251
252 b, err := io.ReadAll(rc)
253 if err != nil {
254 f.Fatal(err)
255 }
256 rc.Close()
257
258 if !bytes.HasPrefix(b, []byte("go test fuzz")) {
259 continue
260 }
261
262 vals, err := unmarshalCorpusFile(b)
263 if err != nil {
264 f.Fatal(err)
265 }
266 for _, v := range vals {
267 f.Add(v)
268 }
269 }
270}
271
272// unmarshalCorpusFile decodes corpus bytes into their respective values.
273func unmarshalCorpusFile(b []byte) ([][]byte, error) {

Callers 2

FuzzReaderFunction · 0.85
FuzzReadBytesFunction · 0.85

Calls 2

unmarshalCorpusFileFunction · 0.85
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…