diff --git a/crates/ec-av1/fixtures/422_header_edge16_walk.obu b/crates/ec-av1/fixtures/422_header_edge16_walk.obu new file mode 100644 index 0000000000000000000000000000000000000000..bfdfcb705dd034e8ddcfd5e1928f2a7bd7c3871a GIT binary patch literal 128 zcmV-`0Du1q3P1n=L6*PlP|OH2au5UX01!X`FbKfF<^7p{pzfC$wH29Jl)(H*6&L?f zP-6ZO3V?}j#l7_=_DM+@C`RHot```q=#D){g1YmN6W|@=pkD{lr`uEUF)>s2JufSd iC!mAsdFm?3L=6~QA`n*2DsqM*64T+%4XFP>V_v}IpE*nb literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index efdf16f3..531e2c08 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21490,8 +21490,11 @@ const PLANE_BLOCK_INVALID_440: &[(usize, usize)] = &[ /// Whether `av1_ss_size_lookup[(bw, bh)][sx][sy]` is not `BLOCK_INVALID` -- i.e. /// whether libaom lets a subsize of this luma shape have a chroma plane block -/// at this subsampling at all. -fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { +/// at this subsampling at all. `pub(crate)` so a fixture gate in `stream.rs` +/// can assert WHICH shape its pin carries, rather than only that the decode +/// refused -- a refusal gate that cannot name the shape is one decode-site +/// change away from measuring the wrong thing. +pub(crate) fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { match (sx, sy) { (1, 0) => !PLANE_BLOCK_INVALID_422.contains(&(bw, bh)), (0, 1) => !PLANE_BLOCK_INVALID_440.contains(&(bw, bh)), @@ -37233,6 +37236,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:35559/35567), the 64-level ones + // (36247/36264) and the 32-level ones + // (36371/36391) all end in `PARTITION_HORZ` / + // `PARTITION_VERT` / `PARTITION_SPLIT`, which + // the guard after their `match` sees -- the + // inter-frame 16-level edge arms (54777/54790) + // 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) = @@ -56870,6 +56922,57 @@ mod tests { } } } + // r11 (lane-av1subsizesweep): a partition-symbol READ is a `dec.(..)` + // call whose OWN ARGUMENT LIST names a `partition_w[` CDF. That is the + // whole definition, and it is why the read spellings need no hand-list: + // `dec.symbol(..partition_w..)` qualifies, the frame-edge gather's + // `dec.symbol_fixed(&gather(..partition_w..))` qualifies, and + // `dec.debug_state()` does not -- it never names a partition CDF. A third + // spelling is covered the day somebody writes it. + // + // r11's hole was a SPELLING gap, not a shape gap: the old matcher named + // `dec.symbol(` literally, and `dec.symbol(` is not a substring of + // `dec.symbol_fixed(`. So the key-frame 16-level frame-edge arm -- which + // dispatches `decode_leaf_rect` straight off a gathered `edge_split` onto + // a BLOCK_8X16 chroma walk -- was never a site at all. + let is_partition_read = |window: &str| -> bool { + let mut at = 0usize; + while let Some(rel) = window[at..].find("dec.") { + let call = at + rel + "dec.".len(); + at = call; + let name: String = window[call..] + .chars() + .take_while(|c| c.is_ascii_alphanumeric() || *c == '_') + .collect(); + if name.is_empty() { + continue; + } + let Some(open) = window[call + name.len()..].find('(') else { + continue; + }; + let arg_from = call + name.len() + open + 1; + let mut depth = 1usize; + let mut stop = None; + for (i, c) in window[arg_from..].char_indices() { + match c { + '(' => depth += 1, + ')' => { + depth -= 1; + if depth == 0 { + stop = Some(arg_from + i); + break; + } + } + _ => {} + } + } + let Some(stop) = stop else { continue }; + if window[arg_from..stop].contains("partition_w") { + return true; + } + } + false + }; for (n, line) in lines.iter().enumerate() { let t = line.trim_start(); // A doc comment quoting the shape is not a site, and neither is the @@ -56880,7 +56983,9 @@ mod tests { let lo = n.saturating_sub(1); let hi = (n + 2).min(lines.len()); let window = lines[lo..hi].join(" "); - if !window.contains("dec.symbol(") { + // r11: the read test is the DERIVED predicate above, not a spelling + // literal. Naming `dec.symbol(` here is what hid the frame-edge arm. + if !is_partition_read(&window) { continue; } let Some(i) = window.find("partition_w") else { @@ -56915,23 +57020,25 @@ mod tests { continue; } // This binding is followed by the symbol read if the SAME line - // completes `let = dec.symbol(`, or if the next line starts - // the call. That is what separates `let part8 =` from an unrelated - // `let ec_dbg_pre =` two lines above it. + // completes `let = dec.(`, or if the next line + // starts the call. That is what separates `let part8 =` from an + // unrelated `let ec_dbg_pre =` two lines above it. let next = lines.get(cand + 1).copied().unwrap_or(""); - let binds_here = ct.contains("= dec.symbol") || next.contains("dec.symbol("); + let binds_here = ct.contains("= dec.") || next.contains("dec."); if binds_here || cand == n { var = Some(name); break; } } let Some(var) = var else { continue }; - // An edge `gather` binds `b` and is not a resolution: libaom resolves - // those from a two-symbol CDF and the site is guarded at the level's - // own resolution instead. - if var == "b" { - continue; - } + // r11: the edge `gather` reads are SITES now, not skips. r10 skipped + // them on the reasoning that "the site is guarded at the level's own + // resolution instead" -- true for every arm that resolves into a + // `partN`, and FALSE for the one that does not: the key-frame 16-level + // frame-edge arm dispatches `decode_leaf_rect` straight off `edge_split`, + // and `BLOCK_8X16` is BLOCK_INVALID at 4:2:2. Every site therefore has + // to carry a guard for its OWN level between the read and the first + // chroma-walking dispatch after it -- see the per-site check below. sites.push((n, var, level)); } @@ -57194,6 +57301,584 @@ 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() { + let src = include_str!("decode.rs"); + // r2: `decode_body` is hoisted to the top of the test because the per-row + // guard check below needs it BEFORE the walk census it sits under, and a + // reader who has to hunt for a binding is a reader who will not notice + // when it is scoped to the wrong thing. + let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") { + Some(i) => &src[..i], + None => src, + }; + // (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). + // + // r2 (Main's review, and it was right): `AtResolution` used to assert + // only that SOME shape the walk handles is BLOCK_INVALID, which + // restates the libaom table and never mentions a guard -- deleting the + // inter 32-level guard left it green. So a resolution row now CARRIES + // the guard it depends on: `(walk, fn-scope, level)`, and the check + // below looks for `refuse_invalid_subsize((level, level))` inside that + // function and before the walk's first call site in it. A row that + // cannot be checked that way says so with `Prose` instead. + enum Mech { + AtDispatch, + /// Protected by `refuse_invalid_subsize((L, L))` in the named + /// function, above the walk's first call site there. + AtResolution(&'static str, usize), + /// The walk is reached INDIRECTLY -- this row's guard is asserted to + /// exist in `fscope`, and the ordering is asserted by the per-route + /// loop further down (which scopes to the enclosing function and + /// names this walk's real caller chain). Used only where the walk's + /// call site is not in the guard's own function. + AtResolutionVia(&'static str, usize), + Unreachable(&'static str), + } + // The key-frame tile decoder and the inter tile decoder. Every + // resolution guard lives in one of the two, which is what makes "the + // guard for THIS row" a scoped lookup rather than a global one. + const KF: &str = "decode_key_frame_tile_with_cdfs"; + const INTER: &str = "decode_inter_frame_tile_with_cdfs"; + 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::AtResolutionVia(KF, 16), + ), + // ---- 1:4 and 2:1 rect walks, all resolved-symbol guarded -- + ( + "decode_rect4_16", + &[(16, 4), (4, 16)], + Mech::AtResolution(KF, 16), + ), + ( + "decode_rect4_16_strip", + &[(16, 4), (4, 16)], + Mech::AtResolutionVia(KF, 16), + ), + ( + "decode_block_rect", + &[(32, 16), (16, 32)], + Mech::AtResolution(KF, 32), + ), + ( + "decode_block_rect4", + &[(32, 8), (8, 32)], + Mech::AtResolution(KF, 32), + ), + ( + "decode_block_rect64", + &[(64, 16), (16, 64)], + Mech::AtResolution(KF, 64), + ), + // The 128-root guard lives in `read_sb128_root`, the shared + // resolver both tile decoders call -- not in the walker's own + // function. + ( + "decode_block_128rect", + &[(128, 64), (64, 128)], + Mech::AtResolutionVia("read_sb128_root", 128), + ), + // `decode_rect_split` is called from inside decode_block_rect / + // decode_leaf_rect / decode_block_rect4 / decode_block_rect64, none of + // which is the tile decoder -- so the guard it inherits is checked on + // its own callers' rows, not here. + ( + "decode_rect_split", + &[(64, 16), (16, 64), (32, 16), (16, 32)], + Mech::AtResolutionVia(KF, 32), + ), + ( + "decode_leaf_rect", + &[(16, 8), (8, 16)], + Mech::AtResolution(KF, 16), + ), + // ---- the INTER-side rect walks ----------------------------- + // + // r2: without these three rows the inter 32- and 64-level guards + // were claimed by NOTHING, and deleting either left the census + // green. They are load-bearing -- `decode_intra_rect_in_inter` + // dispatches `decode_block_rect4` on 32x8/8x32 (8x32 is + // BLOCK_INVALID at 4:2:2) and `decode_block_rect64` on + // 64x16/16x64 (16x64 likewise) -- so each gets its own row naming + // the guard that stands in front of it. + // + // These are `AtResolutionVia`, not `AtResolution`: the walk is + // dispatched from `decode_intra_rect_in_inter`, a helper, not from + // the tile decoder the guard lives in. The check is therefore guard + // EXISTENCE in that decoder -- which is what reds when the guard + // is deleted -- and the linkage is stated here rather than derived. + ( + "decode_block_rect4[inter]", + &[(32, 8), (8, 32)], + Mech::AtResolutionVia(INTER, 32), + ), + ( + "decode_block_rect64[inter]", + &[(64, 16), (16, 64)], + Mech::AtResolutionVia(INTER, 64), + ), + ( + "decode_intra_rect_in_inter", + &[(16, 8), (8, 16), (16, 4), (4, 16)], + Mech::AtResolutionVia(INTER, 16), + ), + // ---- 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(KF, 8), + ), + ( + "decode_inter_sub8_rect2", + &[(8, 4), (4, 8)], + Mech::AtResolution(INTER, 8), + ), + ( + "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. + 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})" + ); + } + } + // r2: the guard THIS row depends on, scoped to the function it + // lives in and ordered before the walk's first call there. + // Deleting that one guard -- and only that one -- reds this row, + // which is what r2's review showed the previous version could + // not do. + Mech::AtResolution(fscope, level) => { + 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" + ); + let fstart = decode_body + .find(&format!("\nfn {fscope}(")) + .or_else(|| decode_body.find(&format!("\npub(crate) fn {fscope}("))) + .or_else(|| decode_body.find(&format!("\npub fn {fscope}("))) + .unwrap_or_else(|| { + panic!("the census names `{fscope}`, which is not a function here") + }); + let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| { + decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i) + }) + .min() + .unwrap_or(decode_body.len()); + let body = &decode_body[fstart..fend]; + let guard = format!("refuse_invalid_subsize(({level}, {level})"); + let gpos = body.find(&guard).unwrap_or_else(|| { + panic!( + "{walk} claims refuse_invalid_subsize(({level}, {level})) guards it, \ + but there is NO such guard in `{fscope}` -- the row's mechanism is \ + prose, not a check; re-derive it or mark the row Prose" + ) + }); + let call = body.find(&format!("{name}(")).unwrap_or_else(|| { + panic!( + "{walk} has no call site inside `{fscope}` to order the guard against" + ) + }); + assert!( + gpos < call, + "{walk}: in `{fscope}` the ({level}, {level}) guard is at {gpos} and the \ + walk is dispatched at {call} -- a guard BELOW the dispatch can never \ + observe it" + ); + } + Mech::AtResolutionVia(fscope, level) => { + assert!( + !offending.is_empty(), + "{walk} is listed AtResolutionVia but no shape it walks is \ + BLOCK_INVALID" + ); + let fstart = decode_body + .find(&format!("\nfn {fscope}(")) + .or_else(|| decode_body.find(&format!("\npub(crate) fn {fscope}("))) + .or_else(|| decode_body.find(&format!("\npub fn {fscope}("))) + .unwrap_or_else(|| { + panic!("the census names `{fscope}`, which is not a function here") + }); + let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| { + decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i) + }) + .min() + .unwrap_or(decode_body.len()); + assert!( + decode_body[fstart..fend] + .contains(&format!("refuse_invalid_subsize(({level}, {level})")), + "{walk} claims refuse_invalid_subsize(({level}, {level})) in `{fscope}` \ + guards it, but there is NO such guard there" + ); + } + 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). + 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")); + // r2 (Main's review, and it was right): the guard search is SCOPED + // to the anchor's own enclosing function. `find()` over the whole + // decode body returns the FIRST `refuse_invalid_subsize((16, 16)` -- + // the KEY-FRAME one -- so the inter pair's comparison was satisfied + // by a guard three quarters of the file away, and deleting the inter + // 16-level guard left this test green. Both routes live in + // different `fn` bodies (`decode_key_frame_tile_with_cdfs` and the + // inter tile decoder), so the enclosing function is the scope that + // tells the two apart. + let fn_scope = |at: usize| -> std::ops::Range { + let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| decode_body[..at].rfind(pat)) + .max() + .unwrap_or(0); + let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "] + .iter() + .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i)) + .min() + .unwrap_or(decode_body.len()); + head..tail + }; + let scope = fn_scope(test_at); + let guard_at = decode_body[scope.clone()] + .find("refuse_invalid_subsize((16, 16)") + .map(|i| scope.start + i) + .unwrap_or_else(|| { + panic!( + "{what}: there is NO refuse_invalid_subsize((16, 16)) in the function \ + enclosing the 1:4 arm test -- so nothing refuses the VERT_4 symbol \ + this arm dispatches on, and decode_rect4_16_intrabc's closure is gone" + ) + }); + assert!( + guard_at < test_at && test_at < call_at, + "{what}: guard at {guard_at} (function scope {scope:?}), 1:4 arm test at \ + {test_at}, dispatch at {call_at}. The guard has to sit ABOVE the 1:4 arm \ + test INSIDE THE SAME FUNCTION, or the VERT_4 symbol it refuses has already \ + been dispatched on" + ); + assert!( + scope.contains(&guard_at) && scope.contains(&test_at) && scope.contains(&call_at), + "{what}: guard, 1:4 test and dispatch must share one enclosing function" + ); + } + // 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/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 37626b0d..f5090c4e 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2939,6 +2939,82 @@ pub(crate) mod tests { ); } + /// lane-av1subsizesweep: the FRAME-EDGE walk of a BLOCK_INVALID subsize, + /// pinned. This is the one install site the partition-symbol guards missed, + /// and the sibling pin above cannot see it -- that pin's 8x16 comes from a + /// 16x16-level `PARTITION_VERT_B` (an interior AB strip, refused at + /// decode.rs:36472), while this pin's comes from the key-frame 16-level + /// FRAME-EDGE arm, which is not a `dec.symbol(` site at all: it reads one + /// gathered bit with `dec.symbol_fixed(&gather(..))` and dispatches + /// `decode_leaf_rect` straight off it. + /// + /// `422_header_edge16_walk.obu` (128 bytes, sha256 + /// `e8ab2bb229896f796cdec4d2cb383b41f057ef8d364da30f160a3f55a452657f`, + /// fnv1a64 `0xcfa2394ebe1f7764`) is a 4:2:2 sequence header over a 4:2:0 + /// key frame's tile, at 88x64. Width 88 is 8 mod 16, so the last 16x16 + /// column block is COLUMN-short and the frame-edge arm fires; height 64 is + /// 16-aligned, so the ROW is not short and the both-cut arm is not taken. + /// The gathered bit names `PARTITION_VERT`, so the strip is `BLOCK_8X16`. + /// + /// libaom's own verdict, which is the rule this pin pins: + /// + /// ```text + /// $ aomdec --rawvideo -o /dev/null fixtures/422_header_edge16_walk.obu + /// Warning: Failed to decode frame 1: Corrupt frame detected + /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode + /// ``` + /// + /// What makes this pin different from every other refusal gate in this file + /// is that the 8x16 is the ONLY offending subsize in the stream. Measured + /// over a 260-candidate sweep (4 card textures x 5 quantizers x 13 declared + /// widths), this is the one candidate whose decode with the guard removed + /// SUCCEEDS: with the `refuse_invalid_subsize` at decode.rs:37098 deleted, + /// this decoder returned a full 88x64 picture where libaom refuses the + /// frame. So the guard is not a redundant second refusal here -- it is the + /// only thing between a corrupt frame and a plausible-looking decode. + #[test] + fn a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused() { + const NAME: &str = + "a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused"; + let _gate_lock = lock_gate_counters(); + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures") + .join("422_header_edge16_walk.obu"); + let pinned = read_pin(&path, 128, 0xcfa2394ebe1f7764, NAME); + // The shape must be the one this lane's arm carries: if the pin ever + // stops being an 8x16 strip the refusal is coming from somewhere else + // and this gate is measuring the wrong thing. + assert!( + !crate::decode::chroma_plane_block_codable(8, 16, 1, 0), + "{NAME}: BLOCK_8X16 must be BLOCK_INVALID at 4:2:2 -- this gate's whole \ + subject is `av1_ss_size_lookup[BLOCK_8X16][1][0] == BLOCK_INVALID`" + ); + assert!( + crate::decode::chroma_plane_block_codable(16, 8, 1, 0), + "{NAME}: the 16x8 mirror MUST stay legal at 4:2:2 (BLOCK_8X8) -- it is what \ + keeps the new guard from refusing the sibling arm's strip" + ); + let err = decode_stream(&pinned) + .err() + .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); + let msg = err.to_string(); + assert!( + msg.contains("invalid with this subsampling mode"), + "{NAME}: the refusal must name libaom's rule (its own wording), got: {msg}" + ); + // Positive control: a genuine 4:2:2 stream must still decode, so this + // gate cannot pass by refusing everything. + let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures") + .join("422_key_64x64.obu"); + let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) + .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); + assert!( + !ok.is_empty(), + "{NAME}: the 4:2:2 control decoded no frames" + ); + } + /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned /// as fixtures (`git add -f`; `fixtures/` is gitignored). /// diff --git a/lanes/av1subsizesweep.report.md b/lanes/av1subsizesweep.report.md new file mode 100644 index 00000000..2c3924e9 --- /dev/null +++ b/lanes/av1subsizesweep.report.md @@ -0,0 +1,279 @@ +# 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`. + +## Headline: the find came from censusing WALK sites, not SYMBOL sites + +The merged lane's gate enumerates partition-**symbol** sites. This lane enumerates +chroma-plane **walk** sites — every `decode_*` that reconstructs chroma from a +block's luma extent, with the footprints its dispatch can hand it — and that +reframing is what found the hole. A symbol-site census cannot see a subsize that +arrives without a partition symbol at all, and it cannot see a subsize that +arrives through a *differently spelled* symbol read. + +Concretely: the key-frame 16-level **frame-edge** arm reads one gathered bit with +`dec.symbol_fixed(&gather(..))` and dispatches `decode_leaf_rect` **directly** on +it. The merged scan's read test was the literal `dec.symbol(`, and +`dec.symbol(` is not a substring of `dec.symbol_fixed(`. Every sibling edge arm +resolves into a `partN` the level's guard sees; this one did not. + +## The hole, and the fix + +| | reads | resolves to | guarded before? | +|---|---|---|---| +| 128-root edge (`35559`/`35567`) | `symbol_fixed(&gather(..))` | `SPLIT`/`HORZ`/`VERT` | yes — `refuse_invalid_subsize((128,128), part128)` at `35596` | +| 64-level edge (`36247`/`36264`) | same | same | yes — `(64,64)` at `36286` | +| 32-level edge (`36371`/`36391`) | same | same | yes — `(32,32)` at `36414` | +| **16-level edge (key frame, `37043`/`37048`)** | same | **`edge_split`, straight into `decode_leaf_rect`** | **NO — nothing on the path** | +| 16-level edge (inter, `54777`/`54790`) | same | `part16` | yes — `(16,16)` at `54809` | + +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 this +walked a subsize libaom refuses at `decodeframe.c:1456`. With `has_cols16 == true` +the strip is `16x8` — `BLOCK_8X16`'s mirror, whose `(1,0)` cell is `BLOCK_8X8` — +and **must** keep decoding. + +**Fix** (`decode.rs:37101-37119`): the guard sits on the arm's own path and names +the LEVEL, not a 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. + +### Reachability, stated separately from the guard's correctness + +There **is** a witness, and it is the only offending subsize in its stream. +`crates/ec-av1/fixtures/422_header_edge16_walk.obu` (128 bytes, sha256 +`e8ab2bb229896f796cdec4d2cb383b41f057ef8d364da30f160a3f55a452657f`, fnv1a64 +`0xcfa2394ebe1f7764`) is a 4:2:2 sequence header over a 4:2:0 key frame's tile at +88x64. Width 88 is 8 mod 16 → the last 16x16 column block is column-short, so the +frame-edge arm fires; height 64 is 16-aligned, so the row is not short and the +both-cut arm is not taken. The gathered bit names `PARTITION_VERT`, so the strip +is `BLOCK_8X16`. + +libaom's own verdict: + +```text +$ aomdec --rawvideo -o /dev/null fixtures/422_header_edge16_walk.obu +Warning: Failed to decode frame 1: Corrupt frame detected +Warning: Additional information: Block size 8x16 invalid with this subsampling mode +``` + +The three-way measurement, which is the part that matters: + +| build | this decoder | +|---|---| +| with the guard | REFUSED, naming libaom's rule — agrees with `aomdec` | +| **guard deleted** | **`OK: 1 frames decoded, 88x64`** — a full picture from a frame libaom calls corrupt | +| libaom | refuses | + +So the guard is load-bearing, not a redundant second refusal, and the gate +`a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused` +reds when the guard is deleted (verified). + +**Severity: a false-accept, not a pixel divergence.** libaom refuses the whole +frame, so there is no "correct" pixel output to diverge from; the defect is that we +returned plausible-looking pixels for a corrupt frame. No legal 4:2:2 stream is +affected — the shape only reaches stream data through a hostile or mismatched +header, which is the same exposure the merged lane's guards already carry. + +**The earlier "no witness" claim in this lane was wrong, and so was its +explanation.** The first sweep (45 aomenc-encoded 4:2:2 streams) never reached the +arm, and I attributed that to `partition_rect_allowed`. That mechanism governs the +encoder's partition *search*; this arm's partition comes from a single gathered +bit after a frame-edge geometry test, so `partition_rect_allowed` does not explain +it — the real reason aomenc never produced a witness is **not known**. The +witness exists, but it had to be built from this crate's own encoder with a +**declared** width (`encode_key_frame_at_size`, the `gen_coverage_cells.rs` cell-2 +construction) and then re-headered, because aomenc rounds the coded size to even +and never declares 88. + +## The named residue: `decode_rect4_16_intrabc` — CLOSED, not guarded a third time + +Its concrete code shape is `decode.rs:18334-18337`: + +```rust +let (cw, ch) = if own_chroma { (bw >> ss_x(fctx), bh >> ss_y(fctx)) } + else { (pw / 2, ph / 2) }; // both axes halved +``` + +`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` (`36801`) and `decode_intra_rect_in_inter` (`45457`, reached only when `fctx.inter_strip_chroma` is set — one writer, `55126`) are both **16x16-level 1:4 arms**, each 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`. 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. + +Classified **guarded-at-resolution**, not `unreachable`: the site *is* handable an +INVALID subsize in principle, and a guard one level up is what makes it safe. + +## Census table + +`guard` = the `refuse_invalid_subsize` that covers the walk. 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's `color_config` asserts +`subsampling_y == 0` when `subsampling_x == 0`, so no frame can select it. + +| # | site | shapes | offending @mode | guard | mechanism | checked by | +|---|---|---|---|---|---|---| +| 1 | `decode_leaf_rect` kf 16-edge (`37124`) | 16x8, **8x16** | 8x16@(1,0) | `(16,16)` `edge_part` **added this lane**, `37106` | AtDispatch | census ordering + the pinned fixture | +| 2 | `decode_rect4_16_intrabc` (`18232`) | 16x4, **4x16** | 4x16@(1,0) | `(16,16)` `36480` kf / `54809` inter | AtResolutionVia | derived VERT_4→(4,16), per-route ordering loop | +| 3 | `decode_rect4_16` (`17552`) | 16x4, 4x16 | 4x16@(1,0) | `(16,16)` `36480` | AtResolution | row-scoped guard + ordering | +| 4 | `decode_rect4_16_strip` (`18862`) | 16x4, 4x16 | 4x16@(1,0) | `(16,16)` `36480` | AtResolutionVia | guard-in-scope + per-route loop | +| 5 | `decode_block_rect` (`15596`) | 32x16, **16x32** | 16x32@(1,0) | `(32,32)` `36414` / `54663` | AtResolution | row-scoped guard + ordering | +| 6 | `decode_block_rect4` (`16764`) | 32x8, **8x32** | 8x32@(1,0) | `(32,32)` `36414` | AtResolution | row-scoped guard + ordering | +| 7 | `decode_block_rect4`[inter] | 32x8, **8x32** | 8x32@(1,0) | `(32,32)` `54663` | AtResolutionVia | guard-in-scope in the inter decoder | +| 8 | `decode_block_rect64` (`19851`) | 64x16, **16x64** | 16x64@(1,0) | `(64,64)` `36286` | AtResolution | row-scoped guard + ordering | +| 9 | `decode_block_rect64`[inter] | 64x16, **16x64** | 16x64@(1,0) | `(64,64)` `54279` | AtResolutionVia | guard-in-scope in the inter decoder | +| 10 | `decode_intra_rect_in_inter` (`13761`) | 16x8, **8x16**, 16x4, **4x16** | all four | `(16,16)` `54809` | AtResolutionVia | guard-in-scope + per-route loop | +| 11 | `decode_block_128rect` (`23929`) | 128x64, **64x128** | 64x128@(1,0) | `(128,128)` `35596` in `read_sb128_root` | AtResolutionVia | guard-in-scope | +| 12 | `decode_rect_split` (`12420`) | 32x16, 16x32, 64x16, 16x64 | all four | inherits from rows 5/7/8/9 | AtResolutionVia | guard-in-scope | +| 13 | `decode_leaf_rect` AB arms (`36599`, `36688`, `36737`, `36756`) | 16x8, **8x16** | 8x16@(1,0) | `(16,16)` `36480` — `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) | +| 14 | `decode_leaf_rect8` (`27741`) | 8x4, **4x8** | 4x8@(1,0) | `(8,8)` `36890` / `37189`, plus the inline check at `36912` | AtResolution | row-scoped guard + ordering | +| 15 | `decode_inter_sub8_rect2` (`48920`) | 8x4, **4x8** | 4x8@(1,0) | `(8,8)` `55221` | AtResolution | row-scoped guard + ordering | +| 16 | `decode_leaf_split4` (`27052`) | 4x4 | none | none needed | unreachable | offending set asserted empty | +| 17 | `decode_inter_sub8_split4` (`47056`) | 4x4 | none | none needed | unreachable | offending set asserted empty | +| 18 | `decode_leaf8` (`24421`), `decode_inter_block8` (`50102`) | 8x8 | none | none needed | unreachable | offending set asserted empty | +| 19 | `decode_block` (`22483`), `decode_inter_block` (`41429`) | squares only | none | none needed | unreachable | every square's plane block is valid at every selectable mode; the whole BLOCK_INVALID column is rect | + +**Rows not closed: none.** Every row is guarded (1–15) or needs no guard because +the shape is codable at every selectable subsampling mode (16–19). + +## The merged lane's matcher gap, widened (r11) + +Its site list was incomplete **for a spelling, not for a shape**, so it would miss +the next differently-spelled read the same way. The read test is now derived: + +> a partition-symbol READ is a `dec.(..)` call whose **own argument list** +> names a `partition_w[` CDF. + +That is the whole definition and it needs no hand-list. `dec.symbol(..partition_w..)` +qualifies; the frame-edge gather's `dec.symbol_fixed(&gather(..partition_w..))` +qualifies; `dec.debug_state()` does not — it never names a partition CDF. A third +spelling is covered the day somebody writes it. The `var == "b"` skip is gone too: +edge reads are **sites** now, and instead of being skipped they must carry a guard +for their own level before the first chroma-walking dispatch that follows them. + +**A limitation, stated rather than hidden:** the definition is syntactic. A read +that reaches a `partition_w` CDF through a helper whose argument list does not +mention the CDF name would not be enumerated. There is no such call in this file +today, and the census's `AtDispatch` row covers the arm this gap actually hid. + +## Evidence + +### The widening bites, and so does every guard the census claims + +Per-guard deletion, one at a time, by line number, against the census alone: + +| deleted | census | +|---|---| +| 35596 — 128-root (`read_sb128_root`) | RED — "NO such guard there" | +| 36286 — kf 64x64 | RED — "NO such guard in `decode_key_frame_tile_with_cdfs`" | +| 36414 — kf 32x32 | RED — same, naming `decode_block_rect` | +| 36472 — kf 16x16 | RED — ordering ("guard BELOW the dispatch") | +| 36890 — kf 8x8 (first) | RED — ordering, naming `decode_leaf_rect8` | +| 37106 — kf 16-level frame-edge arm | RED — "sits AFTER the `decode_leaf_rect` it protects" | +| 37106 — same guard, moved below the dispatch | RED — the r5 defect in a new place | +| 54279 — inter 64x64 | RED — names `decode_block_rect64[inter]` | +| 54663 — inter 32x32 | RED — names `decode_block_rect4[inter]` | +| 54809 — inter 16x16 | RED — names `decode_intra_rect_in_inter` | +| 55221 — inter 8x8 | RED — names `decode_inter_sub8_rect2` | + +**Two guards are claimed by LEVEL, not by site**, and the census stays green when +they are deleted — stated here rather than papered over: + +* **37189** — the key-frame 8x8 **second** resolution (the frame-edge straddle loop). +* **54042** — the inter decoder's own 128-root guard (the row claims the shared one in `read_sb128_root`). + +Both are caught by the merged scan's resolution-count cross-check +(`the decode body has 12 partition resolutions but only 11 guard sites`). A +per-site row for each would pin them individually; that is the obvious next +ratchet step and it is not in this lane. + +### Over-refusal control + +`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:37106 bsize=16x16 part=2 codable=true reached=2 +SUBSIZE_ARM site=.../decode.rs:37109 part=2 codable=true reached=2 +``` + +`part=2` is `PARTITION_VERT` — the 8x16 strip, INVALID at 4:2:2. At 4:2:0 the +guard reports `codable=true` and the frame decodes: the guard is on a live path and +refuses nothing it should not. + +### Tests + +* `cargo check --tests` clean. +* `cargo test -p ec-av1 --lib -- 422 sub8 subsize chroma_422` — **27 passed, 0 failed** (52 s), including the pinned 4:2:2 corpus, bigblock, lossless-inter and intrabc-sb128 pixel-exactness gates. +* `cargo test -p ec-av1 --lib -- pixel_exact byte_exact` — **270 passed, 0 failed** (818 s). The over-refusal control at scale: if the new guard refused anything legal these would go red. +* The three structural gates pass together, plus the two hostile-pin refusal gates. + +## Wider sweep — hardcoded chroma halvings, NAMED NOT FIXED (out of charter) + +One finding **is** inside the residue and is covered by row 2: +`decode_rect4_16_intrabc`'s `else` arm at `18334-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. Dead only because row 2's guard +refuses VERT_4 at 4:2:2. If that guard moves, this arm becomes the live defect. + +Outside the charter, named for the owning lanes. Provenance: line numbers +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` | `(bw / 2, bh / 2)` + 2×2 luma average | correct 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 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; at `ss (1,0)` the plane rect is `(side/2, side)` and a square `side/2` is too short on rows `>= side/2` | not probed; the lossless sibling was repaired to `chroma_stride`, these were not. Needs an owning lane with a 128-root 4:2:2 mu-chunk witness | +| `decode.rs:35708, 53419` | floor-`>>` chroma plane allocators | shape assumption at frame edges; not probed | +| `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`) | `(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:58989, 59008, 59261-59281` | 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. + +## Housekeeping + +An early edit of this lane leaked into the primary checkout through a relative +path and was reverted before any commit (`git checkout --` on the one file it +touched); a second leak, the `stream.rs` gate, was caught the same way. The +primary checkout is clean at every commit on this branch, and no commit here +contains either hunk. + +## Not closed, stated plainly + +1. **The structural gate is a derived site list, not a proof.** It pins the + mechanism for 19 walks and 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. +2. **Two guards are level-claimed, not site-claimed** (kf 8x8 second resolution, + inter 128-root). The merged scan's count cross-check is what reds them. +3. **The read-spelling derivation is syntactic.** A read reaching a `partition_w` + CDF through a helper that does not mention the CDF name would not be enumerated. +4. **`decode_rect4_16_intrabc`'s `else` arm is still wrong in isolation** — closed + by reachability, not construction. Closing it by construction would mean + asserting a caller property from inside the callee, and breaking the moment the + arm gains a legal 4:2:2 VERT_4 use. +5. **Why aomenc never produces this shape is unknown.** The witness had to be + built from this crate's own encoder with a declared width. See the reachability + section — the earlier `partition_rect_allowed` explanation was wrong. \ No newline at end of file