forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

seed.sh54 lines, 2.3 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# seed.sh: fill fuzz/corpus/<target>/ with DEFLATE and zlib streams.
3#
4# Streams come from python3's zlib at levels 0, 1, 6 and 9, over a few input shapes
5# (text, zeros, random, a repeated block) so stored, fixed and dynamic blocks all appear.
6# inflate_raw and inflate_diff take raw DEFLATE (zlib header and trailer stripped);
7# inflate_zlib takes the full zlib stream; inflate_into gets both with the format byte.
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)
14
15python3 -I - "$FUZZ_DIR/corpus" "$ROOT" <<'PY'
16import os, random, sys, zlib
17
18corpus, root = sys.argv[1], sys.argv[2]
19targets = {t: os.path.join(corpus, t) for t in ("inflate_raw", "inflate_zlib", "inflate_into", "inflate_diff")}
20for d in targets.values():
21 os.makedirs(d, exist_ok=True)
22
23rng = random.Random(0x1f1a7e)
24shapes = {
25 "text": (b"the quick brown fox jumps over the lazy dog\n" * 200),
26 "zeros": bytes(64 * 1024),
27 "random": bytes(rng.getrandbits(8) for _ in range(8192)),
28 "mixed": bytes(rng.choice(b"abcdefgh ") for _ in range(4096)) + b"0123456789" * 300,
29}
30# Real fixture bytes too, when linked: the first few KiB of each file under fixtures/.
31fixtures = os.path.join(root, "fixtures")
32if os.path.isdir(fixtures):
33 for name in sorted(os.listdir(fixtures))[:6]:
34 p = os.path.join(fixtures, name)
35 if os.path.isfile(p):
36 shapes["fx-" + name.replace("/", "_")[:40]] = open(p, "rb").read(8192)
37
38n = 0
39for shape, data in shapes.items():
40 for level in (0, 1, 6, 9):
41 z = zlib.compressobj(level, zlib.DEFLATED, -15)
42 raw = z.compress(data) + z.flush()
43 zl = zlib.compress(data, level)
44 base = f"{shape}-l{level}"
45 for t, payload in (("inflate_raw", raw), ("inflate_diff", b"\x00" + raw),
46 ("inflate_zlib", zl), ("inflate_into", b"\x00" + raw),
47 ("inflate_into", b"\x01" + zl), ("inflate_diff", b"\x01" + zl)):
48 d = targets[t]
49 # Several payloads per target share a name; hash-suffix to keep them apart.
50 name = f"{base}-{len(payload)}-{payload[0]:02x}"
51 open(os.path.join(d, name), "wb").write(payload)
52 n += 1
53print(f"seeded {n} streams under {corpus}")
54PY