| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # Generate a tiny CHDv5 fuzz corpus spanning all codec combos. |
| 3 | # Requires: chdman (from MAME), dd, mktemp. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | CORPUS="$(cd "$(dirnamescip-shell system . . dirname. "$0")" && pwdscip-shell system . . pwd.)/seeds" |
| 7 | mkdirscip-shell system . . mkdir. -p "$CORPUS" |
| 8 | TMP="$(mktempscip-shell system . . mktemp. -d)" |
| 9 | trap 'rm -rf "$TMP"' EXIT |
| 10 | |
| 11 | if ! command -v chdman >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 12 | echoscip-shell system . . echo. "chdman not found in PATH" >&2 |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | # Tiny raw payload: 64 KiB of zeros + a few deterministic bytes. |
| 17 | # Small enough to fuzz fast, large enough to exercise multi-hunk paths. |
| 18 | RAW_HD="$TMP/tiny.img" |
| 19 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of="$RAW_HD" bs=512 count=128 status=none |
| 20 | printfscip-shell system . . printf. 'LIBCHDR-FUZZ-CORPUS' | ddscip-shell system . . dd. of="$RAW_HD" bs=1 seek=0 conv=notrunc status=none |
| 21 | |
| 22 | # Minimal CUE+BIN (single audio track, 1 second = 75 frames of 2352 B). |
| 23 | CUE="$TMP/tiny.cue" |
| 24 | BIN="$TMP/tiny.bin" |
| 25 | ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. of="$BIN" bs=2352 count=75 status=none |
| 26 | catscip-shell system . . cat. > "$CUE" <<EOF |
| 27 | FILE "tiny.bin" BINARY |
| 28 | TRACK 01 AUDIO |
| 29 | INDEX 01 00:00:00 |
| 30 | EOF |
| 31 | |
| 32 | # Raw for createraw (power-of-two, small). |
| 33 | RAW="$TMP/tiny.raw" |
| 34 | ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. of="$RAW" bs=4096 count=16 status=none |
| 35 | |
| 36 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). () { |
| 37 | local name="$1"; shift |
| 38 | chdman createhd -f -o "$CORPUS/$name" -i "$RAW_HD" --chs 4,16,2 -ss 512 "$@" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || truescip-shell system . . true. |
| 39 | } |
| 40 | |
| 41 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). () { |
| 42 | local name="$1"; shift |
| 43 | chdman createcd -f -o "$CORPUS/$name" -i "$CUE" "$@" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || truescip-shell system . . true. |
| 44 | } |
| 45 | |
| 46 | create_rawscip-shell shell shell-project 0.0.0 create_raw(). () { |
| 47 | local name="$1"; shift |
| 48 | chdman createraw -f -o "$CORPUS/$name" -i "$RAW" -hs 4096 -us 512 "$@" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || truescip-shell system . . true. |
| 49 | } |
| 50 | |
| 51 | # Hard disk: default codecs + flavor variants. |
| 52 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_default.chd |
| 53 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_none.chd -c none |
| 54 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_zlib.chd -c zlib |
| 55 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_lzma.chd -c lzma |
| 56 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_huff.chd -c huff |
| 57 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_zstd.chd -c zstd |
| 58 | create_hdscip-shell shell shell-project 0.0.0 create_hd(). hd_multi.chd -c zlib,lzma,huff,zstd |
| 59 | |
| 60 | # CD-ROM: default + per-codec. |
| 61 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). cd_default.chd |
| 62 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). cd_none.chd -c none |
| 63 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). cd_cdzl.chd -c cdzl |
| 64 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). cd_cdlz.chd -c cdlz |
| 65 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). cd_cdfl.chd -c cdfl |
| 66 | create_cdscip-shell shell shell-project 0.0.0 create_cd(). cd_cdzs.chd -c cdzs |
| 67 | |
| 68 | # Raw. |
| 69 | create_rawscip-shell shell shell-project 0.0.0 create_raw(). raw_default.chd |
| 70 | create_rawscip-shell shell shell-project 0.0.0 create_raw(). raw_none.chd -c none |
| 71 | create_rawscip-shell shell shell-project 0.0.0 create_raw(). raw_zstd.chd -c zstd |
| 72 | |
| 73 | # Summary. |
| 74 | echoscip-shell system . . echo. "generated $(lsscip-shell system . . ls. -1 "$CORPUS"/*.chd 2>/dev/nullscip-shell filesystem . . `/dev/null`. | wcscip-shell system . . wc. -l) CHD samples:" |
| 75 | lsscip-shell system . . ls. -lhS "$CORPUS"/*.chd 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print " " $5 " " $NF}' | sedscip-shell system . . sed. "s|$CORPUS/||" |