forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

seed.sh53 lines, 2.0 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# seed.sh: fill fuzz/corpus/<target>/ from the repo's still-image fixtures.
3#
4# Every file under fixtures/stills (PNG, JPEG, WebP, GIF, BMP, TIFF) seeds the whole-file targets:
5# decode, decode_with_limits, info, probe, decode_animation. Each format target gets only the files of its
6# own format, so its corpus starts on the right signature. The VP8 frames under fixtures/vp8 are
7# VP8 bitstreams, not stills, and are not used here.
8#
9# Corpus lives under fuzz/corpus, which is git-ignored.
10set -euo pipefail
11
12FUZZ_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
13ROOT=$(cd -- "$FUZZ_DIR/../../.." && pwd)
14STILLS="$ROOT/fixtures/stills"
15[ -d "$STILLS" ] || { echo "seed.sh: $STILLS missing; run scripts/link-fixtures.sh" >&2; exit 2; }
16
17CORPUS="$FUZZ_DIR/corpus"
18mkdir -p "$CORPUS"/{decode,decode_with_limits,info,probe,decode_animation,bmp,gif,jpeg,png,tiff,webp}
19
20python3 -I - "$STILLS" "$CORPUS" <<'PY'
21import glob, os, sys
22
23stills, corpus = sys.argv[1], sys.argv[2]
24by_format = {
25 "png": (".png",), "jpeg": (".jpg", ".jpeg"), "webp": (".webp",),
26 "gif": (".gif",), "bmp": (".bmp",), "tiff": (".tif", ".tiff"),
27}
28all_files = sorted(p for p in glob.glob(os.path.join(stills, "*")) if os.path.isfile(p))
29if not all_files:
30 sys.exit("seed.sh: no still-image fixtures found")
31
32def write(target, name, data):
33 with open(os.path.join(corpus, target, name), "wb") as f:
34 f.write(data)
35
36count = {}
37def bump(t):
38 count[t] = count.get(t, 0) + 1
39
40for path in all_files:
41 name = os.path.basename(path)
42 ext = os.path.splitext(name)[1].lower()
43 data = open(path, "rb").read()
44 for t in ("decode", "decode_with_limits", "info", "probe", "decode_animation"):
45 write(t, name, data)
46 bump(t)
47 for fmt, exts in by_format.items():
48 if ext in exts:
49 write(fmt, name, data)
50 bump(fmt)
51for t in ("decode", "decode_with_limits", "info", "decode_animation", "bmp", "gif", "jpeg", "png", "tiff", "webp"):
52 print(f"{t}: {count.get(t, 0)} seeds")
53PY