forge
Explore
Log in

Don't you dare go Hollow

lane-av1leaf8oob: derive leaf8 intrabc chroma extent from subsampling

Browse files at this commit

9aeafc1387814d9d764beaf52b9964f261cd6c07Ahmet Kaan GümüşParent: 0bfd062
decode_leaf8's intrabc frame-copy closure hardcoded the 4:2:0 chroma
halving (vec![0u16; 4 * 4], predict_with_filter at 4, 4) for the U/V
prediction buffers. At 4:4:4 the leaf's own chroma plane block is 8x8,
so the 16-sample override reached PlaneBuf::reconstruct as an 8x8
prediction and indexed prediction[16] of the 16-sample buffer
(len 16, index 16, decode.rs:3774). Size both buffers from
(8 >> ss_x, 8 >> ss_y) instead -- identical at 4:2:0, 8x8 at 4:4:4 --
which also heals the stride-8 palette windows the TX4 4:4:4-lossless
arm cuts from the same buffers.

Gate: stream::tests::an_intrabc_8x8_leaf_chroma_frame_copy_at_444_
decodes_without_the_oob pins the witness-hunt reproducer
(fixtures/444_leaf8_oob.obu, force-added, sha256 72bed279...) with a
red-before run reproducing the exact panic and a leaf8_intrabc_hits
0 -> 4 non-vacuity delta. The gate pins no pixel baseline: the stream
diverges from the oracle aomdec and reads never-written chroma samples
in 458 whole 8x8 blocks (nondeterministic output) -- one pre-existing
decode desync, deferred to a divergence lane, measured in
lanes/av1leaf8oob.report.md. intrabc + lossless filters green, cargo
check 0 warnings.
crates/ec-av1/fixtures/444_leaf8_oob.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+16 -6
@@ -18150,17 +18150,27 @@ fn decode_leaf8(
18150 mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),18150 mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
18151 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,18151 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
18152 );18152 );
18153- let mut ub = vec![0u16; 4 * 4];18153+ // The chroma extent is THIS frame's subsampled size of the 8x8 luma
18154+ // leaf (`get_plane_block_size`): 4x4 at 4:2:0, 8x8 at 4:4:4. The
18155+ // literal 4x4 this replaces hardcoded the 4:2:0 halving -- at 4:4:4
18156+ // the 16-sample override fed this leaf's own 8x8 chroma reconstruct,
18157+ // which indexed `prediction[16]` of a 16-sample buffer
18158+ // (len 16, index 16 at `PlaneBuf::reconstruct`). The same buffers
18159+ // are windowed at stride 8 by `read_intra_chroma_lossless` (the TX4
18160+ // 4:4:4-lossless arm) and consumed whole by the TX8 and skip arms,
18161+ // so all three heal with this one sizing.
18162+ let (cw, ch) = (8 >> ss_x(fctx), 8 >> ss_y(fctx));
18163+ let mut ub = vec![0u16; cw * ch];
18154 mc::predict_with_filter(18164 mc::predict_with_filter(
18155 &u.data, u.width, u.true_width, u.true_height,18165 &u.data, u.width, u.true_width, u.true_height,
18156- mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),18166+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)),
18157- 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,18167+ cw, ch, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
18158 );18168 );
18159- let mut vb = vec![0u16; 4 * 4];18169+ let mut vb = vec![0u16; cw * ch];
18160 mc::predict_with_filter(18170 mc::predict_with_filter(
18161 &v.data, v.width, v.true_width, v.true_height,18171 &v.data, v.width, v.true_width, v.true_height,
18162- mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),18172+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)),
18163- 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,18173+ cw, ch, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
18164 );18174 );
18165 (yb, ub, vb)18175 (yb, ub, vb)
18166 });18176 });
crates/ec-av1/src/stream.rsmodified+126 -0
@@ -5762,6 +5762,132 @@ pub(crate) mod tests {
5762 }5762 }
5763 }5763 }
5764 5764
5765+ /// lane-av1-leaf8oob: the OOB pin for [`decode_leaf8`]'s intrabc chroma
5766+ /// frame-copy buffers. The closure hardcoding the leaf's chroma
5767+ /// prediction at `4x4` (`vec![0u16; 4 * 4]`, `predict_with_filter` at
5768+ /// `4, 4`) carried the 4:2:0 halving of an 8x8 luma leaf into every
5769+ /// subsampling: at 4:4:4 the leaf's own chroma plane block is 8x8
5770+ /// (`csz == 8`), so the 16-sample override reached
5771+ /// [`PlaneBuf::reconstruct`] as an 8x8 prediction and indexed
5772+ /// `prediction[16]` of a 16-sample buffer --
5773+ /// `index out of bounds: the len is 16 but the index is 16` at the
5774+ /// reconstruct call, on every conformant stream of this shape (a panic,
5775+ /// never a refusal). Same signature class as lane-lossless128's
5776+ /// 128-axis lossless extent (`len 16, index 16` there too).
5777+ ///
5778+ /// `crates/ec-av1/fixtures/444_leaf8_oob.obu`, 3577 bytes, sha256
5779+ /// `72bed2791d1ceba8be7926a052c7838c5d96d4f9d56d28fb69789a753d3593af`
5780+ /// (force-added past the `fixtures` gitignore like every sibling
5781+ /// fixture): the lane ticket's witness-hunt reproducer (s1a/s2e) -- a
5782+ /// 320x256, 3-frame, 8-bit 4:4:4 screen-content keyframe run whose
5783+ /// census pins 4 intrabc 8x8 leaves (the oracle's own MB dump opens on
5784+ /// unbroken inter-classified intra = intrabc blocks). The encoding
5785+ /// recipe is not independently recoverable in this lane; the bytes are
5786+ /// pinned by length + FNV-1a64 here and by the oracle raw fingerprint
5787+ /// below.
5788+ ///
5789+ /// WHAT THIS GATE DOES NOT CLAIM: sample-exactness -- and it pins no
5790+ /// pixel baseline. Measured against the oracle aomdec (`--rawvideo`;
5791+ /// comparison method ground-truthed by the green
5792+ /// `a_lossless_sb128_rect_intra_block_decodes_sample_exact` and
5793+ /// `a_lossless_444_min_partition8_inter_stream_decodes_sample_exact`
5794+ /// witnesses on this same tree), this stream DIVERGES and its output is
5795+ /// not even self-deterministic: frame 0's first differing LUMA sample
5796+ /// is at (275,128), the (y, u, v) differing counts per frame are
5797+ /// (20811, 35467, 32320)/(20308, 39177, 35994)/(20131, 39588, 36601) of
5798+ /// 81920 samples per plane, and under `EC_AV1_PLANE_SENTINEL=1` the
5799+ /// chroma counts move (u f0 35467 -> 35630) while luma stays put.
5800+ /// Sentinel-vs-uninit output diffing localises that dependence to 458
5801+ /// WHOLE 8x8 chroma blocks (frame 0: chroma x >= 96, y >= 64) reading
5802+ /// samples this decode never wrote -- ambient memory in those slots,
5803+ /// hence any pixel-exact assert here drifts run to run with the batch.
5804+ /// Both facts belong to ONE pre-existing defect this lane must not
5805+ /// chase (the ticket's fix touches only leaf8's chroma prediction
5806+ /// buffers, which cannot feed a luma sample, and the pre-fix run never
5807+ /// got past the panicked leaf): a decode desync on this stream around
5808+ /// frame-0 SB (3..4, 2), after which samples diverge from the oracle
5809+ /// and the misread layout leaves chroma blocks unreconstructed.
5810+ /// Disposition: `deferred(unblock: divergence lane -- EC trace pairing
5811+ /// against the oracle on this fixture)`. So this gate pins exactly what
5812+ /// its ticket owns: fixture identity, a decode that RUNS TO COMPLETION
5813+ /// where the old code died with `len 16, index 16`, and the arm counter.
5814+ ///
5815+ /// Assertions (all before/without any skip path):
5816+ /// 1. fixture bytes: exact length + FNV-1a64;
5817+ /// 2. `decode_stream` succeeds -- 3 frames, 320x256 (the pre-fix run
5818+ /// died here with the len-16/index-16 panic);
5819+ /// 3. non-vacuity: `leaf8_intrabc_hits` moves (measured 0 -> 4), so the
5820+ /// arm owning the fixed buffers really fired;
5821+ /// 4. the oracle aomdec still decodes the pinned bytes (raw size +
5822+ /// fingerprint), anchoring the deferred divergence comparison.
5823+ #[test]
5824+ fn an_intrabc_8x8_leaf_chroma_frame_copy_at_444_decodes_without_the_oob() {
5825+ const NAME: &str = "an_intrabc_8x8_leaf_chroma_frame_copy_at_444_decodes_without_the_oob";
5826+ const FIXTURE_LEN: usize = 3577;
5827+ const FIXTURE_FNV: u64 = 0x86b9_3a51_fe16_353c;
5828+ const W: usize = 320;
5829+ const H: usize = 256;
5830+ const FRAMES: usize = 3;
5831+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
5832+ .join("fixtures/444_leaf8_oob.obu");
5833+ let stream = std::fs::read(&obu).unwrap_or_else(|e| {
5834+ panic!(
5835+ "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \
5836+ which is a failure, not a skip",
5837+ obu.display()
5838+ )
5839+ });
5840+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved");
5841+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
5842+
5843+ let _guard = lock_gate_counters();
5844+ crate::decode::reset_leaf8_intrabc_hits();
5845+ let frames = decode_stream(&stream).unwrap_or_else(|e| {
5846+ panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
5847+ });
5848+ assert!(
5849+ crate::decode::leaf8_intrabc_hits() > 0,
5850+ "{NAME}: gate is vacuous -- no intrabc 8x8 leaf was decoded, so the arm \
5851+ owning the fixed chroma buffers never fired"
5852+ );
5853+ assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
5854+ for f in &frames {
5855+ assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");
5856+ }
5857+
5858+ // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames.
5859+ if aomdec_path().is_file() {
5860+ let dir = std::env::temp_dir().join(format!("ec-av1-leaf8oob-{}", std::process::id()));
5861+ let _ = std::fs::remove_dir_all(&dir);
5862+ std::fs::create_dir_all(&dir).expect("scratch dir");
5863+ let raw = dir.join("aomdec.raw");
5864+ let out = Command::new(aomdec_path())
5865+ .args(["--codec=av1", "--rawvideo", "-o"])
5866+ .arg(&raw)
5867+ .arg(&obu)
5868+ .stdin(Stdio::null())
5869+ .stdout(Stdio::piped())
5870+ .stderr(Stdio::piped())
5871+ .output()
5872+ .expect("aomdec failed to run");
5873+ assert!(
5874+ out.status.success(),
5875+ "{NAME}: the oracle aomdec refused the stream: {}",
5876+ String::from_utf8_lossy(&out.stderr)
5877+ );
5878+ let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output");
5879+ let _ = std::fs::remove_dir_all(&dir);
5880+ assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size");
5881+ assert_eq!(
5882+ fnv1a64(&ref_raw),
5883+ 0x3821_0bcb_f572_973c,
5884+ "{NAME}: aomdec raw fingerprint moved"
5885+ );
5886+ } else {
5887+ eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
5888+ }
5889+ }
5890+
5765 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis5891 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis
5766 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces5892 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces
5767 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane5893 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane
lanes/av1leaf8oob.report.mdadded+134 -0
@@ -0,0 +1,134 @@
1+# lane-av1leaf8oob: fix the 4:4:4 intrabc 8x8-leaf chroma OOB panic
2+
3+Tree: lane-av1-leaf8oob @ 9e77c16b (base = lane-av1llpredgate2's pin).
4+Reproducer pinned at `crates/ec-av1/fixtures/444_leaf8_oob.obu`.
5+
6+## Defect
7+
8+`cargo run -p ec-av1 --example decode_probe` on the fixture died with
9+
10+```
11+thread 'main' panicked at crates/ec-av1/src/decode.rs:3774:16:
12+index out of bounds: the len is 16 but the index is 16
13+```
14+
15+(`PlaneBuf::reconstruct` via `exec_intra` via `decode_leaf8`, reached through
16+the `#[track_caller]` reconstruct calls at 4:4:4, 8x8 leaf.)
17+
18+Root cause, ONE plane-math site as the ticket guessed: `decode_leaf8`'s
19+intrabc frame-copy closure sized the leaf's chroma prediction buffers with
20+the literal 4:2:0 halving of an 8x8 luma leaf — `vec![0u16; 4 * 4]` and
21+`predict_with_filter(.., 4, 4, ..)` for BOTH U and V — while the leaf's own
22+chroma reconstruct at 4:4:4 runs `csz == 8`. The 16-sample override rode the
23+`PALETTE_PRED` slot into `reconstruct` as an 8x8 prediction, which indexed
24+`prediction[row * 8 + col]` = 16 at row 2, col 0: `len 16, index 16`.
25+
26+## Fix (source, not a clamp)
27+
28+`crates/ec-av1/src/decode.rs`, `decode_leaf8` intrabc closure: the chroma
29+extent is now derived from the frame's subsampling,
30+`(cw, ch) = (8 >> ss_x(fctx), 8 >> ss_y(fctx))` for both the buffer size and
31+the `predict_with_filter` geometry, and the row subpel arg uses `ss_y` like
32+every sibling intrabc site (rect intrabc at 11570/11910/11920, the
33+`luma: bool` helper at 13899; bit-identical at every reachable ss since
34+4:2:2 refuses at the sequence header, so ss_x == ss_y in all decodable
35+streams). 4:2:0 still computes 4x4 — byte-identical there.
36+
37+The one sizing heals all three consumers of the buffers: the TX8 and skip
38+arms consume them whole at `csz`, and the TX4 4:4:4-lossless arm windows
39+them at stride 8 inside `read_intra_chroma_lossless`
40+(`palette_window(buf, stride, ox, oy, 4, 4)` reads up to index 63), which
41+had the same OOB latent.
42+
43+## Class sweep (hardcoded 4:2:0 chroma extent, decode.rs)
44+
45+Swept every intrabc chroma prediction site in decode.rs:
46+
47+| site | extent | verdict |
48+|---|---|---|
49+| `decode_leaf8` intrabc closure (18128/18134 pre-fix) | literal `4*4` | **THE BUG** — fixed |
50+| `decode_block` square intrabc (16735+) | `chroma_side = side >> ss_x` | ss-derived, clean |
51+| rect intrabc owned/rect4 (11557+, 11897+) | `cw * ch`, `cside` | ss-derived, clean |
52+| `predict_intrabc` helper (13899) | `w * h` params, `ss_x`/`ss_y` split | clean |
53+| `sub8_leaf_chroma444` (18927+) | `bw * bh` (already chroma units) | clean by construction |
54+| `decode_leaf_split4` 4x4 arm (19423+) | literal `4*4`/`4,4` | 4:2:0-only arm (chroma_444 returns earlier) — literal correct there |
55+| `decode_leaf_rect8` clamp arm (20106+) | literal `4*4`/`4,4` | same 4:2:0-only arm — literal correct there |
56+
57+No second 4:4:4-reachable instance exists in decode.rs. Signature-class
58+note: lane-lossless128 hit the identical panic text (`len 16, index 16`)
59+from a 128-axis lossless extent — recurring class, both now pinned by
60+gates.
61+
62+## Gate
63+
64+`stream::tests::an_intrabc_8x8_leaf_chroma_frame_copy_at_444_decodes_without_the_oob`
65+(crates/ec-av1/src/stream.rs), modelled on the av1llpredgate2 pattern:
66+
67+- Fixture provenance: the lane ticket's witness-hunt reproducer (s1a/s2e);
68+ 3577 bytes, sha256
69+ `72bed2791d1ceba8be7926a052c7838c5d96d4f9d56d28fb69789a753d3593af`,
70+ FNV-1a64 `0x86b93a51fe16353c`; 320x256, 3 frames, 8-bit 4:4:4
71+ screen-content keyframes (the oracle's MB dump opens on unbroken
72+ inter-classified intra = intrabc blocks). The aomenc recipe is not
73+ independently recoverable in this lane — bytes pinned by length + FNV +
74+ oracle raw fingerprint. Force-added past the `fixtures` gitignore like
75+ every sibling fixture; missing file panics, no skip path.
76+- Assertions: fixture bytes (len + FNV), `decode_stream` succeeds (3
77+ frames, 320x256 — the pre-fix run died here), `leaf8_intrabc_hits`
78+ 0 -> 4 non-vacuity, and the oracle aomdec still decodes the pinned bytes
79+ (raw 737280 bytes, FNV `0x38210bcbf572973c`).
80+
81+### Red-before (mutation verification)
82+
83+`git checkout --` of the fix (patch snapshotted to /tmp, restored
84+byte-identical, `diff`-verified): gate RED at
85+`decode.rs:3774:16 index out of bounds: the len is 16 but the index is 16`
86+— the exact ticketed panic. With the fix: green, standalone AND in the
87+full `intrabc lossless` filter batch (26 passed, 3 consecutive runs).
88+
89+### Why the gate pins NO pixel baseline (measured, then scoped out)
90+
91+Against the oracle aomdec (`--rawvideo`; comparison method ground-truthed:
92+`a_lossless_sb128_rect_intra_block_decodes_sample_exact` and
93+`a_lossless_444_min_partition8_inter_stream_decodes_sample_exact` are green
94+on this same tree), this stream DIVERGES, and not deterministically:
95+
96+- per-frame differing (y, u, v) of 81920 samples/plane:
97+ (20811, 35467, 32320), (20308, 39177, 35994), (20131, 39588, 36601);
98+ frame 0's first differing LUMA sample at (275,128);
99+- under `EC_AV1_PLANE_SENTINEL=1` chroma counts move (u f0 35467 -> 35630)
100+ while luma stays put; sentinel-vs-uninit output diffing localises the
101+ dependence to 458 WHOLE 8x8 chroma blocks (frame 0: chroma x >= 96,
102+ y >= 64) reading samples this decode never wrote — ambient memory, so
103+ any pixel-exact assert drifts run to run (observed: u f1 39177 vs
104+ 39126 vs 39138 across batch runs).
105+
106+Attribution to this lane's diff: none. The fix touches only leaf8's chroma
107+prediction buffers; intra/intrabc luma reads only luma edges and the luma
108+plane, so a luma-first divergence cannot come from it, and the pre-fix run
109+never produced output (panic at the first intrabc 8x8 leaf).
110+
111+Unified reading: ONE pre-existing decode desync on this stream around
112+frame-0 SB (3..4, 2) — after it, samples diverge from the oracle AND the
113+misread layout leaves whole chroma blocks unreconstructed (which is where
114+the never-written reads live). An initial-bounds witness would not have
115+seen this: the stream never decoded before this lane lifted the panic.
116+
117+Disposition: `deferred(unblock: divergence lane — EC trace pairing against
118+the oracle on this fixture; the oracle's AOMMB dump covers only frame 0's
119+first MB rows, so pairing needs the env-gated rungs)`.
120+
121+## Non-regression
122+
123+- `cargo test -p ec-av1 --lib -- intrabc lossless`: 26 passed, 0 failed
124+ (3 consecutive runs, including the 4:2:0 intrabc gates
125+ `an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy`,
126+ the sb128 intrabc pixel-exact gates, and the 4:4:4 lossless
127+ minp64/minp8/sb128 sample-exact gates).
128+- `cargo check -p ec-av1`: 0 warnings.
129+
130+## Hygiene
131+
132+- Target dir `$HOME/.cache/cargo-target-av1leaf8oob` throughout.
133+- Throwaway instruments (`examples/oob_diff.rs`, `examples/oob_dump.rs`)
134+ deleted before commit; no other tree touched; nothing pushed.