#!/bin/bash # Generate seed corpus from existing protocol tests. # Usage: generate_corpus.sh [path/to/local/seedgen] set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" CORPUS_DIR="${PROJECT_ROOT}/data/fuzz/corpus" echo "Generating seed corpus from protocol tests..." # Create corpus directories mkdir -p \ "${CORPUS_DIR}/ipc_protocol" \ "${CORPUS_DIR}/ipc_roundtrip" \ "${CORPUS_DIR}/p2p_protocol" \ "${CORPUS_DIR}/p2p_delta" \ "${CORPUS_DIR}/add_document" \ "${CORPUS_DIR}/proto_serializer" \ "${CORPUS_DIR}/request_handler" \ "${CORPUS_DIR}/streaming_processor" \ "${CORPUS_DIR}/plugin_trust" \ "${CORPUS_DIR}/plugin_abi_mount" \ "${CORPUS_DIR}/plugin_abi_negotiation" \ "${CORPUS_DIR}/download_jobs" \ "${CORPUS_DIR}/fts5_query" \ "${CORPUS_DIR}/utf8" \ "${CORPUS_DIR}/text_extractors" \ "${CORPUS_DIR}/compressed_block" echo "Creating minimal seed inputs..." # FTS5 query seeds: first byte selects prefix-wildcard handling. printf '\x01dendritic cells (DCs)' >"${CORPUS_DIR}/fts5_query/01_plain.txt" printf '\x01(foo OR bar) NOT baz' >"${CORPUS_DIR}/fts5_query/02_operators.txt" printf '\x00title:report "exact phrase"' >"${CORPUS_DIR}/fts5_query/03_column_phrase.txt" printf '\x01NEAR(hello world, 2) IL-6*' >"${CORPUS_DIR}/fts5_query/04_near_prefix.txt" # UTF-8 / encoding seeds: valid multibyte, surrogate, overlong, UTF-16LE with BOM. printf 'caf\xc3\xa9 \xf0\x9f\x98\x80' >"${CORPUS_DIR}/utf8/01_valid.bin" printf 'a\xed\xa0\x80b\xe0\x80\x80c\xf4\x90\x80\x80' >"${CORPUS_DIR}/utf8/02_invalid.bin" printf '\xff\xfeH\x00i\x00\x00\xd8A\x00' >"${CORPUS_DIR}/utf8/03_utf16le.bin" # Text extractor seeds: HTML with scripts, comments and block tags. printf '
a