From e6e5fdc604d47ef70dc15c8f895588a9e212866f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 29 Sep 2026 04:55:29 +0300 Subject: [PATCH] scripts: document the 1-byte-per-sample depth assumption on oracle dump rungs 1/6/7/15 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.md | 177 +++++++++++++++++++++++++++++ scripts/instrument-aom-oracle.sh | 63 ++++++++++ 2 files changed, 240 insertions(+) create mode 100644 lanes/av1oraclerungdepth.report.md diff --git a/lanes/av1oraclerungdepth.report.md b/lanes/av1oraclerungdepth.report.md new file mode 100644 index 00000000..48989eea --- /dev/null +++ b/lanes/av1oraclerungdepth.report.md @@ -0,0 +1,177 @@ +# lane-av1oraclerungdepth — make the oracle dump-rung DEPTH ASSUMPTION explicit + +Branch: `lane-av1oraclerungdepth`, worktree `/home/user/.cache/wt/av1rungdepth`, +base HEAD `aa0ac8c2` (main). **Comments only** — `scripts/instrument-aom-oracle.sh`, ++63 lines, every added line a `#` comment (verified: `git diff -U0 | grep '^+' | +grep -v '^ *#'` is empty). No decoder change, no gate change, no oracle rebuild, +no change to the shared `~/.cache/aom-oracle`. + +## 1. What the four rungs are + +Verified by reading the emitted C (no re-derivation): + +| rung | env var | writes | depth check | paired decoder-side dump | +|---|---|---|---|---| +| 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)` | +| 6 POSTDEBLOCK | `EC_AV1_POSTDEBLOCK_DUMP` | `fwrite(..., 1, y_width, ...)` per row | **none** | `EC_AV1_POSTDEBLOCK_DUMP`, `decode.rs:35336` (dup `:53126`) | +| 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`) | +| 15 POSTCDEF | `EC_AV1_POSTCDEF_DUMP` | `fwrite(..., 1, y_width, ...)` per row | **none** | `EC_AV1_POSTCDEF_DUMP`, `decode.rs:35356` (dup `:53148`) | +| **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) | + +Each of the four is `fwrite(ptr, 1, w, f)` — one byte per sample, no +`YV12_FLAG_HIGHBITDEPTH` branch. Rung 12 is the only one that checks. All four +stay as-is: the pairing with a u8-narrowing decoder dump is the reason they +exist, and changing one side breaks the diff. **Behaviour unchanged.** + +## 2. What was added + +A `DEPTH ASSUMPTION` block directly under each of the four rung headers, at +the point a reader editing that rung reads first: + +- `scripts/instrument-aom-oracle.sh:129` (rung 1), `:321` (rung 6), `:385` + (rung 7), `:891` (rung 15) + +Each block states, in six to ten lines: the assumption (1 B/sample, no +`YV12_FLAG_HIGHBITDEPTH` check), why it is deliberate (byte-paired with the +named decoder-side dump that narrows to u8, with its file:line), the failure +signature on an HBD stream (SIGSEGV / a file exactly half `w*h*bps`, which +reads like a truncated decode), and the HBD-correct alternative (rung 12 +`EC_AV1_FINAL_DUMP`, with its line). + +Two summary pointers were added so the trap is visible without opening a rung: + +- `:10-17` — the file header, right under "Rungs provided", before the first + rung entry. +- `:703-714` — the rung-12 block that already said "unlike the u8-narrowing + debug dumps", now expanded into the full trap with the measured numbers and + the `stat -c%s` vs `w*h*bps` check to run before blaming a decoder. + +Final line references in the file (all verified against the committed +script): rung 1 block `:131`, rung 6 `:328`, rung 7 `:396`, rung 15 `:905`; +rung 1 emitted C `:146`, rung 6 `:352`, rung 7 `:416`, rung 15 `:934`, +rung 12 emitted C `:730`. + +## 3. Item 2 — no assertion added, and why + +The instruction's escape clause applies: **the script has no natural +non-byte-affecting failure point.** + +- The script is a source patcher. It runs `python3 - "$F" <<'PY...'` sixteen + times, rewriting `~/.cache/aom-oracle/src/av1/decoder/decodeframe.c`. It + never runs `aomdec`, never opens a dump file, never has a frame index. +- Its only per-rung "ok" signal is 16 `print("... instrumented")` / + `print("... already instrumented (no-op)")` lines emitted at + *instrumentation* time. They fire before any byte is written. +- The script has no depth value. Grepped: no `bit_depth`, no `bps`, no + `ftell`/`fseek`/`stat`/`getsize`, no run-time state at all. + +A size assertion there would need the stream's `bit_depth`, the frame count and +the produced file path — none of which exist in this script. Plumbing them in +would mean the script parsing a fixture and re-running the oracle, which is +`build-aom-oracle.sh`'s job and is explicitly out of scope (no oracle +rebuild). **Comments alone shipped**, per the instruction. + +The equivalent check a lane runs by hand is now written into the two summary +blocks: `stat -c%s .f0` against `w*h*bps`. + +## 4. Proof + +### 4a. Static + +``` +$ bash -n scripts/instrument-aom-oracle.sh +bash -n OK +$ # every <<'PY…' heredoc body compiled in isolation +python heredocs compile OK: 16 +$ git diff -U0 scripts/instrument-aom-oracle.sh | grep -E '^\+[^+]' | grep -vE '^\+ *#' +(no output) # every added line is a comment +``` + +### 4b. The trap, measured on the shared oracle (read-only use) + +The shared build is already instrumented (`grep -c EC_INSTRUMENTED +decodeframe.c` = 7) and is a high-bitdepth build +(`aom_config.h: #define CONFIG_AV1_HIGHBITDEPTH 1`). It was only *run*, never +edited or rebuilt. Fixture: the committed +`crates/ec-av1/fixtures/av112bit-key.obu`, which the y4m header reports as +`W160 H128 C420p12` — 160·128 + 2·(80·64) = **30720 samples**, bps = 2, so +`w*h*bps` = **61440 B**. + +Each env var tested in isolation: + +| env var | exit | dump written | +|---|---|---| +| (none) | 0 | — (61496 B y4m) | +| `EC_AV1_FINAL_DUMP` (rung 12) | **0** | `fin.f0` = **61440 B** = `w*h*bps` ✅ | +| `EC_AV1_PREFILT_DUMP` (rung 1) | **139** | `pf.f0` = 0 B | +| `EC_AV1_POSTDEBLOCK_DUMP` (rung 6) | **139** | 0 B | +| `EC_AV1_PREFILT_WIDE_DUMP` (rung 7) | **139** | 0 B | +| `EC_AV1_POSTCDEF_DUMP` (rung 15) | **139** | 0 B | + +The 139 is a genuine SIGSEGV inside this rung's own `fwrite`, not a decode +refusal — gdb on rung 1: + +``` +#3 fwrite () +#4 av1_decode_tg_tiles_and_wrapup (pbi=…, …) <- rung 1's insertion point +#5 read_one_tile_group_obu (…) +``` + +Same four rungs on the 8-bit fixture `444_lossy_superres_256x128_d12.obu` +(`W256 H128 C444`): rung 1 exits **0** and writes `p8.f0` = 65664 B. So the +four rungs are fine at 8 bits and broken at 12. + +**Correction to the charter's premise, kept in the comments:** on this build +the four rungs do not reach the "silently half-length" state — they crash +first (0-byte file), which reads the same way, worse. Where the 1-byte write +*does* stay in bounds the arithmetic is exactly as predicted. Replicated on +the real rung-12 output rather than asserted: + +``` +$ python3 -c "…unpack fin.f0 as <30720H, take each low byte, write…" +rung12 EC_AV1_FINAL_DUMP size = 61440 (160*128 + 2*80*64 = 30720 samples x 2 B) +what a 1 B/sample rung emits = 30720 == exactly half: True +expected 8-bit rung size (w*h*bps=1) = 30720 +``` + +Both numbers are now in the comments: the comment at `:136-141` and the two +summary blocks name 61440 expected / 30720 actual, so a lane hitting this sees +the numbers it will actually measure. + +### 4c. What could NOT be demonstrated without touching the shared oracle + +- **The half-length file as an actual artifact.** On this build the four rungs + SIGSEGV before finishing, so a real 30720 B file cannot be produced from the + shared `aomdec`. Producing one would need a rebuild of an instrumented + oracle with a fixed pointer/scale in the rung, which the charter forbids + (no oracle rebuild) and which would also be a behaviour change. The 30720 B + figure is therefore **derived byte arithmetic on a real 30720-sample file** + (`fin.f0`), not a captured half-length dump. +- **The root cause of the SIGSEGV** is not diagnosed — only located to the + rung's `fwrite` on the u16 buffer. Fixing it would change emitted bytes and + break the pairing, i.e. out of scope here; it is a separate lane if anyone + wants HBD pre-filter/post-deblock/post-CDEF ladders. +- **`bash scripts/instrument-aom-oracle.sh` was not executed end-to-end**, for + the same reason: its first act is rewriting the shared oracle source. The + `bash -n` plus 16/16 heredoc compile is the strongest check available + without it. + +## 5. Follow-ups this lane did not do (not done on purpose) + +1. The four rungs could take a `YV12_FLAG_HIGHBITDEPTH` branch like rung 12, + which would make them HBD-usable — but the decoder-side pair narrows to u8 + on purpose (`as u8`), so both sides would have to change together, and every + existing byte-pairing gate would need re-pinning. That is a behaviour + change, not a comment. +2. A reusable `stat -c%s … vs w*h*bps` check as a real assertion belongs in the + gate that decodes through these rungs, not in the patcher. + +## 6. Constraint compliance + +- `scripts/instrument-aom-oracle.sh` only (plus this report). +- Comments only — no emitted byte changes (diff verified in §4a). +- No decoder change, no gate change. +- `~/.cache/aom-oracle` was executed read-only; no rebuild, no source edit. + `git status --porcelain` in the primary checkout is unchanged (verified empty + before and after). +- Never pushed. diff --git a/scripts/instrument-aom-oracle.sh b/scripts/instrument-aom-oracle.sh index 953cc279..825419bf 100755 --- a/scripts/instrument-aom-oracle.sh +++ b/scripts/instrument-aom-oracle.sh @@ -7,6 +7,14 @@ # this script reproduce the full ladder from scratch. # # Rungs provided (both env-gated, so an uninstrumented run is unchanged): +# DEPTH TRAP (lane-av1oraclerungdepth): the DUMP rungs 1 / 6 / 7 / 15 write +# 1 byte per sample with no YV12_FLAG_HIGHBITDEPTH check (they are paired +# with decoder-side dumps that narrow to u8 on purpose). On a 10/12-bit +# stream they crash the oracle, or where they survive produce a file of +# EXACTLY HALF w*h*bps -- which looks like a truncated decode but is the +# rung's depth assumption. Each of those four carries a +# `DEPTH ASSUMPTION` block naming its decoder-side pair; rung 12 +# (EC_AV1_FINAL_DUMP) is the depth-correct one. # EC_AV1_PREFILT_DUMP= -> .f per frame, Y then U then V, # crop-sized rows, written after tile decode and BEFORE any loop filter, # 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" s = s.replace(old_sig, new_sig, 1) # --- rung 1: pre-filter recon dump -------------------------------------- +# DEPTH ASSUMPTION (lane-av1oraclerungdepth): this rung writes 1 byte per +# sample and has NO YV12_FLAG_HIGHBITDEPTH check. That is deliberate -- it is +# byte-paired with our own EC_AV1_PREFILT_DUMP, which narrows 10/12-bit to u8 +# on purpose (decode.rs:35263-35273, `p.data.iter().map(|&s| s as u8)`). +# TRAP: on an HBD stream the file is EXACTLY HALF w*h*2 = w*h bytes, which +# reads like a truncated/short decode, not a decoder bug. For HBD use rung 12 +# EC_AV1_FINAL_DUMP (:730) -- it IS depth-correct (u8 / u16 LE). +# OBSERVED 2026-09-29 on the HBD oracle build (CONFIG_AV1_HIGHBITDEPTH=1) with +# the committed `av112bit-key.obu` (160x128 4:2:0 12-bit = 30720 samples): +# rung 12 wrote 61440 B (w*h*bps) and this rung's 1-byte fwrite SIGSEGVs inside +# fwrite (exit 139, 0-byte file); the bytes it would have written are 30720 B +# = exactly half. Either way this is the RUNG's depth assumption, not a decoder +# defect -- never read a half-length/empty file here as a truncated decode. anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync, pbi->num_workers, 1);""" dump = """ { @@ -304,6 +325,16 @@ print("intra mode-info instrumented") PYI # --- rung 6: post-deblock, pre-superres row dump ------------------------ +# DEPTH ASSUMPTION (lane-av1oraclerungdepth): 1 byte per sample, NO +# YV12_FLAG_HIGHBITDEPTH check. Deliberate -- byte-paired with our +# EC_AV1_POSTDEBLOCK_DUMP, which narrows to u8 (decode.rs:35336, +# `dump_stage(..., &y, &u, &v)` over the u16 planes; same at :53126). +# TRAP: on an HBD stream the file is EXACTLY HALF w*h*2, which reads like a +# truncated/short decode, not a decoder bug. For HBD use rung 12 +# EC_AV1_FINAL_DUMP (:730) -- depth-correct (u8 / u16 LE). +# OBSERVED 2026-09-29 (HBD build, av112bit-key.obu): the 1-byte fwrite SIGSEGVs +# (exit 139); where it survives it writes 30720 B where 61440 B is expected -- +# exactly half. That is this rung, not a truncated decode. python3 - "$F" <<'PYD' import sys path = sys.argv[1] @@ -362,6 +393,16 @@ PYD # additive env var at the SAME anchor (pre-loop-filter) but dumping the full # y_width/y_height aligned buffer, so a margin-region reconstruction bug can # be told apart from a margin-region deblock bug. +# DEPTH ASSUMPTION (lane-av1oraclerungdepth): 1 byte per sample, NO +# YV12_FLAG_HIGHBITDEPTH check. Deliberate -- byte-paired with our +# EC_AV1_PREFILT_WIDE_DUMP, which narrows to u8 (decode.rs:19734-19762, +# `dump_prefilter_wide`; same body duplicated at :53048). TRAP: on an HBD +# stream the file is EXACTLY HALF w*h*2, which reads like a truncated/short +# decode, not a decoder bug. For HBD use rung 12 EC_AV1_FINAL_DUMP (:730) -- +# depth-correct (u8 / u16 LE). +# OBSERVED 2026-09-29 (HBD build, av112bit-key.obu): the 1-byte fwrite SIGSEGVs +# (exit 139); where it survives it writes 30720 B where 61440 B is expected -- +# exactly half. That is this rung, not a truncated decode. python3 - "$F" <<'PYW' import sys path = sys.argv[1] @@ -659,6 +700,19 @@ PYC11 # y_crop_width), 8-bit as u8 and high bitdepth as u16 LE -- bit-depth # correct, unlike the u8-narrowing debug dumps. # +# DEPTH TRAP (lane-av1oraclerungdepth) -- READ BEFORE USING ANY DUMP RUNG: +# rungs 1 (PREFILT :146), 6 (POSTDEBLOCK :352), 7 (PREFILT_WIDE :416) and +# 15 (POSTCDEF :934) write 1 byte per sample with NO YV12_FLAG_HIGHBITDEPTH +# check, because each is byte-paired with a decoder-side dump that narrows to +# u8 on purpose. On a 10/12-bit stream those four are unusable: measured on the +# HBD oracle build with `av112bit-key.obu` (160x128 4:2:0 12-bit, 30720 +# samples) their 1-byte fwrite SIGSEGVs (exit 139, 0-byte file), and where it +# survives it writes 30720 B where w*h*bps = 61440 B is expected -- EXACTLY +# HALF, which reads like a truncated decode. Check `stat -c%s` against +# w*h*bps before calling either a decoder defect. This rung (12) is the +# depth-correct one for HBD. Each of those four rungs carries a +# `DEPTH ASSUMPTION` block naming its decoder-side pair and line. +# # Rungs 1/6 (pre-filter / post-deblock) stop before CDEF+LR+superres, and # every ffmpeg/aomdec pixel gate in this repo compares SHOWN frames only # (class gate-blind-to-hidden-frames), so before this rung no instrument in @@ -848,6 +902,15 @@ PYST # builds (its 8-bit run SEGFAULTS); this rung is the 8-bit one. lane- # av1422filter added it to the live oracle tree by hand first, then it was # transcribed here (class: instrument that lives only in a build tree). +# DEPTH ASSUMPTION (lane-av1oraclerungdepth): 1 byte per sample, NO +# YV12_FLAG_HIGHBITDEPTH check. Deliberate -- byte-paired with our +# EC_AV1_POSTCDEF_DUMP, which narrows to u8 (decode.rs:35356; same at +# :53148). TRAP: on an HBD stream the file is EXACTLY HALF w*h*2, which reads +# like a truncated/short decode, not a decoder bug. For HBD use rung 12 +# EC_AV1_FINAL_DUMP (:730) -- depth-correct (u8 / u16 LE). +# OBSERVED 2026-09-29 (HBD build, av112bit-key.obu): the 1-byte fwrite SIGSEGVs +# (exit 139); where it survives it writes 30720 B where 61440 B is expected -- +# exactly half. That is this rung, not a truncated decode. python3 - "$F" <<'PYC' import sys path = sys.argv[1]