addFuzzDataFromZip will read the supplied zip and add all as corpus for f. Byte slices only.
(f *testing.F, filename string)
| 227 | // addFuzzDataFromZip will read the supplied zip and add all as corpus for f. |
| 228 | // Byte slices only. |
| 229 | func 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. |
| 273 | func unmarshalCorpusFile(b []byte) ([][]byte, error) { |
no test coverage detected
searching dependent graphs…