bench/znippy-unpack/make-corpus.sh
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Heimdall is a defensive sandbox. Make the znippy-unpack probe corpus from real data on oden.
# The znippy binary: znippy 0.10.0 (26ede82), built in heim-m0 (glibc), at bin/znippy.
set -eu
D=$(cd "$(dirname "$0")" && pwd); Z=$D/bin/znippy; C=$D/profiles/znippy-unpack/corpus
mkdir -p "$C"; cd "$C"
"$Z" compress -i "$HOME/d-heim-prof/corpus/scan" -o small.znippy --format generic
"$Z" compress -i "$HOME/.cargo/registry/cache/index.crates.io-1949cf8c6b5b557f" -o crates.znippy --format rust
"$Z" compress -i "$HOME/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f" -o sources.znippy --format generic
cp small.znippy corrupt.znippy
n=$(stat -c %s small.znippy)
python3 -I -c '
import sys
n = int(sys.argv[1]); f = open("corrupt.znippy", "r+b")
for off in range(n // 3, n // 3 + 4096, 97):
f.seek(off); b = f.read(1); f.seek(off); f.write(bytes([b[0] ^ 0xFF]))
' "$n"
head -c $((n * 6 / 10)) small.znippy > truncated.znippy
sha256sum *.znippy > SHA256SUMS