forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

seed.sh56 lines, 2.1 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# seed.sh: rebuild fuzz/corpus/ from the crate's test fixtures.
3#
4# Frames are cut out of each IVF file (the first 10 frames, frames over 256 KiB skipped)
5# into corpus/decode_frame/. Whole IVF files up to 256 KiB go into corpus/decode_stream/, and
6# a 10-frame prefix of every larger file too. The corpus is generated, not committed.
7#
8# Usage: crates/ec-vp9/fuzz/seed.sh (from any directory; needs python3 and the fixtures/ link)
9set -euo pipefail
10here=$(cd -- "$(dirname -- "$0")" && pwd)
11repo=$(cd -- "$here/../../.." && pwd)
12rm -rf "$here/corpus"
13mkdir -p "$here/corpus/decode_frame" "$here/corpus/decode_stream"
14exec python3 -I - "$here" "decode_stream" "$repo/fixtures/vp9/*.ivf" "$here/../tests/data/*.ivf" <<'PY'
15import glob, os, struct, sys
16
17here, stream_target = sys.argv[1], sys.argv[2]
18sources = sorted(sum((glob.glob(p) for p in sys.argv[3:]), []))
19MAX_FRAMES, MAX_BYTES = 10, 256 * 1024
20
21def split_ivf(data):
22 hdr_len = struct.unpack_from('<H', data, 6)[0] or 32
23 frames, pos = [], hdr_len
24 while pos + 12 <= len(data):
25 size = struct.unpack_from('<I', data, pos)[0]
26 pos += 12
27 if pos + size > len(data):
28 break
29 frames.append(data[pos:pos + size])
30 pos += size
31 return data[:hdr_len], frames
32
33def ivf(header, frames):
34 out = bytearray(header)
35 for i, f in enumerate(frames):
36 out += struct.pack('<IQ', len(f), i) + f
37 return bytes(out)
38
39nframes = 0
40for path in sources:
41 name = os.path.splitext(os.path.basename(path))[0]
42 data = open(path, 'rb').read()
43 header, frames = split_ivf(data)
44 kept = [f for f in frames[:MAX_FRAMES] if len(f) <= MAX_BYTES]
45 for i, f in enumerate(kept):
46 with open(os.path.join(here, 'corpus', 'decode_frame', f'{name}-{i:02}.bin'), 'wb') as out:
47 out.write(f)
48 nframes += 1
49 if len(data) <= MAX_BYTES:
50 blob, dest = data, f'{name}.ivf'
51 else:
52 blob, dest = ivf(header, kept), f'{name}-prefix.ivf'
53 with open(os.path.join(here, 'corpus', stream_target, dest), 'wb') as out:
54 out.write(blob)
55print(f'seeded {nframes} frames and {len(sources)} IVF files from {len(sources)} sources')
56PY