forge
Explore
Log in

Don't you dare go Hollow

scripts: document the 1-byte-per-sample depth assumption on oracle dump rungs 1/6/7/15

Browse files at this commit

e6e5fdc604d47ef70dc15c8f895588a9e212866fAhmet Kaan GümüşParent: df78a6b
Comments only -- no emitted byte changes. Each of the four rungs that
fwrite(..., 1, w, f) with no YV12_FLAG_HIGHBITDEPTH check now carries a
DEPTH ASSUMPTION block naming the decoder-side dump it is byte-paired
with (which narrows to u8 on purpose) and rung 12 EC_AV1_FINAL_DUMP as
the depth-correct HBD alternative. The file header and the rung-12
summary point at those blocks so the trap is visible without opening a
rung.

Measured on the shared HBD oracle build with the committed
av112bit-key.obu (160x128 4:2:0 12-bit, 30720 samples): rung 12 writes
61440 B (w*h*bps) while the four 1-byte rungs SIGSEGV inside fwrite
(exit 139) and, where the write survives, would emit 30720 B -- exactly
half, which reads like a truncated decode.
lanes/av1oraclerungdepth.report.mdadded+177 -0
@@ -0,0 +1,177 @@
1+# lane-av1oraclerungdepth — make the oracle dump-rung DEPTH ASSUMPTION explicit
2+
3+Branch: `lane-av1oraclerungdepth`, worktree `/home/user/.cache/wt/av1rungdepth`,
4+base HEAD `aa0ac8c2` (main). **Comments only** — `scripts/instrument-aom-oracle.sh`,
5++63 lines, every added line a `#` comment (verified: `git diff -U0 | grep '^+' |
6+grep -v '^ *#'` is empty). No decoder change, no gate change, no oracle rebuild,
7+no change to the shared `~/.cache/aom-oracle`.
8+
9+## 1. What the four rungs are
10+
11+Verified by reading the emitted C (no re-derivation):
12+
13+| rung | env var | writes | depth check | paired decoder-side dump |
14+|---|---|---|---|---|
15+| 1 PREFILT | `EC_AV1_PREFILT_DUMP` | `fwrite(..., 1, y_crop_width, ...)` per row | **none** | `EC_AV1_PREFILT_DUMP`, `decode.rs:35263-35273` — `p.data.iter().map(\|&s\| s as u8)` |
16+| 6 POSTDEBLOCK | `EC_AV1_POSTDEBLOCK_DUMP` | `fwrite(..., 1, y_width, ...)` per row | **none** | `EC_AV1_POSTDEBLOCK_DUMP`, `decode.rs:35336` (dup `:53126`) |
17+| 7 PREFILT_WIDE | `EC_AV1_PREFILT_WIDE_DUMP` | `fwrite(..., 1, y_width, ...)` per row | **none** | `EC_AV1_PREFILT_WIDE_DUMP`, `decode.rs:19734-19762` (dup `:53048`) |
18+| 15 POSTCDEF | `EC_AV1_POSTCDEF_DUMP` | `fwrite(..., 1, y_width, ...)` per row | **none** | `EC_AV1_POSTCDEF_DUMP`, `decode.rs:35356` (dup `:53148`) |
19+| **12 FINAL** | `EC_AV1_FINAL_DUMP` | `fwrite(..., ec_hbd ? 2 : 1, ...)` | **yes** (`YV12_FLAG_HIGHBITDEPTH`) | `EC_AV1_FINAL_DUMP`, `stream.rs:2129-2155` (u16 LE) |
20+
21+Each of the four is `fwrite(ptr, 1, w, f)` — one byte per sample, no
22+`YV12_FLAG_HIGHBITDEPTH` branch. Rung 12 is the only one that checks. All four
23+stay as-is: the pairing with a u8-narrowing decoder dump is the reason they
24+exist, and changing one side breaks the diff. **Behaviour unchanged.**
25+
26+## 2. What was added
27+
28+A `DEPTH ASSUMPTION` block directly under each of the four rung headers, at
29+the point a reader editing that rung reads first:
30+
31+- `scripts/instrument-aom-oracle.sh:129` (rung 1), `:321` (rung 6), `:385`
32+ (rung 7), `:891` (rung 15)
33+
34+Each block states, in six to ten lines: the assumption (1 B/sample, no
35+`YV12_FLAG_HIGHBITDEPTH` check), why it is deliberate (byte-paired with the
36+named decoder-side dump that narrows to u8, with its file:line), the failure
37+signature on an HBD stream (SIGSEGV / a file exactly half `w*h*bps`, which
38+reads like a truncated decode), and the HBD-correct alternative (rung 12
39+`EC_AV1_FINAL_DUMP`, with its line).
40+
41+Two summary pointers were added so the trap is visible without opening a rung:
42+
43+- `:10-17` — the file header, right under "Rungs provided", before the first
44+ rung entry.
45+- `:703-714` — the rung-12 block that already said "unlike the u8-narrowing
46+ debug dumps", now expanded into the full trap with the measured numbers and
47+ the `stat -c%s` vs `w*h*bps` check to run before blaming a decoder.
48+
49+Final line references in the file (all verified against the committed
50+script): rung 1 block `:131`, rung 6 `:328`, rung 7 `:396`, rung 15 `:905`;
51+rung 1 emitted C `:146`, rung 6 `:352`, rung 7 `:416`, rung 15 `:934`,
52+rung 12 emitted C `:730`.
53+
54+## 3. Item 2 — no assertion added, and why
55+
56+The instruction's escape clause applies: **the script has no natural
57+non-byte-affecting failure point.**
58+
59+- The script is a source patcher. It runs `python3 - "$F" <<'PY...'` sixteen
60+ times, rewriting `~/.cache/aom-oracle/src/av1/decoder/decodeframe.c`. It
61+ never runs `aomdec`, never opens a dump file, never has a frame index.
62+- Its only per-rung "ok" signal is 16 `print("... instrumented")` /
63+ `print("... already instrumented (no-op)")` lines emitted at
64+ *instrumentation* time. They fire before any byte is written.
65+- The script has no depth value. Grepped: no `bit_depth`, no `bps`, no
66+ `ftell`/`fseek`/`stat`/`getsize`, no run-time state at all.
67+
68+A size assertion there would need the stream's `bit_depth`, the frame count and
69+the produced file path — none of which exist in this script. Plumbing them in
70+would mean the script parsing a fixture and re-running the oracle, which is
71+`build-aom-oracle.sh`'s job and is explicitly out of scope (no oracle
72+rebuild). **Comments alone shipped**, per the instruction.
73+
74+The equivalent check a lane runs by hand is now written into the two summary
75+blocks: `stat -c%s <dump>.f0` against `w*h*bps`.
76+
77+## 4. Proof
78+
79+### 4a. Static
80+
81+```
82+$ bash -n scripts/instrument-aom-oracle.sh
83+bash -n OK
84+$ # every <<'PY…' heredoc body compiled in isolation
85+python heredocs compile OK: 16
86+$ git diff -U0 scripts/instrument-aom-oracle.sh | grep -E '^\+[^+]' | grep -vE '^\+ *#'
87+(no output) # every added line is a comment
88+```
89+
90+### 4b. The trap, measured on the shared oracle (read-only use)
91+
92+The shared build is already instrumented (`grep -c EC_INSTRUMENTED
93+decodeframe.c` = 7) and is a high-bitdepth build
94+(`aom_config.h: #define CONFIG_AV1_HIGHBITDEPTH 1`). It was only *run*, never
95+edited or rebuilt. Fixture: the committed
96+`crates/ec-av1/fixtures/av112bit-key.obu`, which the y4m header reports as
97+`W160 H128 C420p12` — 160·128 + 2·(80·64) = **30720 samples**, bps = 2, so
98+`w*h*bps` = **61440 B**.
99+
100+Each env var tested in isolation:
101+
102+| env var | exit | dump written |
103+|---|---|---|
104+| (none) | 0 | — (61496 B y4m) |
105+| `EC_AV1_FINAL_DUMP` (rung 12) | **0** | `fin.f0` = **61440 B** = `w*h*bps` ✅ |
106+| `EC_AV1_PREFILT_DUMP` (rung 1) | **139** | `pf.f0` = 0 B |
107+| `EC_AV1_POSTDEBLOCK_DUMP` (rung 6) | **139** | 0 B |
108+| `EC_AV1_PREFILT_WIDE_DUMP` (rung 7) | **139** | 0 B |
109+| `EC_AV1_POSTCDEF_DUMP` (rung 15) | **139** | 0 B |
110+
111+The 139 is a genuine SIGSEGV inside this rung's own `fwrite`, not a decode
112+refusal — gdb on rung 1:
113+
114+```
115+#3 fwrite ()
116+#4 av1_decode_tg_tiles_and_wrapup (pbi=…, …) <- rung 1's insertion point
117+#5 read_one_tile_group_obu (…)
118+```
119+
120+Same four rungs on the 8-bit fixture `444_lossy_superres_256x128_d12.obu`
121+(`W256 H128 C444`): rung 1 exits **0** and writes `p8.f0` = 65664 B. So the
122+four rungs are fine at 8 bits and broken at 12.
123+
124+**Correction to the charter's premise, kept in the comments:** on this build
125+the four rungs do not reach the "silently half-length" state — they crash
126+first (0-byte file), which reads the same way, worse. Where the 1-byte write
127+*does* stay in bounds the arithmetic is exactly as predicted. Replicated on
128+the real rung-12 output rather than asserted:
129+
130+```
131+$ python3 -c "…unpack fin.f0 as <30720H, take each low byte, write…"
132+rung12 EC_AV1_FINAL_DUMP size = 61440 (160*128 + 2*80*64 = 30720 samples x 2 B)
133+what a 1 B/sample rung emits = 30720 == exactly half: True
134+expected 8-bit rung size (w*h*bps=1) = 30720
135+```
136+
137+Both numbers are now in the comments: the comment at `:136-141` and the two
138+summary blocks name 61440 expected / 30720 actual, so a lane hitting this sees
139+the numbers it will actually measure.
140+
141+### 4c. What could NOT be demonstrated without touching the shared oracle
142+
143+- **The half-length file as an actual artifact.** On this build the four rungs
144+ SIGSEGV before finishing, so a real 30720 B file cannot be produced from the
145+ shared `aomdec`. Producing one would need a rebuild of an instrumented
146+ oracle with a fixed pointer/scale in the rung, which the charter forbids
147+ (no oracle rebuild) and which would also be a behaviour change. The 30720 B
148+ figure is therefore **derived byte arithmetic on a real 30720-sample file**
149+ (`fin.f0`), not a captured half-length dump.
150+- **The root cause of the SIGSEGV** is not diagnosed — only located to the
151+ rung's `fwrite` on the u16 buffer. Fixing it would change emitted bytes and
152+ break the pairing, i.e. out of scope here; it is a separate lane if anyone
153+ wants HBD pre-filter/post-deblock/post-CDEF ladders.
154+- **`bash scripts/instrument-aom-oracle.sh` was not executed end-to-end**, for
155+ the same reason: its first act is rewriting the shared oracle source. The
156+ `bash -n` plus 16/16 heredoc compile is the strongest check available
157+ without it.
158+
159+## 5. Follow-ups this lane did not do (not done on purpose)
160+
161+1. The four rungs could take a `YV12_FLAG_HIGHBITDEPTH` branch like rung 12,
162+ which would make them HBD-usable — but the decoder-side pair narrows to u8
163+ on purpose (`as u8`), so both sides would have to change together, and every
164+ existing byte-pairing gate would need re-pinning. That is a behaviour
165+ change, not a comment.
166+2. A reusable `stat -c%s … vs w*h*bps` check as a real assertion belongs in the
167+ gate that decodes through these rungs, not in the patcher.
168+
169+## 6. Constraint compliance
170+
171+- `scripts/instrument-aom-oracle.sh` only (plus this report).
172+- Comments only — no emitted byte changes (diff verified in §4a).
173+- No decoder change, no gate change.
174+- `~/.cache/aom-oracle` was executed read-only; no rebuild, no source edit.
175+ `git status --porcelain` in the primary checkout is unchanged (verified empty
176+ before and after).
177+- Never pushed.
scripts/instrument-aom-oracle.shmodified+63 -0
@@ -7,6 +7,14 @@
77 # this script reproduce the full ladder from scratch.
88 #
99 # Rungs provided (both env-gated, so an uninstrumented run is unchanged):
10+# DEPTH TRAP (lane-av1oraclerungdepth): the DUMP rungs 1 / 6 / 7 / 15 write
11+# 1 byte per sample with no YV12_FLAG_HIGHBITDEPTH check (they are paired
12+# with decoder-side dumps that narrow to u8 on purpose). On a 10/12-bit
13+# stream they crash the oracle, or where they survive produce a file of
14+# EXACTLY HALF w*h*bps -- which looks like a truncated decode but is the
15+# rung's depth assumption. Each of those four carries a
16+# `DEPTH ASSUMPTION` block naming its decoder-side pair; rung 12
17+# (EC_AV1_FINAL_DUMP) is the depth-correct one.
1018 # EC_AV1_PREFILT_DUMP=<prefix> -> <prefix>.f<N> per frame, Y then U then V,
1119 # crop-sized rows, written after tile decode and BEFORE any loop filter,
1220 # CDEF or LR. Diff against our own EC_AV1_PREFILT_DUMP to separate a
@@ -120,6 +128,19 @@ assert old_sig in s, "read_partition signature moved"
120128 s = s.replace(old_sig, new_sig, 1)
121129
122130 # --- rung 1: pre-filter recon dump --------------------------------------
131+# DEPTH ASSUMPTION (lane-av1oraclerungdepth): this rung writes 1 byte per
132+# sample and has NO YV12_FLAG_HIGHBITDEPTH check. That is deliberate -- it is
133+# byte-paired with our own EC_AV1_PREFILT_DUMP, which narrows 10/12-bit to u8
134+# on purpose (decode.rs:35263-35273, `p.data.iter().map(|&s| s as u8)`).
135+# TRAP: on an HBD stream the file is EXACTLY HALF w*h*2 = w*h bytes, which
136+# reads like a truncated/short decode, not a decoder bug. For HBD use rung 12
137+# EC_AV1_FINAL_DUMP (:730) -- it IS depth-correct (u8 / u16 LE).
138+# OBSERVED 2026-09-29 on the HBD oracle build (CONFIG_AV1_HIGHBITDEPTH=1) with
139+# the committed `av112bit-key.obu` (160x128 4:2:0 12-bit = 30720 samples):
140+# rung 12 wrote 61440 B (w*h*bps) and this rung's 1-byte fwrite SIGSEGVs inside
141+# fwrite (exit 139, 0-byte file); the bytes it would have written are 30720 B
142+# = exactly half. Either way this is the RUNG's depth assumption, not a decoder
143+# defect -- never read a half-length/empty file here as a truncated decode.
123144 anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync,
124145 pbi->num_workers, 1);"""
125146 dump = """ {
@@ -304,6 +325,16 @@ print("intra mode-info instrumented")
304325 PYI
305326
306327 # --- rung 6: post-deblock, pre-superres row dump ------------------------
328+# DEPTH ASSUMPTION (lane-av1oraclerungdepth): 1 byte per sample, NO
329+# YV12_FLAG_HIGHBITDEPTH check. Deliberate -- byte-paired with our
330+# EC_AV1_POSTDEBLOCK_DUMP, which narrows to u8 (decode.rs:35336,
331+# `dump_stage(..., &y, &u, &v)` over the u16 planes; same at :53126).
332+# TRAP: on an HBD stream the file is EXACTLY HALF w*h*2, which reads like a
333+# truncated/short decode, not a decoder bug. For HBD use rung 12
334+# EC_AV1_FINAL_DUMP (:730) -- depth-correct (u8 / u16 LE).
335+# OBSERVED 2026-09-29 (HBD build, av112bit-key.obu): the 1-byte fwrite SIGSEGVs
336+# (exit 139); where it survives it writes 30720 B where 61440 B is expected --
337+# exactly half. That is this rung, not a truncated decode.
307338 python3 - "$F" <<'PYD'
308339 import sys
309340 path = sys.argv[1]
@@ -362,6 +393,16 @@ PYD
362393 # additive env var at the SAME anchor (pre-loop-filter) but dumping the full
363394 # y_width/y_height aligned buffer, so a margin-region reconstruction bug can
364395 # be told apart from a margin-region deblock bug.
396+# DEPTH ASSUMPTION (lane-av1oraclerungdepth): 1 byte per sample, NO
397+# YV12_FLAG_HIGHBITDEPTH check. Deliberate -- byte-paired with our
398+# EC_AV1_PREFILT_WIDE_DUMP, which narrows to u8 (decode.rs:19734-19762,
399+# `dump_prefilter_wide`; same body duplicated at :53048). TRAP: on an HBD
400+# stream the file is EXACTLY HALF w*h*2, which reads like a truncated/short
401+# decode, not a decoder bug. For HBD use rung 12 EC_AV1_FINAL_DUMP (:730) --
402+# depth-correct (u8 / u16 LE).
403+# OBSERVED 2026-09-29 (HBD build, av112bit-key.obu): the 1-byte fwrite SIGSEGVs
404+# (exit 139); where it survives it writes 30720 B where 61440 B is expected --
405+# exactly half. That is this rung, not a truncated decode.
365406 python3 - "$F" <<'PYW'
366407 import sys
367408 path = sys.argv[1]
@@ -659,6 +700,19 @@ PYC11
659700 # y_crop_width), 8-bit as u8 and high bitdepth as u16 LE -- bit-depth
660701 # correct, unlike the u8-narrowing debug dumps.
661702 #
703+# DEPTH TRAP (lane-av1oraclerungdepth) -- READ BEFORE USING ANY DUMP RUNG:
704+# rungs 1 (PREFILT :146), 6 (POSTDEBLOCK :352), 7 (PREFILT_WIDE :416) and
705+# 15 (POSTCDEF :934) write 1 byte per sample with NO YV12_FLAG_HIGHBITDEPTH
706+# check, because each is byte-paired with a decoder-side dump that narrows to
707+# u8 on purpose. On a 10/12-bit stream those four are unusable: measured on the
708+# HBD oracle build with `av112bit-key.obu` (160x128 4:2:0 12-bit, 30720
709+# samples) their 1-byte fwrite SIGSEGVs (exit 139, 0-byte file), and where it
710+# survives it writes 30720 B where w*h*bps = 61440 B is expected -- EXACTLY
711+# HALF, which reads like a truncated decode. Check `stat -c%s` against
712+# w*h*bps before calling either a decoder defect. This rung (12) is the
713+# depth-correct one for HBD. Each of those four rungs carries a
714+# `DEPTH ASSUMPTION` block naming its decoder-side pair and line.
715+#
662716 # Rungs 1/6 (pre-filter / post-deblock) stop before CDEF+LR+superres, and
663717 # every ffmpeg/aomdec pixel gate in this repo compares SHOWN frames only
664718 # (class gate-blind-to-hidden-frames), so before this rung no instrument in
@@ -848,6 +902,15 @@ PYST
848902 # builds (its 8-bit run SEGFAULTS); this rung is the 8-bit one. lane-
849903 # av1422filter added it to the live oracle tree by hand first, then it was
850904 # transcribed here (class: instrument that lives only in a build tree).
905+# DEPTH ASSUMPTION (lane-av1oraclerungdepth): 1 byte per sample, NO
906+# YV12_FLAG_HIGHBITDEPTH check. Deliberate -- byte-paired with our
907+# EC_AV1_POSTCDEF_DUMP, which narrows to u8 (decode.rs:35356; same at
908+# :53148). TRAP: on an HBD stream the file is EXACTLY HALF w*h*2, which reads
909+# like a truncated/short decode, not a decoder bug. For HBD use rung 12
910+# EC_AV1_FINAL_DUMP (:730) -- depth-correct (u8 / u16 LE).
911+# OBSERVED 2026-09-29 (HBD build, av112bit-key.obu): the 1-byte fwrite SIGSEGVs
912+# (exit 139); where it survives it writes 30720 B where 61440 B is expected --
913+# exactly half. That is this rung, not a truncated decode.
851914 python3 - "$F" <<'PYC'
852915 import sys
853916 path = sys.argv[1]