This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit 254964058bdfdb4e5add269f279e2a275061a5dd
Author: Boris Faure <[email protected]>
AuthorDate: Tue Nov 3 21:44:04 2026 +0000

    tests/fuzz: add seed generator, dictionary and triage script
    
    make-seeds.sh turns the escape-codes tests into seeds, with a header
    asking for plain 4096-byte reads, and adds unterminated OSC, DCS, APC
    and CSI seeds repeated into megabytes. terminal.dict lists the
    introducers, parameters and finals worth reaching. triage.sh replays
    crashes and hangs through the ASAN build, drops what does not
    reproduce or only grows linearly with the input, buckets the rest by
    stack and minimises one input per bucket.
---
 tests/fuzz/make-seeds.sh |  60 +++++++++++++++++++
 tests/fuzz/terminal.dict | 150 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/fuzz/triage.sh     |  93 +++++++++++++++++++++++++++++
 3 files changed, 303 insertions(+)

diff --git a/tests/fuzz/make-seeds.sh b/tests/fuzz/make-seeds.sh
new file mode 100755
index 00000000..d1ef068b
--- /dev/null
+++ b/tests/fuzz/make-seeds.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+# Generate the raw seeds for the escape sequence parser campaign.
+#
+#   make-seeds.sh [raw-dir] [tyfuzz]
+#   afl-cmin -i "$raw-dir" -o seeds -- "$tyfuzz" @@
+#
+# One seed per tests/*.sh replay, prefixed with the fuzzers' 3-byte test
+# case header: byte 0x07 is 4096-byte reads, bytes 0x00 0x00 mean no
+# repeat, so a seed is then exactly what the test fed. The buffering seeds
+# below are hand-made on top: unterminated OSC, DCS, APC and CSI with the
+# repeat exponent (byte 1) raised so that a few bytes expand into a
+# megabyte, the span (byte 2) starting before and after the introducer.
+
+set -eu
+
+here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
+tests_dir=$(dirname "$here")
+raw=${1:-"$here/seeds-raw"}
+tyfuzz=${2:-"$tests_dir/../build-afl/src/bin/tyfuzz"}
+
+mkdir -p "$raw"
+
+for script in "$tests_dir"/*.sh; do
+    name=$(basename "$script")
+    out="$raw/$name"
+    printf '\x07\x00\x00' > "$out"
+    sh "$script" >> "$out" 2>/dev/null || true
+    # afl-fuzz works best on small inputs, and afl-cmin keeps the replay
+    # cost of the corpus down: drop what is already over 64 KB, a later
+    # campaign instance covers what the tail of a benchmark corpus would.
+    if [ "$(wc -c < "$out")" -gt 65536 ]; then
+        rm "$out"
+        echo "dropping $name: over 64 KB" >&2
+    fi
+done
+
+# Unterminated introducers, so the sequences sit in ty->buf until the
+# parser gives up on them. Byte 1 is the exponent written raw: 2^(k mod 21)
+# repetitions of the span, capped at 4 MiB by the harness. Byte 0x00 puts
+# the span at the introducer; 0x02, right after it.
+for k in 10 12 14 16 18 20; do
+    oct=$(printf '%03o' "$k")
+    i=0
+    for seq in '\x1b]0;' '\x1bP0;1|' '\x1b_AAAA' '\x1b[38;2;'; do
+        i=$((i + 1))
+        for b2 in 0x00 0x02; do
+            raw2=$(printf '%s' "$b2" | sed 's/^0x//')
+            {
+                printf '\x07'
+                printf "\\$oct"
+                printf "\\x$raw2"
+                printf '%b' "$seq"
+                printf 'AAAAAAAA'
+            } > "$raw/buffering-k$k-$i-$raw2"
+        done
+    done
+done
+
+echo "$raw:" >&2
+echo "  afl-cmin -i '$raw' -o '${raw%seeds-raw}seeds' -- '$tyfuzz' @@" >&2
diff --git a/tests/fuzz/terminal.dict b/tests/fuzz/terminal.dict
new file mode 100644
index 00000000..ea0eab27
--- /dev/null
+++ b/tests/fuzz/terminal.dict
@@ -0,0 +1,150 @@
+# AFL++ dictionary for the escape sequence parser campaign.
+#
+# Not exhaustive: CmpLog finds the rest. Entries are grouped by what they
+# reach, from the introducers down. See DEV.md for the campaign.
+
+# introducers (C1 and their 8-bit equivalents)
+"\x1b["
+"\x1b]"
+"\x1bP"
+"\x1b_"
+"\x1b^"
+"\x1bX"
+"\x1b}"
+"\x9b"
+"\x9d"
+"\x90"
+
+# terminators of the string sequences
+"\x07"
+"\x1b\\"
+"\x9c"
+
+# CSI prefixes (private modes) and intermediates
+"?"
+">"
+"<"
+"="
+"$"
+" "
+"!"
+"\""
+"'"
+"*"
+"+"
+"#"
+"%"
+
+# CSI finals worth reaching
+"m"
+"h"
+"l"
+"r"
+"s"
+"t"
+"p"
+"$p"
+"$r"
+"q"
+"u"
+"c"
+"n"
+"@"
+"A"
+"B"
+"C"
+"D"
+"G"
+"J"
+"K"
+"L"
+"M"
+"P"
+"S"
+"T"
+"X"
+"d"
+"e"
+"g"
+
+# OSC numbers in use
+"0;"
+"2;"
+"4;"
+"7;"
+"8;"
+"9;"
+"9;4;"
+"10;"
+"11;"
+"12;"
+"17;"
+"19;"
+"52;"
+"104;"
+"110;"
+"111;"
+"112;"
+"777;"
+"1337;"
+
+# Terminology's block escapes (tysend/tycat) and their sub-commands
+"\x1b}bn"
+"\x1b}bs"
+"\x1b}be"
+"\x1b}bi"
+"\x1b}br"
+"\x1b}bc"
+"\x1b}bl"
+"\x1b}by"
+"\x1b}ba"
+
+# DECSET modes worth reaching
+"?1049"
+"?2004"
+"?2026"
+"?1006"
+"?1002"
+"?1003"
+"?1005"
+"?1007"
+"?1034"
+"?1036"
+"?1039"
+"?25"
+"?7"
+"?12"
+"?47"
+"?5"
+"?4"
+"?9"
+"?1"
+"?6"
+"?1000"
+"?7727"
+"?8452"
+
+# long and edge numbers
+"65535"
+"65536"
+"2147483647"
+"2147483648"
+"4294967295"
+"4294967296"
+"-1"
+";;;;;;;;"
+";0"
+";1"
+
+# colours
+"#"
+"#fff"
+"#ffffff"
+"#ffffffff"
+"rgb:"
+"rgba:"
+"hsl("
+"hsla("
+"color:"
+"red"
+"transparent"
diff --git a/tests/fuzz/triage.sh b/tests/fuzz/triage.sh
new file mode 100755
index 00000000..5afd431e
--- /dev/null
+++ b/tests/fuzz/triage.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+# Triage what a tyfuzz campaign saved, into fix commits.
+#
+#   triage.sh <findings dir> <one-shot ASAN tyfuzz> [work dir]
+#
+# The findings dir is afl-fuzz's -o, holding a crashes/ and a hangs/ per
+# instance, and the ASAN binary is the one-shot build of src/bin/tyfuzz
+# (build-afl-asan). One-shot, not persistent: a crash that only reproduces
+# while sharing state with previous inputs is not one we can fix, and the
+# campaign runs with AFL_PERSISTENT_RECORD=100 so those inputs are saved
+# alongside it.
+#
+# For every input:
+# 1. replay it through the one-shot ASAN build;
+# 2. a crash that does not reproduce is dropped;
+# 3. a hang is replayed twice more, at repeat exponent k (byte 1) and k+1:
+#    a replay whose time more than doubles is a quadratic re-parse and goes
+#    to the fix list, one whose time merely grows with the input is a big
+#    but legitimate 4 MiB stream, not a bug;
+# 4. what reproduces is bucketed by the top of the ASAN stack, and the
+#    first input of each bucket is minimized with afl-tmin.
+#
+# The buckets and minimized inputs land in the work dir. The fix commit for
+# each bucket is a hand-written tests/<name>.sh reproducer, never the crash
+# file itself.
+
+set -eu
+
+findings=${1:?usage: triage.sh <findings dir> <one-shot ASAN tyfuzz> [work dir]}
+asan=${2:?usage: triage.sh <findings dir> <one-shot ASAN tyfuzz> [work dir]}
+work=${3:-triage}
+
+mkdir -p "$work"
+: > "$work/buckets.txt"
+: > "$work/hang-times.txt"
+
+# $1: the input file; the replay appends its log under $work, and what is
+# echoed is the wall clock time of the replay, in whole seconds.
+replay_time()
+{
+    t0=$(date +%s)
+    timeout -s ABRT 60 "$asan" "$1" > "$work/replay.log" 2>&1 || true
+    t1=$(date +%s)
+    echo $((t1 - t0))
+}
+
+# $1: the input file, $2: the exponent to write over byte 1
+copy_with_exp()
+{
+    cp "$1" "$work/replay-input"
+    printf "\\$(printf '%03o' "$2")" \
+        | dd of="$work/replay-input" bs=1 seek=1 count=1 conv=notrunc \
+        2>/dev/null
+}
+
+for f in "$findings"/*/crashes/id:* "$findings"/*/hangs/id:*; do
+    [ -f "$f" ] || continue
+    kind=$(basename "$(dirname "$f")")
+    name="$kind/$(basename "$f")"
+
+    k=$(od -An -tu1 -j1 -N1 "$f" | tr -d ' ')
+
+    if [ "$kind" = hangs ]; then
+        copy_with_exp "$f" "$k"
+        t_k=$(replay_time "$work/replay-input")
+        copy_with_exp "$f" $(( (k + 1) % 256 ))
+        t_k1=$(replay_time "$work/replay-input")
+        printf '%s k=%ds k+1=%ds\n' "$name" "$t_k" "$t_k1" \
+            >> "$work/hang-times.txt"
+        # second resolution: 1 -> 2 is noise, 4 -> 20 is a re-parse
+        if [ "$t_k1" -le $(( 2 * (t_k + 1) )) ]; then
+            continue
+        fi
+    elif replay "$f" > /dev/null 2>&1; then
+        echo "$name: does not reproduce, dropped" >&2
+        continue
+    fi
+
+    # bucket by the top of the ASAN stack
+    bucket=$(head -100 "$work/replay.log" |
+        grep -A3 'ERROR: AddressSanitizer' |
+        tail -3 | cksum | cut -d' ' -f1)
+    echo "$bucket $f" >> "$work/buckets.txt"
+    if [ "$(grep -c "^$bucket " "$work/buckets.txt")" -eq 1 ]; then
+        afl-tmin -i "$f" -o "$work/min-$bucket" \
+            -- "$asan" "@@" > /dev/null 2>&1 || true
+    fi
+done
+
+echo "buckets (one minimized input each):" >&2
+sort "$work/buckets.txt" |
+    awk '{ if ($1 != last) print "  " $2; last = $1 }' >&2
+echo "hang replay times: $work/hang-times.txt" >&2

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to