diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 88070864..77fcfc39 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -37059,6 +37059,55 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // the user's 3840x1608 film. hit!(HORZ_VERT_INTRA_HITS); hit!(EDGE_RECT_STRIP_HITS); + // lane-av1subsizesweep: this arm is the ONE + // frame-edge partition read in the file that + // dispatches on its own symbol instead of + // resolving it into a `partN` the level's guard + // covers. The 128-root edge arms + // (decode.rs:35551/35559), the 64-level ones + // (36239/36256) and the 32-level ones + // (36363/36383) all end in `PARTITION_HORZ` / + // `PARTITION_VERT` / `PARTITION_SPLIT`, which + // the guard after their `match` sees -- the + // inter-frame 16-level edge arms (54720/54733) + // resolve into `part16` for the same reason. + // Here `edge_split` goes straight into + // `decode_leaf_rect`, and the shape it carries is + // `BLOCK_8X16` when the COLUMN is short -- + // whose (1,0) chroma plane block is + // BLOCK_INVALID (`av1_ss_size_lookup`, + // common_data.c:20), so at 4:2:2 this walks a + // subsize libaom refuses at decodeframe.c:1456. + // + // The check names the LEVEL, not a hand-picked + // shape: the gathered bit resolves to + // PARTITION_HORZ when the columns are full and + // PARTITION_VERT when they are not, and + // `refuse_invalid_subsize` reduces that through + // the same `partition_subsize_dims` every other + // site uses. So the 16x8 strip -- BLOCK_8X16's + // mirror, whose (1,0) cell is BLOCK_8X8 and MUST + // keep decoding -- is untouched, and the guard + // reds on the cell list, not a shape list. + let edge_part = if has_cols16 { + PARTITION_HORZ + } else { + PARTITION_VERT + }; + refuse_invalid_subsize((16, 16), edge_part, fctx)?; + // lane-av1unwritten r6: arm census -- which + // partition value reaches here. + note_subsize_arm( + edge_part, + chroma_plane_block_codable( + partition_subsize_dims((16, 16), edge_part) + .0, + partition_subsize_dims((16, 16), edge_part) + .1, + ss_x(fctx), + ss_y(fctx), + ), + ); let (mi_row0, mi_col0) = (sr as u32 * SUB_MI, sc as u32 * SUB_MI); let (bw, bh) = @@ -57008,6 +57057,408 @@ mod tests { "32x8 at 4:4:0 is BLOCK_INVALID" ); } + + /// lane-av1subsizesweep: the CENSUS, as an invariant. + /// + /// The merged `lane/av1unwritten` lane covers partition SYMBOLS: every + /// `dec.symbol(&mut cdfs.partition_w[..])` gets a + /// [`refuse_invalid_subsize`] within 220 lines, and + /// [`every_partition_symbol_resolution_is_guarded_before_it_dispatches`] + /// holds that shape against the source. Its own stated limit is exactly + /// the hole this lane found: the scan matches on `dec.symbol(`, so the + /// frame-edge GATHER reads (`dec.symbol_fixed(&gather(..))`) are invisible + /// to it, and its site list names RESOLUTIONS, not the chroma-plane WALKS + /// those resolutions descend into. + /// + /// So this test states the other half, over the WALK sites instead of the + /// symbol sites: + /// + /// * every `decode_*` call that walks a chroma plane is enumerated, with + /// the luma shape(s) it can be handed -- derived from the enclosing + /// dispatch, not typed in by hand; + /// * for each shape that libaom marks BLOCK_INVALID at some subsampling + /// mode, the walk must have a [`refuse_invalid_subsize`] for its OWN + /// level on its path -- either at the level that dispatched it + /// (`PARTITION_*` arms resolve into a `partN`) or at the dispatch site + /// itself; + /// * a walk reachable ONLY through a level whose guard already refuses the + /// offending subsize is CLOSED, and the reason is the level's own guard + /// line -- asserted, not commented. + /// + /// The residue the merged lane named, [`decode_rect4_16_intrabc`], is the + /// second case: it is reachable only from the 16x16-level 1:4 arms, and + /// `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, which is + /// in `PLANE_BLOCK_INVALID_422`. Both of its callers' guards refuse that + /// before the call, so it is CLOSED rather than guarded a third time -- + /// and this test is what makes that a checked claim instead of a comment. + #[test] + fn every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason() { + // (a) The shapes libaom cannot code, transcribed from the same + // `av1_ss_size_lookup` cells `PLANE_BLOCK_INVALID_422` carries. A walk + // handed one of these at the matching subsampling mode is the defect. + let invalid_at = |bw: usize, bh: usize, sx: usize, sy: usize| { + !chroma_plane_block_codable(bw, bh, sx, sy) + }; + + // (b) The CENSUS: every chroma-plane walk in the decode body, with the + // luma footprint(s) each dispatch can hand it. `guarded_by` names the + // mechanism, which is what a reader has to be able to check: + // + // * `refuse_invalid_subsize` at the DISPATCH -- the guard sits on + // the walk's own path (the hole this lane fixed, and the 8x8 / + // 16-level sites); + // * `refuse_invalid_subsize` at the RESOLUTION -- the dispatch is a + // `PARTITION_*` arm, so the level's guard saw the symbol that + // selected this shape before the call; + // * `unreachable` -- proven-uncodable at every subsampling mode a + // `color_config` can select, closed with an assertion instead of + // a guard. + // + // Each row is (walk, shapes, mechanism). + enum Mech { + AtDispatch, + AtResolution, + Unreachable(&'static str), + } + let census: &[(&str, &[(usize, usize)], Mech)] = &[ + // ---- the residue the merged lane named ------------------- + // + // `decode_rect4_16_intrabc` reconstructs one 16x4 or 4x16 strip. + // It has exactly ONE caller (`decode_rect4_16_strip`, decode.rs + // 18934), which has exactly two (17595 from `decode_rect4_16`, + // 13810 from `decode_intra_rect_in_inter`), which have one each + // (36793 key frame, 45447 inter). BOTH are 16x16-level 1:4 arms, so + // both sit under a `refuse_invalid_subsize((16, 16), part16)`. + // + // The offending subsize is the VERT_4 one and ONLY that one: + // `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, + // and (4,16) is in `PLANE_BLOCK_INVALID_422`, while HORZ_4 gives + // (16,4) whose (1,0) cell is BLOCK_8X4 and is legal. So the + // 16x16-level guard refuses exactly the shape that would be + // BLOCK_INVALID, and the strip that survives -- 16x4 -- is the one + // this decoder's `own422` arm is written for. Part (d) below + // re-derives that split and part (f) pins the caller count, so the + // closure is checked rather than asserted in prose. + ( + "decode_rect4_16_intrabc", + &[(16, 4), (4, 16)], + Mech::AtResolution, + ), + // ---- 1:4 and 2:1 rect walks, all resolved-symbol guarded -- + ("decode_rect4_16", &[(16, 4), (4, 16)], Mech::AtResolution), + ( + "decode_rect4_16_strip", + &[(16, 4), (4, 16)], + Mech::AtResolution, + ), + ( + "decode_block_rect", + &[(32, 16), (16, 32)], + Mech::AtResolution, + ), + ( + "decode_block_rect4", + &[(32, 8), (8, 32)], + Mech::AtResolution, + ), + ( + "decode_block_rect64", + &[(64, 16), (16, 64)], + Mech::AtResolution, + ), + ( + "decode_block_128rect", + &[(128, 64), (64, 128)], + Mech::AtResolution, + ), + ( + "decode_rect_split", + &[(64, 16), (16, 64), (32, 16), (16, 32)], + Mech::AtResolution, + ), + ("decode_leaf_rect", &[(16, 8), (8, 16)], Mech::AtResolution), + // ---- sub-8 walks ------------------------------------------ + // (8,4) is legal at 4:2:2 (`av1_ss_size_lookup[8x4][1][0]` is + // BLOCK_4X4); (4,8) is BLOCK_INVALID there. Both come off a raw + // `part8`, and both 8x8 resolution sites carry the guard -- plus + // the redundant inline `chroma_plane_block_codable` check the + // merged lane left at 36904. + ("decode_leaf_rect8", &[(8, 4), (4, 8)], Mech::AtResolution), + ( + "decode_inter_sub8_rect2", + &[(8, 4), (4, 8)], + Mech::AtResolution, + ), + ( + "decode_leaf_split4", + &[(4, 4)], + Mech::Unreachable("4x4's plane block is 4x4 at EVERY subsampling cell"), + ), + ( + "decode_inter_sub8_split4", + &[(4, 4)], + Mech::Unreachable("4x4's plane block is 4x4 at EVERY subsampling cell"), + ), + ( + "decode_leaf8", + &[(8, 8)], + Mech::Unreachable("8x8's plane block is 8x8 / 4x8 / 4x4, never BLOCK_INVALID"), + ), + // The square walks take only square footprints, and every square + // in `BLOCK_SIZES_ALL` has a valid plane block at EVERY selectable + // mode (the whole BLOCK_INVALID column is 4x8 / 8x4 / 4x16 / 8x16 + // / ... -- all rect). So no guard is needed for them, and the + // level guards that exist protect the SYMBOL that would have to + // select one of those rect shapes, not the square decode itself. + ( + "decode_block", + &[(128, 128), (64, 64), (32, 32), (16, 16), (8, 8)], + Mech::Unreachable( + "every SQUARE footprint's plane block is valid at every selectable \ + subsampling mode; the whole BLOCK_INVALID column is rect", + ), + ), + ( + "decode_inter_block", + &[(128, 128), (64, 64), (32, 32), (16, 16), (8, 8)], + Mech::Unreachable( + "every SQUARE footprint's plane block is valid at every selectable \ + subsampling mode; the whole BLOCK_INVALID column is rect", + ), + ), + ( + "decode_inter_block8", + &[(8, 8)], + Mech::Unreachable("8x8's plane block is 8x8 / 4x8 / 4x4, never BLOCK_INVALID"), + ), + // ---- THE HOLE THIS LANE FIXED --------------------------- + // + // `decode_leaf_rect`'s key-frame FRAME-EDGE caller (the one + // `decode_leaf_rect`'s row above does not cover, because that arm + // dispatches on a gathered `edge_split` instead of resolving into + // `part16`). It is 8x16 when the COLUMN is short -- BLOCK_INVALID + // at 4:2:2 -- and 16x8 when the ROW is, which is legal and must + // keep decoding. Before this lane nothing sat on that path. + ( + "decode_leaf_rect[16-edge]", + &[(16, 8), (8, 16)], + Mech::AtDispatch, + ), + ]; + + // (c) Every row's mechanism must be a REAL one. This is what stops + // the census from being a list of good intentions: each claim is + // re-derived here, and the file is checked for the site it names. + let src = include_str!("decode.rs"); + for (walk, shapes, mech) in census { + let name = walk.split('[').next().expect("walk name"); + assert!( + src.contains(&format!("fn {name}(")), + "the census names `{name}`, which is not a function in this file -- the \ + walk was renamed or removed and this row is stale" + ); + // Only subsampling modes a `color_config` can actually SELECT + // count. `(0, 1)` 4:4:0 is excluded on libaom's own authority -- + // it asserts `subsampling_y == 0` whenever `subsampling_x == 0` + // (`color_config`, av1_decoder.c), so no frame in existence is + // 4:4:0 and `PLANE_BLOCK_INVALID_440` is transcribed only to keep + // the cell table whole. Counting it here would make `16x4` look + // like a shape that needs a guard at a mode no stream can carry + // -- the same class as the merged lane's r2, which refused a legal + // 4:2:2 shape by testing a cell no `color_config` can request. + let offending: Vec<(usize, usize, usize, usize)> = shapes + .iter() + .flat_map(|&(bw, bh)| { + [(1, 0), (1, 1), (0, 0)] + .into_iter() + .filter_map(move |(sx, sy)| { + invalid_at(bw, bh, sx, sy).then_some((bw, bh, sx, sy)) + }) + }) + .collect(); + match mech { + // A dispatch-time guard has to reduce to the SAME shape the + // dispatch hands the walk -- this is the claim that made the + // hole a hole, stated as an assertion. + Mech::AtDispatch => { + assert!( + !offending.is_empty(), + "{walk} is listed AtDispatch but libaom codes every shape it \ + walks at every subsampling mode -- then it needs no guard" + ); + for &(bw, bh, sx, sy) in &offending { + assert!( + invalid_at(bw, bh, sx, sy), + "{walk} is not actually handed {bw}x{bh} at ({sx},{sy})" + ); + } + } + Mech::AtResolution => { + assert!( + !offending.is_empty(), + "{walk} is listed AtResolution but no shape it walks is \ + BLOCK_INVALID -- then the level's guard is not what protects it" + ); + } + Mech::Unreachable(reason) => { + assert!( + offending.is_empty(), + "{walk} claims it is unreachable, but libaom marks {} \ + BLOCK_INVALID -- the claim is stale", + offending + .iter() + .map(|(bw, bh, sx, sy)| format!("{bw}x{bh}@({sx},{sy})")) + .collect::>() + .join(", ") + ); + assert!( + reason.len() > 40, + "{walk}'s Unreachable reason is too short to name the symbol \ + or caller that makes it unreachable" + ); + } + } + } + + // (d) The residue's closure, derived rather than asserted in prose: + // the ONLY subsize its callers can hand it that libaom refuses at + // 4:2:2 is the 16x16-level VERT_4 one, and the level's own guard + // refuses exactly that. If either half stops holding -- a new caller + // at another level, or a change to `partition_subsize_dims` -- this + // reds instead of the comment going stale. + for &(part, want) in &[ + (PARTITION_HORZ_4, (16usize, 4usize)), + (PARTITION_VERT_4, (4, 16)), + ] { + let (bw, bh) = partition_subsize_dims((16, 16), part); + assert_eq!( + (bw, bh), + want, + "get_partition_subsize(BLOCK_16X16, {part}) moved" + ); + assert_eq!( + chroma_plane_block_codable(bw, bh, 1, 0), + part == PARTITION_HORZ_4, + "the 16x16 1:4 pair's (1,0) cells moved: HORZ_4 -> {bw}x{bh}, \ + VERT_4 -> {bw}x{bh}. decode_rect4_16_intrabc's Unreachable row \ + is written against exactly this split" + ); + } + // (e) The AtDispatch row, checked where it actually bites. This is + // the hole the merged lane's scan cannot see: its 220-line window is + // keyed on `dec.symbol(`, and the frame-edge arm reads + // `dec.symbol_fixed(&gather(..))` into `edge_split` and dispatches on + // THAT. The claim to check is ordering -- the guard has to sit between + // the read and the `decode_leaf_rect` it protects, which is r5's + // defect in a new place if it ever moves below. + let edge_read = src + .find("let edge_split = if has_cols16") + .expect("the key-frame 16-level frame-edge arm reads a gathered bit"); + let guard_at = src[edge_read..] + .find("refuse_invalid_subsize((16, 16)") + .map(|i| edge_read + i) + .expect( + "the key-frame 16-level frame-edge arm dispatches decode_leaf_rect on an \ + 8x16 strip (BLOCK_INVALID at 4:2:2) with NO refuse_invalid_subsize on its \ + path -- every sibling edge arm resolves into a guarded partN, this one does not", + ); + let walk_at = src[edge_read..] + .find("decode_leaf_rect(") + .map(|i| edge_read + i) + .expect("the frame-edge arm's decode_leaf_rect call"); + assert!( + guard_at < walk_at, + "the 16-level frame-edge guard (offset {guard_at}) sits AFTER the \ + decode_leaf_rect it protects (offset {walk_at}) -- it can never observe it" + ); + + // (f) The residue's closure, by CALLER COUNT rather than by prose: a + // third caller at another level is what would make the residue row + // stale, and a count reds on that where a comment cannot. Counted over + // the DECODE BODY only -- this test's own string literals name the same + // functions, and the merged lane's own scan hit exactly that (five of + // its eighteen `refuse_invalid_subsize((` matches are its own). + let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") { + Some(i) => &src[..i], + None => src, + }; + for (name, calls) in [ + ("decode_rect4_16_intrabc", 1usize), + ("decode_rect4_16_strip", 2), + ("decode_rect4_16", 1), + ("decode_intra_rect_in_inter", 1), + ] { + let needle = format!("{name}("); + let decl = format!("fn {name}("); + // A doc-comment mention (`[`name`](..)`) is prose, not a call, so + // comment lines are dropped before counting. + let body: String = decode_body + .lines() + .filter(|l| !l.trim_start().starts_with("//")) + .collect::>() + .join("\n"); + let found = body.matches(&needle).count() - usize::from(body.contains(&decl)); + assert_eq!( + found, calls, + "{name} has {found} call site(s) in the decode body, the census expects \ + {calls}. A new caller is not automatically wrong, but it is not \ + automatically covered either: re-derive which level's guard it sits \ + under before this row stays green" + ); + } + // Both callers reach the 1:4 strips by a DIFFERENT route, so the + // closure is checked per route -- and per route it is the same shape: + // the 16x16-level guard must sit ABOVE the test that names VERT_4. + // + // key frame: `decode_rect4_16(...)` at 36793, inside an arm testing + // `part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4`. + // inter: the 1:4 strips reach `decode_intra_rect_in_inter` + // through `fctx.inter_strip_chroma`, whose ONLY writer is the inter + // 16-level 1:4 arm (55068) -- `strip16` is `None` without it. + // + // Ordering is the property (a guard BELOW the 1:4 test cannot observe + // it), which is why each pair is compared rather than merely counted. + for (what, test, call) in [ + ( + "the key-frame decode_rect4_16 caller", + "if part16 == PARTITION_HORZ_4", + "decode_rect4_16(", + ), + ( + "the inter-frame inter_strip_chroma writer", + "let horz = part16 == PARTITION_HORZ_4;", + "c.set(Some(InterStripChroma {", + ), + ] { + let test_at = decode_body + .find(test) + .unwrap_or_else(|| panic!("the 1:4 arm test {test:?} for {what} is gone")); + // `decode_rect4_16(` also matches the DEFINITION, which is the + // first occurrence -- the call is the last one. + let call_at = decode_body + .rfind(call) + .unwrap_or_else(|| panic!("{what} is gone -- re-derive the residue's closure")); + let guard_at = decode_body + .find("refuse_invalid_subsize((16, 16)") + .expect("a 16x16-level guard above both 1:4 arms"); + assert!( + guard_at < test_at && test_at < call_at, + "{what}: guard at {guard_at}, 1:4 arm test at {test_at}, dispatch at \ + {call_at}. The guard has to sit ABOVE the 1:4 arm test, or the \ + VERT_4 symbol it refuses has already been dispatched on" + ); + } + // And the inter route really is the only one: `strip16` is built from + // `strip_chroma`, which is `inter_strip_chroma.take()`, so a missing + // writer would silently drop the arm rather than expose it. + assert_eq!( + decode_body.matches("inter_strip_chroma.with(|c| {").count(), + 1, + "inter_strip_chroma gained a second writer -- the inter 1:4 strips can now \ + come from a level whose guard this census has not checked" + ); + } + /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and /// reports "no leaf there" as `None` so the caller can fall back to the diff --git a/lanes/av1subsizesweep.report.md b/lanes/av1subsizesweep.report.md new file mode 100644 index 00000000..f7e09e81 --- /dev/null +++ b/lanes/av1subsizesweep.report.md @@ -0,0 +1,238 @@ +# lane/av1subsizesweep — census of every chroma-plane walk a BLOCK_INVALID subsize can reach + +Base `main` = `e45cc748` ("Merge lane/av1unwritten: refuse the subsize libaom calls corrupt"). +Worktree `~/.cache/wt/av1subsizesweep`, own `CARGO_TARGET_DIR=~/.cache/tgt/subsizesweep`. + +## What the merged lane already covered (not redone) + +`refuse_invalid_subsize` (`decode.rs:21489`) with `PLANE_BLOCK_INVALID_422` / +`PLANE_BLOCK_INVALID_440` transcribed cell-for-cell from `av1_ss_size_lookup` +(`common_data.c`), `partition_subsize_dims` as libaom's `get_partition_subsize` +reduced to dimensions, **11 guard call sites**, the structural test +`every_partition_symbol_resolution_is_guarded_before_it_dispatches`, and the +`EC_AV1_SUBSIZE_GUARD_TRACE` / `EC_AV1_SUBSIZE_ARM_TRACE` coverage artefacts. + +Its named residue: `decode_rect4_16_intrabc`. + +## The hole this lane found: the key-frame 16-level FRAME-EDGE arm + +`decode.rs:37034-37067` (pre-fix numbering) is the **one** partition read in the +file that dispatches on its own symbol instead of resolving it into a `partN` the +level's guard covers. + +| | reads | resolves to | guarded? | +|---|---|---|---| +| 128-root edge (`35551`/`35559`) | `symbol_fixed(&gather(..))` | `PARTITION_SPLIT`/`HORZ`/`VERT` | yes — `refuse_invalid_subsize((128,128), part128)` at `35588` | +| 64-level edge (`36239`/`36256`) | same | same | yes — `(64,64)` guard at `36278` | +| 32-level edge (`36363`/`36383`) | same | same | yes — `(32,32)` guard at `36406` | +| **16-level edge (kf)** | same | **`edge_split`, straight into `decode_leaf_rect`** | **NO — nothing on the path** | +| 16-level edge (inter, `54767`/`54780`) | same | `part16` | yes — `(16,16)` guard at `54799` | + +With `has_cols16 == false` the strip is `BLOCK_8X16`, whose `(1,0)` chroma plane +block is `BLOCK_INVALID` (`av1_ss_size_lookup`, `common_data.c:20`). At 4:2:2 that +is a subsize libaom refuses at `decodeframe.c:1456`, and this decoder walked it +into `decode_leaf_rect` anyway. With `has_cols16 == true` the strip is `16x8` — +`BLOCK_8X16`'s mirror, whose `(1,0)` cell is `BLOCK_8X8` — and **must** keep +decoding. + +Why the merged lane's structural test could not see it: the scan keys on +`dec.symbol(` (line 56698), and this arm reads `dec.symbol_fixed(&gather(..))`. +Every other edge read is either invisible for the same reason or resolves into a +guarded `partN`; only this one both dispatches directly *and* carries an +INVALID shape. + +**Fix** (`decode.rs:37063-37109`): the guard sits on the arm's own path, named by +LEVEL not by a hand-picked shape — the gathered bit resolves to +`PARTITION_HORZ` when the columns are full and `PARTITION_VERT` when they are +not, and `refuse_invalid_subsize((16,16), edge_part, …)` reduces that through the +same `partition_subsize_dims` every other site uses. A `note_subsize_arm` census +line was added alongside, per the merged lane's convention. + +## The named residue: `decode_rect4_16_intrabc` — CLOSED, not guarded a third time + +Its concrete code shape is `decode.rs:18336-18337`: + +```rust +let (cw, ch) = if own_chroma { (bw >> ss_x(fctx), bh >> ss_y(fctx)) } + else { (pw / 2, ph / 2) }; // <- hardcoded both-axes halving +``` + +`own_chroma = own444 || own422`, and `own422 = ss_x == 1 && ss_y == 0 && horz` +(`18317`). A **VERT** strip at `ss (1,0)` is therefore neither `own444` nor +`own422`, falls to the `else`, and derives `pw,ph = (8,16)` → `cw,ch = (4,8)` — +a `BLOCK_4X8` plane block, itself `BLOCK_INVALID` at `(1,0)`. Same for the +`(pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)` origin at `18354`. + +It is dead, and the reason is derived rather than read: + +1. `decode_rect4_16_intrabc` has exactly **one** caller (`decode_rect4_16_strip`, + `18934`). +2. `decode_rect4_16_strip` has exactly **two** (`17595` from `decode_rect4_16`, + `13810` from `decode_intra_rect_in_inter`). +3. `decode_rect4_16` (`36793`) and `decode_intra_rect_in_inter` (`45447`, reached + only when `fctx.inter_strip_chroma` is set — one writer, `55116`) are both + **16x16-level 1:4 arms**, and both sit above a + `refuse_invalid_subsize((16, 16), part16, …)`. +4. `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, and `(4,16)` is + in `PLANE_BLOCK_INVALID_422`. So the guard refuses the **only** shape that + could reach the bad arm. +5. `PARTITION_HORZ_4` gives `(16,4)`, whose `(1,0)` cell is `BLOCK_8X4` and is + legal — so the strip that survives is the one `own422` is written for, and + `refuse_invalid_subsize` does not over-refuse. + +Items 1–5 are asserted in +`every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason` (4 and 5 +derived from the real predicate; 1–3 from counted call sites plus the ordering of +guard < 1:4-arm test < dispatch on each of the two routes). It is closed as +**guarded-at-resolution**, not `unreachable`: the site *is* handable an INVALID +subsize in principle, and what makes it safe is a guard one level up. + +## Census table + +`guard` = the `refuse_invalid_subsize` that covers the walk. "shape@mode" lists the +footprints the walk is handed and the subsampling mode at which libaom marks them +`BLOCK_INVALID`. Offending shapes at 4:2:2 `(1,0)`: **4x8, 8x16, 4x16, 8x32, +16x32, 16x64, 32x64, 64x128**. 4:4:0 `(0,1)` is excluded throughout — libaom +asserts `subsampling_y == 0` when `subsampling_x == 0`, so no frame can select +it. + +| # | site | shapes | offending @mode | guard | mechanism | evidence | +|---|---|---|---|---|---|---| +| 1 | `decode_leaf_rect` **kf 16-edge** (`37067`) | 16x8, **8x16** | 8x16@(1,0) | `refuse_invalid_subsize((16,16), edge_part)` **added this lane** | AtDispatch | census row + ordering assert; mutations A/B red | +| 2 | `decode_rect4_16_intrabc` (`18232`) | 16x4, **4x16** | 4x16@(1,0) | `(16,16)` @ `36472` (kf) / `54799` (inter) | AtResolution | derived VERT_4→(4,16) + caller count, census part (d)/(f) | +| 3 | `decode_rect4_16` (`17552`) | 16x4, 4x16 | 4x16@(1,0) | same `(16,16)` guards | AtResolution | single caller `36793`, under the 1:4 arm | +| 4 | `decode_rect4_16_strip` (`18862`) | 16x4, 4x16 | 4x16@(1,0) | same | AtResolution | callers `17595`, `13810`, both 1:4 | +| 5 | `decode_block_rect` (`15596`) | 32x16, **16x32** | 16x32@(1,0) | `(32,32)` @ `36406` / `54653` | AtResolution | 32-level HORZ/VERT arms | +| 6 | `decode_block_rect4` (`16764`) | 32x8, **8x32** | 8x32@(1,0) | `(32,32)` @ `36406` / `54653` | AtResolution | 32-level HORZ_4/VERT_4 arms | +| 7 | `decode_block_rect64` (`19851`) | 64x16, **16x64** | 16x64@(1,0) | `(64,64)` @ `36278` / `54269` | AtResolution | 64-level 1:4 arms | +| 8 | `decode_block_128rect` (`23921`) | 128x64, **64x128** | 64x128@(1,0) | `(128,128)` @ `35588` / `54032` | AtResolution | 128-root HORZ/VERT + all four AB arms | +| 9 | `decode_rect_split` (`12420`) | 32x16, 16x32, 64x16, 16x64 | all four | inherited from callers 5/7 | AtResolution | 4 call sites, all under 5–8 | +| 10 | `decode_leaf_rect` **AB arms** (`36599`, `36688`, `36737`, `36756`) | 16x8, **8x16** | 8x16@(1,0) | `(16,16)` @ `36472` — `partition_subsize_dims((16,16), VERT_A/B) == (8,16)` | AtResolution | guard is above the AB range, never inside it (merged lane's AB invariant) | +| 11 | `decode_leaf_rect8` (`27733`) | 8x4, **4x8** | 4x8@(1,0) | `(8,8)` @ `36882` / `37179`, plus the redundant inline check at `36904` | AtResolution | both 8x8 resolutions | +| 12 | `decode_inter_sub8_rect2` (`48863`) | 8x4, **4x8** | 4x8@(1,0) | `(8,8)` @ `55211` | AtResolution | inter 8x8 level | +| 13 | `decode_leaf_split4` (`27044`) | 4x4 | none | none needed | unreachable | 4x4's plane block is 4x4 in **every** cell | +| 14 | `decode_inter_sub8_split4` (`46999`) | 4x4 | none | none needed | unreachable | same | +| 15 | `decode_leaf8` (`24413`) | 8x8 | none | none needed | unreachable | 8x8 → 8x8/4x8/4x4, never INVALID | +| 16 | `decode_inter_block8` (`50045`) | 8x8 | none | none needed | unreachable | same | +| 17 | `decode_block` (`22475`) | squares only | none | none needed | unreachable | every square's plane block is valid at **every** selectable mode; the whole BLOCK_INVALID column is rect | +| 18 | `decode_inter_block` (`41372`) | squares only | none | none needed | unreachable | same | +| 19 | `read_sb128_root` (`35493`) | 128x128 root | none itself | own `(128,128)` guard at `35588` | AtResolution | covers rows 5–8 upstream | + +**Rows not closed: none.** Every row is either guarded (1–12, 19) or needs no +guard because the shape is codable at every selectable subsampling mode (13–18). + +## Evidence + +**Guard fires on a live path, and does not over-refuse.** `EC_AV1_SUBSIZE_GUARD_TRACE` +on real `aomenc` 4:2:0 streams of exactly the shape that reaches the arm +(`testsrc2`, widths 40/72/104/136, `h=120`, `--min-partition-size=4 +--max-partition-size=64 --sb-size=64`): + +``` +SUBSIZE_GUARD site=.../decode.rs:37098 bsize=16x16 part=2 codable=true reached=2 +SUBSIZE_ARM site=.../decode.rs:37101 part=2 codable=true reached=2 +``` + +`part=2` is `PARTITION_VERT` — the 8x16 strip, the shape that is INVALID at +4:2:2. At 4:2:0 the guard reports `codable=true`, the frame decodes OK. The guard +is on a live path and refuses nothing it should not. + +**A real aomenc witness for the guard FIRING does not exist, and that is a +property of libaom, not a gap in the sweep.** 45 real 4:2:2 encodes were built +(`--i422`, `testsrc2`, 11 widths × 3 heights at cq 45, plus 12 +`--tune-content=screen --enable-intrabc=1 --enable-palette=1` encodes at cq 20; +widths chosen so the 16-level column is short, heights so it is the *only* short +axis). None reached `37098` at all. The reason is that aomenc's own +`partition_rect_allowed` is gated on the same `av1_ss_size_lookup` table (the +merged lane cites `partition_search.c:3383-3389`), so a conformant encoder +cannot emit a partition whose plane block is `BLOCK_INVALID`. The guard is +therefore a **hostile-stream** guard, in exactly the same class as the merged +lane's own `37171-37177` note ("Not corpus-reachable at ss(1,0) today, so it is +residue rather than live pixels, and it is guarded anyway"). No witness is +claimed. + +**Red-before-green on the new gate** (both mutations against +`every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason`): + +* delete `refuse_invalid_subsize((16,16), edge_part, …)` → RED, "dispatches + `decode_leaf_rect` on an 8x16 strip … with NO `refuse_invalid_subsize` on its path". +* move it **below** the `decode_leaf_rect` call (r5's defect in a new place) → + RED, "sits AFTER the `decode_leaf_rect` it protects -- it can never observe it". + +Restored; both green. + +**The gate caught two errors in my own census before it shipped** — recorded +because they are the class this lane exists to close: + +* it counted 4:4:0 `(0,1)` as a reachable offending mode and flagged `16x4` as + needing a guard. That is the merged lane's r2 mistake reproduced: refusing a + legal 4:2:2 shape by testing a cell no `color_config` can request. Fixed by + restricting the offending set to the selectable modes. +* it flagged `decode_block`/`decode_inter_block` as `AtResolution` when no shape + they walk is ever INVALID (squares only). Reclassified `unreachable`. + +**Named tests.** `cargo check --tests` clean. `cargo test -p ec-av1 --lib -- 422 +sub8 subsize chroma_422` → **27 passed, 0 failed** (52 s), including +`a_real_422_key_frame_and_inter_sequence_decode_pixel_exact`, +`the_pinned_422_corpus_cells_decode_pixel_exact`, +`the_pinned_422_bigblock_witnesses_decode_pixel_exact`, +`the_pinned_422_lossless_inter_witnesses_decode_pixel_exact`, +`the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact`. +The three structural gates pass together. + +**Non-regression on the committed tree.** `cargo test -p ec-av1 --lib -- pixel_exact +byte_exact` → **270 passed, 0 failed** (818 s), on this lane's commit. This is the +over-refusal control at scale: the new guard sits on a live path (measured +reached with `part=2` at 4:2:0 above), and if it refused anything legal these +would go red. + +## Wider sweep — hardcoded chroma halvings, NAMED NOT FIXED (out of charter) + +One wider finding **is inside** the residue and is covered by row 2: +`decode_rect4_16_intrabc`'s `else` arm at `18336-18337` / `18354` — the +`(pw / 2, ph / 2)` halving and the `(pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)` +origin — is a both-axes halving whose predicate (`own444 || own422`) does not +enumerate every reachable `(ss, shape)` cell. It is dead only because row 2's +guard refuses VERT_4 at 4:2:2. If that guard ever moves, this arm becomes the +live defect. + +Outside the charter, named for the owning lanes. Provenance: every row below is +either read by me in the decode spine (rows 1, and the residue's `else` arm +above) or comes from a read-only source sweep run as part of this lane — the +line numbers were confirmed against the worktree, but nothing outside the +decode.rs partition/chroma walk was **reproduced by a probe here**. Rows marked +"not probed" should be re-measured by the lane that takes them. + +| site | what | consequence at 4:2:2 | +|---|---|---| +| `decode.rs:21081` `cfl_ac_q3_at` | `let (cw, ch) = (bw / 2, bh / 2)` + 2×2 luma average | correct today only because `cfl_ac_ss` routes 4:2:2 elsewhere; held by the `cfl_ac_q3_at_hits` 4:2:0-only gate | +| `decode.rs:47516, 47908, 49484, 49930` | `mv_to_q4(, , ss_x(fctx))` — the **Y** axis shifted by `ss_x` | each currently masked by a guard pinning the format to one where `ss_x == ss_y` | +| `decode.rs:43251/43262, 43366` | `chroma_side * chroma_side` sizing in the mu-chroma composed grid, where at `ss (1,0)` the plane rect is `(side/2, side)` and a square `side/2` is too short on rows `>= side/2` | a scout finding from a source read; **not reproduced by a probe in this lane** — the lossless sibling of this path was already repaired to `chroma_stride`, these were not. Needs an owning lane with a 128-root 4:2:2 mu-chunk witness | +| `decode.rs:35700, 53411` | floor-`>>` chroma plane allocators | shape assumption at frame edges; scout finding, not probed here | +| `encode.rs:1674-1687, 1862-1863, 7477/7483, 7928/7934, 8215/8221, 9295-9315` | every chroma plane/stride/crop at `width / 2` with no ss term | correct only because the encoder emits 4:2:0 exclusively; `obmc_plan` (`7362`) passes real `ss_x`/`ss_y` next to a `side / 2` stride, so two conventions meet there | +| `tile.rs:5004-5006` (`fn palette_uv_side`) | `palette_uv_side = (side / 2).max(4)` | 4:2:2/4:4:0 palette map mis-sized | +| `stream.rs:6672, 6773, 17075` + `probe.rs:81` | ffmpeg rawvideo oracle slices chroma at `width * height / 4` | **the dangerous ones**: a future 4:2:2 gate using them compares half the oracle's bytes and passes green. The `_422_depth`/`_444` siblings exist and are correct; the 4:2:0 trio is unguarded against the wrong format | +| `encode.rs:1595-1616` (`Picture::grey`/`check`), `1605`, `1658`, `1852` | every test card's chroma allocated and asserted at `width * height / 4` | the crate's test surface is 4:2:0-sized before any test code runs | +| `decode.rs:59012, 59031, 59284-59304` | test-card chroma + `PlaneBuf` test harness at `width/2`, `height/2` | same | +| `examples/gen_coverage_cells.rs:94-96`, `examples/syntax_census.rs` | quarter-plane chroma arithmetic | same | + +`mc.rs`, `intra.rs`, `transform.rs`, `compound.rs` are clean — plane dims arrive as +parameters. `restoration.rs` and `film_grain.rs` are per-axis and correct. +`motion_field.rs:74`'s `/ 2` is the 8×8 MV-cell grid, not a chroma extent. + +## Not closed, stated plainly + +1. **No aomenc witness proves the new guard FIRES**, because libaom's encoder + cannot emit the symbol (§ Evidence). The red-before-green proof for the guard + is mutation-based, not corpus-based. This is the same limitation the merged + lane's guards carry and is not fixable from this side. +2. **The structural gate is a derived site list, not a proof.** It pins the + mechanism for 19 walks and the guard ordering for the hole, but it cannot see + a walk that is neither named in the census nor reachable through a + `partition_w` read — e.g. a future site fed a block shape from a + non-partition source. The census is a ratchet, not a proof. +3. **`decode_rect4_16_intrabc`'s `else` arm is still wrong in isolation.** It is + closed by reachability, not by construction. Closing it by construction would + mean making the arm `unreachable!("...")` at `ss (1,0) && !horz` — deliberately + not done here, because that would assert a property of the callers from inside + the callee and break the moment the arm gains a legal 4:2:2 VERT_4 use. \ No newline at end of file