forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1unwritten: refuse the subsize libaom calls corrupt

Browse files at this commit

8d3f38abeea1d61ad83a7edaeec8c897293139e8Ahmet Kaan GümüşParent: f91abd51feddfc
440_request_is_422.obu is a 4:2:2 sequence header over a 4:2:0 tile, so its
partition symbols name subsizes (8x16 among them) with no chroma plane block at
ss (1,0). libaom refuses that at decodeframe.c:1445-1458 with
"Block size %dx%d invalid with this subsampling mode", and aomdec refuses the
file outright; libaom's own encoder never emits such a shape either
(partition_search.c:3383-3389 gates partition_rect_allowed with the same table).
This decoder walked those subsizes anyway, and its output for the witness
depends on unwritten plane content.

The fix mirrors libaom's check instead of inventing a geometry: the two
BLOCK_INVALID cell lists of av1_ss_size_lookup are transcribed verbatim, a
partition symbol is resolved to its subsize and refused there when that subsize
has no chroma plane block at the frame's subsampling, and the refusal is a
returned error naming the shape (a partition symbol is stream data, so hostile
bytes reach it). Eleven guard sites cover the ten partition-symbol resolutions;
the eleventh is the redundant one behind the shared read_sb128_root.

Two instruments make the coverage checkable rather than asserted:
EC_AV1_SUBSIZE_GUARD_TRACE records what each guard site sees over the corpus
(exactly one codable=false observation corpus-wide, the key-frame 16-level
VERT_B), and EC_AV1_SUBSIZE_ARM_TRACE does the same for unguarded dispatch arms.
A structural test derives its site list from the bindings in this file, requires
a guard for each resolution's own level, and asserts that no guard sits inside a
PARTITION_HORZ_A..=PARTITION_VERT_B arm, which can only carry values 4..=7.

Verified over four refutation passes. The decode path: no guard fires on a legal
shape (all 20 genuine 4:2:2 fixtures decode, and partition_subsize_dims matches
subsize_lookup cell for cell); 127-fixture sweep, the witness is the only row
that changes and nothing newly refuses; the witness refuses while 422_key_64x64
still decodes. The checker itself failed three times and each failure is in the
report: a four-cell hand-picked predicate that refused a legal 16x4 at 4:2:2,
three guards placed inside arms that could not see the offending value, and an
AB-arm tracker that self-cleared on the arm's own brace line.

Residue, stated: decode_rect4_16_intrabc is out of scope and unaudited, and the
guard-vs-resolution cross-check is level presence plus a 220-line window, not a
dispatch bound.
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
@@ -29,6 +29,11 @@ fn main() {
29 }29 }
30 };30 };
31 let report = || {31 let report = || {
32+ // lane-av1unwritten r6: the subsize-guard coverage table (per call
33+ // site, per partition value, reached vs fired). Env-gated
34+ // (`EC_AV1_SUBSIZE_GUARD_TRACE`), so it is empty unless asked for.
35+ ec_av1::decode::dump_subsize_guard_scan();
36+ ec_av1::decode::dump_subsize_arm_scan();
32 // The census below reads ec-av1's gate counters; without the crate's37 // The census below reads ec-av1's gate counters; without the crate's
33 // `gate-counters` feature every one of them is compiled out and reads 0.38 // `gate-counters` feature every one of them is compiled out and reads 0.
34 if !cfg!(feature = "gate-counters") {39 if !cfg!(feature = "gate-counters") {
crates/ec-av1/src/decode.rsmodified+984 -1
@@ -21235,6 +21235,383 @@ fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
21235 }21235 }
21236 }21236 }
21237 21237
21238+/// Enabled by `EC_AV1_PLANE_SENTINEL` (there is no separate flag for it): at
21239+/// each frame's pre-deblock point, print an
21240+/// EXACT census of the samples the tile walk never wrote -- with
21241+/// it, every plane still holding [`PLANE_SENTINEL`] at
21242+/// this point is a sample no block reconstructed, and no legal sample can
21243+/// equal `0xDEAD` (reconstruction clamps to `(1 << bit_depth) - 1`).
21244+///
21245+/// This is the shipped form of the four-line temporary scan the
21246+/// `lane/av1422seed` census used: it replaces a wrong-sample diff (which says
21247+/// where the OUTPUT is wrong, not whether the block was written at all) with a
21248+/// direct count plus the coordinates of every hole, grouped into per-row
21249+/// spans so a large hole stays readable. Scans each plane over its own
21250+/// `true_width` x `true_height` extent: past that is the padded coding
21251+/// surface's invented tail, which no decoder ever reads.
21252+fn census_unwritten(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
21253+ if !plane_sentinel_on() {
21254+ return;
21255+ }
21256+ let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst);
21257+ for (name, p) in [("Y", y), ("U", u), ("V", v)] {
21258+ let (w, h) = (p.true_width.min(p.width), p.true_height);
21259+ let mut total = 0usize;
21260+ let mut spans: Vec<(usize, usize, usize)> = Vec::new();
21261+ for row in 0..h {
21262+ let mut run: Option<(usize, usize)> = None;
21263+ for col in 0..w {
21264+ if p.data[row * p.width + col] == PLANE_SENTINEL {
21265+ total += 1;
21266+ run = Some(match run {
21267+ None => (col, col),
21268+ Some((a, _)) => (a, col),
21269+ });
21270+ }
21271+ if run.is_some()
21272+ && (col + 1 == w || p.data[row * p.width + col + 1] != PLANE_SENTINEL)
21273+ {
21274+ let (a, b) = run.take().expect("a run is open here");
21275+ spans.push((row, a, b));
21276+ }
21277+ }
21278+ }
21279+ UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst);
21280+ CENSUS_SCANNED.fetch_add(w * h, std::sync::atomic::Ordering::SeqCst);
21281+ if total == 0 {
21282+ eprintln!("SENTINEL_CENSUS idx={idx} plane={name} extent={w}x{h} unwritten=0");
21283+ continue;
21284+ }
21285+ let body: Vec<String> = spans
21286+ .iter()
21287+ .map(|&(r, a, b)| format!("y{r} x{a}..={b}"))
21288+ .collect();
21289+ eprintln!(
21290+ "SENTINEL_CENSUS idx={idx} plane={name} extent={w}x{h} unwritten={total} \
21291+ spans={}: {}",
21292+ spans.len(),
21293+ body.join(" ")
21294+ );
21295+ }
21296+}
21297+
21298+/// Unwritten samples [`census_unwritten`] has counted since the last
21299+/// [`take_unwritten_samples`] -- process-global (not thread-local) because the
21300+/// gate reads it after the decode, from a different thread than the one that
21301+/// scanned the plane.
21302+static UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
21303+
21304+/// Turns [`PLANE_SENTINEL`] filling on for the CALLING thread, independently
21305+/// of `EC_AV1_PLANE_SENTINEL`. A gate cannot set a process-constant env var
21306+/// (see [`crate::envflags`]), and the census is the only honest way to ask
21307+/// "did the tile walk write every sample it was handed" -- a wrong-sample diff
21308+/// cannot tell an unwritten sample from a mis-predicted one.
21309+pub fn set_plane_sentinel(on: bool) {
21310+ PLANE_SENTINEL_ON.with(|c| c.set(on));
21311+}
21312+
21313+/// Reads and clears [`UNWRITTEN_SAMPLES`]: the number of samples the decode
21314+/// just handed to the tile walk never wrote, summed over every frame and
21315+/// plane. Zero is the only acceptable answer for a decoder whose output must
21316+/// not depend on its allocator.
21317+pub fn take_unwritten_samples() -> usize {
21318+ UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
21319+}
21320+
21321+/// Samples [`census_unwritten`] has looked at since the last
21322+/// [`take_census_scanned`]. A gate that only asserts
21323+/// [`take_unwritten_samples`] == 0 passes on a decode that never scanned
21324+/// anything, so it reads THIS too: a census that scanned nothing has proved
21325+/// nothing.
21326+static CENSUS_SCANNED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
21327+
21328+/// Reads and clears [`CENSUS_SCANNED`]; see [`take_unwritten_samples`] for the
21329+/// pairing.
21330+pub fn take_census_scanned() -> usize {
21331+ CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst)
21332+}
21333+
21334+thread_local! {
21335+ /// The [`set_plane_sentinel`] override; `EC_AV1_PLANE_SENTINEL` is the
21336+ /// process-wide default.
21337+ static PLANE_SENTINEL_ON: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
21338+}
21339+
21340+/// Whether freshly allocated planes are [`PLANE_SENTINEL`]-filled.
21341+fn plane_sentinel_on() -> bool {
21342+ crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL")
21343+ || PLANE_SENTINEL_ON.with(std::cell::Cell::get)
21344+}
21345+
21346+/// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this
21347+/// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] !=
21348+/// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every
21349+/// subsize before descending into it:
21350+///
21351+/// ```c
21352+/// if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) ==
21353+/// BLOCK_INVALID)
21354+/// aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
21355+/// "Block size %dx%d invalid with this subsampling mode", ...);
21356+/// ```
21357+/// (`decodeframe.c:1449-1458`).
21358+///
21359+/// So at 4:2:2 a 4x8, 8x16, 16x32, 32x64, 64x128, 4x16, 8x32 or 16x64
21360+/// subsize is NOT DECODABLE: libaom rejects the frame outright and never
21361+/// reaches a transform size for it. This decoder walked those subsizes anyway,
21362+/// covering a chroma plane block whose shape did not match the luma one.
21363+///
21364+/// Two independent facts justify refusing rather than decoding, and NEITHER is
21365+/// this lane's pixel measurement:
21366+///
21367+/// 1. libaom REFUSES the shape. `aomdec` on the pinned
21368+/// `440_request_is_422.obu` (a 4:2:2 sequence header over a 4:2:0 key
21369+/// frame's tile) prints `Failed to decode frame 1: Corrupt frame detected`
21370+/// and `Block size 8x16 invalid with this subsampling mode`.
21371+/// 2. libaom's own ENCODER never emits it: `partition_search.c:3383-3389`
21372+/// gates `partition_rect_allowed` on this same table, so no conformant
21373+/// 4:2:2 stream can contain the shape and the refusal cannot reject legal
21374+/// content.
21375+///
21376+/// What led here was the observation that this decoder's output for such a
21377+/// witness DEPENDS ON UNWRITTEN PLANE CONTENT. Measured on `8d6998d7` by two
21378+/// independent builds (`EC_AV1_FINAL_DUMP=<dir>/x`, the directory created
21379+/// FIRST -- the dump writes nothing if it does not exist): five runs with
21380+/// uninitialised planes give TWO different output hashes, five runs with
21381+/// `EC_AV1_PLANE_SENTINEL=1` give ONE hash, and the sentinel output differs
21382+/// from the plain one. At 8-bit the sentinel survives in the dump as the single
21383+/// byte `0xAD`, not the pair `DE AD` -- `PLANE_SENTINEL`'s u16 narrows in
21384+/// [`crate::stream`]'s u8 write path, so counting a two-byte `0xDEAD` in an
21385+/// 8-bit dump cannot find it. The lane's own pre-deblock census
21386+/// ([`census_unwritten`]) then localised the unwritten samples on THIS lane's
21387+/// tree: 112 per chroma plane on the witness, 224 total. That census number is a
21388+/// lane-tree measurement with a lane-only instrument and is cited as such;
21389+/// (1) and (2) are what make the refusal correct.
21390+///
21391+/// `av1_ss_size_lookup`'s `BLOCK_INVALID` cells, transcribed verbatim:
21392+/// `(common_data.c:17-41`, rows in `BLOCK_SIZES_ALL` order, indexed
21393+/// `[subsampling_x][subsampling_y])`. Every entry below is an (luma width,
21394+/// luma height) whose plane block does not EXIST at that subsampling pair, so
21395+/// libaom refuses any subsize of that shape
21396+/// (`av1/decoder/decodeframe.c:1449-1458`, `AOM_CODEC_CORRUPT_FRAME`,
21397+/// "Block size %dx%d invalid with this subsampling mode").
21398+///
21399+/// There is no other `BLOCK_INVALID` cell in the table: at (0,0) 4:4:4 and at
21400+/// (1,1) 4:2:0 every row is valid, and the sixteen shapes below are the only
21401+/// ones that are invalid at (1,0) 4:2:2 or (0,1) 4:4:0. The table test
21402+/// [`chroma_plane_block_codable_matches_the_libaom_table`] re-transcribes all
21403+/// 22 rows and checks this list cell for cell -- a diff against the C source,
21404+/// not a restatement of it.
21405+///
21406+/// ```
21407+/// BLOCK_4X8 {4X8, 4X4} {INVALID, 4X4} <- INVALID @ (1,0)
21408+/// BLOCK_8X4 {8X4, INVALID} {4X4, 4X4} <- INVALID @ (0,1)
21409+/// BLOCK_8X16 {8X16, 8X8} {INVALID, 4X8} <- INVALID @ (1,0)
21410+/// BLOCK_16X8 {16X8, INVALID} {8X8, 8X4} <- INVALID @ (0,1)
21411+/// BLOCK_16X32 {16X32, 16X16} {INVALID, 8X16} <- INVALID @ (1,0)
21412+/// BLOCK_32X16 {32X16, INVALID}{16X16, 16X8} <- INVALID @ (0,1)
21413+/// BLOCK_32X64 {32X64, 32X32} {INVALID, 16X32} <- INVALID @ (1,0)
21414+/// BLOCK_64X32 {64X32, INVALID}{32X32, 32X16} <- INVALID @ (0,1)
21415+/// BLOCK_64X128 {64X128,64X64} {INVALID, 32X64} <- INVALID @ (1,0)
21416+/// BLOCK_128X64 {128X64,INVALID}{64X64, 64X32} <- INVALID @ (0,1)
21417+/// BLOCK_4X16 {4X16, 4X8} {INVALID, 4X8} <- INVALID @ (1,0)
21418+/// BLOCK_16X4 {16X4, 8X4} {8X4, 8X4} <- valid @ (1,0)
21419+/// BLOCK_8X32 {8X32, 8X16} {INVALID, 4X16} <- INVALID @ (1,0)
21420+/// BLOCK_32X8 {32X8, 16X8} {32X8, 16X4} <- valid @ (0,1)
21421+/// BLOCK_16X64 {16X64,16X32} {INVALID, 8X32} <- INVALID @ (1,0)
21422+/// BLOCK_64X16 {64X16,32X16} {32X16, 32X8} <- valid @ (0,1)
21423+/// ```
21424+///
21425+/// The two "valid" rows are here on purpose: an earlier version of this
21426+/// predicate hardcoded BLOCK_16X4@(1,0) and BLOCK_32X8@(0,1) as invalid, which
21427+/// REFUSED a legal 4:2:2 shape -- one aomenc itself emits, since its own
21428+/// `partition_search.c:3383-3389` gates `partition_rect_allowed[HORZ]` with
21429+/// exactly this table.
21430+const PLANE_BLOCK_INVALID_422: &[(usize, usize)] = &[
21431+ (4, 8),
21432+ (8, 16),
21433+ (16, 32),
21434+ (32, 64),
21435+ (64, 128),
21436+ (4, 16),
21437+ (8, 32),
21438+ (16, 64),
21439+];
21440+
21441+/// The same list at 4:4:0 `(0, 1)` -- a shape no `color_config` can request
21442+/// (libaom asserts `subsampling_y == 0` when `subsampling_x == 0`), kept so
21443+/// the table test can cover every cell rather than only the reachable ones.
21444+const PLANE_BLOCK_INVALID_440: &[(usize, usize)] = &[
21445+ (8, 4),
21446+ (16, 8),
21447+ (32, 16),
21448+ (64, 32),
21449+ (128, 64),
21450+ (16, 4),
21451+ (32, 8),
21452+ (64, 16),
21453+];
21454+
21455+/// Whether `av1_ss_size_lookup[(bw, bh)][sx][sy]` is not `BLOCK_INVALID` -- i.e.
21456+/// whether libaom lets a subsize of this luma shape have a chroma plane block
21457+/// at this subsampling at all.
21458+fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool {
21459+ match (sx, sy) {
21460+ (1, 0) => !PLANE_BLOCK_INVALID_422.contains(&(bw, bh)),
21461+ (0, 1) => !PLANE_BLOCK_INVALID_440.contains(&(bw, bh)),
21462+ _ => true,
21463+ }
21464+}
21465+
21466+/// libaom `get_partition_subsize` (spec 6.10.3, `common_data.c`'s
21467+/// `subsize_lookup`) reduced to its DIMENSIONS -- all the `av1_ss_size_lookup`
21468+/// check needs, and, by construction, never the PARENT block's own shape
21469+/// (that is the r2 mistake in a new place: refusing `16x4` at 4:2:2 by testing
21470+/// the 16x8 parent). `PARTITION_HORZ_A`/`_B` and `PARTITION_VERT_A`/`_B` are
21471+/// the four-way arms, whose subsizes are the strips they visit.
21472+fn partition_subsize_dims(bsize: (usize, usize), part: usize) -> (usize, usize) {
21473+ let (w, h) = bsize;
21474+ match part {
21475+ PARTITION_SPLIT => (w / 2, h / 2),
21476+ PARTITION_HORZ | PARTITION_HORZ_A | PARTITION_HORZ_B => (w, h / 2),
21477+ PARTITION_VERT | PARTITION_VERT_A | PARTITION_VERT_B => (w / 2, h),
21478+ PARTITION_HORZ_4 => (w, h / 4),
21479+ PARTITION_VERT_4 => (w / 4, h),
21480+ _ => (w, h),
21481+ }
21482+}
21483+
21484+/// [`chroma_plane_block_codable`] applied to the subsize a partition SYMBOL
21485+/// selected, exactly as `decode_partition` does at `decodeframe.c:1449-1458`
21486+/// before descending into it. Returns libaom's named refusal for the caller to
21487+/// propagate.
21488+#[track_caller]
21489+fn refuse_invalid_subsize(
21490+ bsize: (usize, usize),
21491+ part: usize,
21492+ fctx: &crate::decode::FrameCtx,
21493+) -> Result<()> {
21494+ // lane-av1unwritten r6: the coverage artefact. A guard that sits INSIDE a
21495+ // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm can only ever observe 4..=7, so
21496+ // "the guard is present" is not evidence that an offending value is caught --
21497+ // which is exactly how r5's three misplaced guards read as coverage. This
21498+ // records, per CALL SITE and per partition value, how often the guard was
21499+ // reached and how often it fired, so a site that never sees an offending
21500+ // value is visible instead of assumed covered.
21501+ if crate::envflags::env_flag!("EC_AV1_SUBSIZE_GUARD_TRACE") {
21502+ note_subsize_guard(
21503+ std::panic::Location::caller(),
21504+ bsize,
21505+ part,
21506+ chroma_plane_block_codable(
21507+ partition_subsize_dims(bsize, part).0,
21508+ partition_subsize_dims(bsize, part).1,
21509+ ss_x(fctx),
21510+ ss_y(fctx),
21511+ ),
21512+ );
21513+ }
21514+ let (bw, bh) = partition_subsize_dims(bsize, part);
21515+ if chroma_plane_block_codable(bw, bh, ss_x(fctx), ss_y(fctx)) {
21516+ Ok(())
21517+ } else {
21518+ Err(refuse_invalid_plane_block(bw, bh, fctx))
21519+ }
21520+}
21521+
21522+/// lane-av1unwritten r6: the OTHER half of the coverage artefact. The guard
21523+/// table says what the guards see; this says what each DISPATCH ARM sees, so a
21524+/// dispatch reached with an offending partition value and no guard above it is a
21525+/// visible hole rather than an absence nobody noticed. `decode_probe` calls
21526+/// [`dump_subsize_arm_scan`] at exit under `EC_AV1_SUBSIZE_ARM_TRACE`.
21527+static SUBSIZE_ARM: std::sync::LazyLock<
21528+ std::sync::Mutex<std::collections::BTreeMap<(&'static str, usize), usize>>,
21529+> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default()));
21530+
21531+#[track_caller]
21532+pub(crate) fn note_subsize_arm(part: usize, codable: bool) {
21533+ if !crate::envflags::env_flag!("EC_AV1_SUBSIZE_ARM_TRACE") {
21534+ return;
21535+ }
21536+ let site = std::panic::Location::caller();
21537+ let key = (
21538+ format!("{}:{}", site.file(), site.line()).leak() as &'static str,
21539+ part * 2 + usize::from(codable),
21540+ );
21541+ if let Ok(mut m) = SUBSIZE_ARM.lock() {
21542+ *m.entry(key).or_insert(0) += 1;
21543+ }
21544+}
21545+
21546+/// Prints and clears the [`note_subsize_arm`] table.
21547+pub fn dump_subsize_arm_scan() {
21548+ let Ok(mut m) = SUBSIZE_ARM.lock() else {
21549+ return;
21550+ };
21551+ for ((site, k), n) in m.iter() {
21552+ eprintln!(
21553+ "SUBSIZE_ARM site={site} part={} codable={} reached={n}",
21554+ k / 2,
21555+ if k % 2 == 1 { "true" } else { "false" },
21556+ );
21557+ }
21558+ m.clear();
21559+}
21560+
21561+/// Per-site, per-value counters for [`refuse_invalid_subsize`], plus the dump
21562+/// that makes the reach/guard split readable. `EC_AV1_SUBSIZE_GUARD_TRACE`
21563+/// records; `dump_subsize_guard_scan` prints (and clears) the table.
21564+static SUBSIZE_GUARD: std::sync::LazyLock<
21565+ std::sync::Mutex<std::collections::BTreeMap<(&'static str, usize, usize, bool), usize>>,
21566+> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default()));
21567+
21568+fn note_subsize_guard(
21569+ site: &'static std::panic::Location<'static>,
21570+ bsize: (usize, usize),
21571+ part: usize,
21572+ codable: bool,
21573+) {
21574+ let key = (
21575+ format!("{}:{}", site.file(), site.line()).leak() as &'static str,
21576+ bsize.0 * 256 + bsize.1,
21577+ part,
21578+ codable,
21579+ );
21580+ if let Ok(mut m) = SUBSIZE_GUARD.lock() {
21581+ *m.entry(key).or_insert(0) += 1;
21582+ }
21583+}
21584+
21585+/// Prints and clears the [`refuse_invalid_subsize`] table: one line per
21586+/// (site, block, partition value) with the times reached and whether the guard
21587+/// fired. `decode_probe` calls this at exit.
21588+pub fn dump_subsize_guard_scan() {
21589+ let Ok(mut m) = SUBSIZE_GUARD.lock() else {
21590+ return;
21591+ };
21592+ for ((site, bsize, part, codable), n) in m.iter() {
21593+ eprintln!(
21594+ "SUBSIZE_GUARD site={site} bsize={}x{} part={part} codable={codable} \
21595+ reached={n}{}",
21596+ bsize / 256,
21597+ bsize % 256,
21598+ if *codable { "" } else { " FIRED" },
21599+ );
21600+ }
21601+ m.clear();
21602+}
21603+
21604+/// [`chroma_plane_block_codable`] as libaom's refusal: a returned error naming
21605+/// the shape and the subsampling mode, never an `assert!` -- a partition symbol
21606+/// is stream data, so a hostile file can reach it.
21607+fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::FrameCtx) -> Error {
21608+ unsupported(
21609+ "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this \
21610+ frame's subsampling mode (libaom: \"Block size %dx%d invalid with this subsampling \
21611+ mode\", av1/decoder/decodeframe.c:1456, refusing by the same rule)",
21612+ )
21613+}
21614+
21238 /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no21615 /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no
21239 /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,21616 /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,
21240 /// at most 4095), so a decode that hashes identically under the flag proves21617 /// at most 4095), so a decode that hashes identically under the flag proves
@@ -21252,7 +21629,7 @@ const PLANE_SENTINEL: u16 = 0xDEAD;
21252 /// ways (see the lane report) and the two agree, which is the proof that no21629 /// ways (see the lane report) and the two agree, which is the proof that no
21253 /// unwritten sample reaches the output.21630 /// unwritten sample reaches the output.
21254 fn fresh_plane(n: usize) -> Vec<u16> {21631 fn fresh_plane(n: usize) -> Vec<u16> {
21255- if crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") {21632+ if plane_sentinel_on() {
21256 return vec![PLANE_SENTINEL; n];21633 return vec![PLANE_SENTINEL; n];
21257 }21634 }
21258 let mut v: Vec<u16> = Vec::with_capacity(n);21635 let mut v: Vec<u16> = Vec::with_capacity(n);
@@ -21294,6 +21671,8 @@ struct PlaneBuf<'a> {
21294 /// old unclipped behaviour exactly.21671 /// old unclipped behaviour exactly.
21295 tile_x1: usize,21672 tile_x1: usize,
21296 tile_y1: usize,21673 tile_y1: usize,
21674+ /// Which plane this buffer IS (0 luma, 1 U, 2 V) -- TEMPORARY probe.
21675+ plane: u8,
21297 }21676 }
21298 21677
21299 /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/21678 /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/
@@ -26322,6 +26701,29 @@ fn sub8_leaf_chroma422(
26322 // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end26701 // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end
26323 // for every leaf this reader owns, and the unit is one TX_4X4 chroma26702 // for every leaf this reader owns, and the unit is one TX_4X4 chroma
26324 // transform wide and tall (`4 << ss` luma px per axis).26703 // transform wide and tall (`4 << ss` luma px per axis).
26704+ // lane-av1unwritten: at ss (1,0) a BLOCK_4X8 chroma reference's plane
26705+ // block is 4x8 -- `get_plane_block_size(BLOCK_4X8, 1, 0)` is BLOCK_4X8
26706+ // (`common_data.c`'s `av1_ss_size_lookup[BLOCK_4X8][1][0]` is
26707+ // BLOCK_INVALID, but `blockd.h:1372` takes the per-axis MIN of the two
26708+ // lookups) -- and `av1_get_max_uv_txsize` (blockd.h:1372-1379) resolves
26709+ // it through `max_txsize_rect_lookup[BLOCK_4X8]` == TX_4X8
26710+ // (`common_data.h:126`). So away from lossless the WHOLE 4x8 plane block
26711+ // is ONE rect transform unit, exactly the one [`leaf8_chroma422_unit`]
26712+ // already reads for a BLOCK_8X8 leaf. Emitting the single square TX_4X4
26713+ // this arm used to wrote left the block's bottom four chroma rows
26714+ // UNWRITTEN: on the pinned `440_request_is_422.obu` (a 4:2:2 header over
26715+ // a 4:2:0 tile, whose legal 8x8 `PARTITION_HORZ` groups make this shape
26716+ // legal syntax) the sentinel census found 112 unwritten samples per
26717+ // chroma plane, one 4x4 block per group, and the decode's output hash
26718+ // CHANGED RUN TO RUN because the unwritten samples were uninitialised
26719+ // memory (class `writer-gap-reaches-output`).
26720+ //
26721+ // At LOSSLESS the single-unit reading is wrong the other way:
26722+ // `av1_get_tx_size`'s first line returns TX_4X4 on every plane
26723+ // (blockd.h:1383), so the 4x8 plane block is walked as TWO stacked 4x4
26724+ // units -- which is exactly what the two chroma-reference leaves of the
26725+ // `decode_leaf_split4` route below already emit, so the square arms stay
26726+ // for lossless.
26325 let tx_w = 4 << ss_x(fctx);26727 let tx_w = 4 << ss_x(fctx);
26326 let tx_h = 4 << ss_y(fctx);26728 let tx_h = 4 << ss_y(fctx);
26327 let reach = Reach::of_tu_chroma(26729 let reach = Reach::of_tu_chroma(
@@ -35178,6 +35580,12 @@ fn read_sb128_root(
35178 // root has no 1:4 arm at all (`PARTITION_HORZ_4`/`VERT_4` are excluded35580 // root has no 1:4 arm at all (`PARTITION_HORZ_4`/`VERT_4` are excluded
35179 // for BLOCK_128X128 by `av1_get_partition_cdf`'s 8-symbol alphabet,35581 // for BLOCK_128X128 by `av1_get_partition_cdf`'s 8-symbol alphabet,
35180 // which stops at VERT_B).35582 // which stops at VERT_B).
35583+ // lane-av1unwritten r4: guard the subsize THIS SYMBOL selected, never the
35584+ // root's own plane block. VERT on a 128x128 root selects BLOCK_64X128,
35585+ // whose 4:2:2 plane block is BLOCK_INVALID; the AB arms select 64x64
35586+ // quadrants (valid), so PARTITION_HORZ / PARTITION_NONE / SPLIT keep
35587+ // decoding untouched.
35588+ refuse_invalid_subsize((128, 128), part128, fctx)?;
35181 match part128 {35589 match part128 {
35182 PARTITION_SPLIT => hit!(PART128_SPLIT_HITS),35590 PARTITION_SPLIT => hit!(PART128_SPLIT_HITS),
35183 PARTITION_NONE => hit!(PART128_NONE_HITS),35591 PARTITION_NONE => hit!(PART128_NONE_HITS),
@@ -35287,6 +35695,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
35287 tile_y0: 0,35695 tile_y0: 0,
35288 tile_x1: width,35696 tile_x1: width,
35289 tile_y1: height,35697 tile_y1: height,
35698+ plane: 0,
35290 };35699 };
35291 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));35700 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
35292 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));35701 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
@@ -35300,6 +35709,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
35300 tile_y0: 0,35709 tile_y0: 0,
35301 tile_x1: cw,35710 tile_x1: cw,
35302 tile_y1: ch,35711 tile_y1: ch,
35712+ plane: 1,
35303 };35713 };
35304 let mut v = PlaneBuf {35714 let mut v = PlaneBuf {
35305 data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),35715 data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
@@ -35311,6 +35721,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
35311 tile_y0: 0,35721 tile_y0: 0,
35312 tile_x1: cw,35722 tile_x1: cw,
35313 tile_y1: ch,35723 tile_y1: ch,
35724+ plane: 2,
35314 };35725 };
35315 35726
35316 let scan32 = default_scan(TX32);35727 let scan32 = default_scan(TX32);
@@ -35856,6 +36267,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
35856 }36267 }
35857 }36268 }
35858 };36269 };
36270+ // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or
36271+ // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is
36272+ // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to
36273+ // dimensions, so this is `decode_partition`'s pre-descend check
36274+ // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT,
36275+ // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep
36276+ // decoding because the helper is exact, not a heuristic. the 64x64 level binds its symbol to `part`.
36277+ refuse_invalid_subsize((64, 64), part, fctx)?;
35859 match part {36278 match part {
35860 PARTITION_NONE => {36279 PARTITION_NONE => {
35861 decode_block(36280 decode_block(
@@ -35978,6 +36397,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
35978 }36397 }
35979 }36398 }
35980 };36399 };
36400+ // lane-av1unwritten r4: VERT on a 32x32 block selects
36401+ // BLOCK_16X32 -- INVALID at 4:2:2. HORZ on the same
36402+ // block selects BLOCK_32X16, whose (1,0) cell is
36403+ // BLOCK_16X16 (valid) and MUST keep decoding, so the
36404+ // check is on the symbol's subsize, not the parent's.
36405+ refuse_invalid_subsize((32, 32), part32, fctx)?;
35981 match part32 {36406 match part32 {
35982 PARTITION_NONE => {36407 PARTITION_NONE => {
35983 decode_block(36408 decode_block(
@@ -36037,6 +36462,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36037 );36462 );
36038 }36463 }
36039 let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]);36464 let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]);
36465+ // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be
36466+ // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize`
36467+ // (common_data.h:71-90) reduced to dimensions, so this is
36468+ // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY
36469+ // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings
36470+ // keep decoding because the helper is exact, not a heuristic. key-frame 16x16 level.
36471+ refuse_invalid_subsize((16, 16), part16, fctx)?;
36472+
36040 if crate::envflags::env_flag!("EC_TRACE") {36473 if crate::envflags::env_flag!("EC_TRACE") {
36041 eprintln!(36474 eprintln!(
36042 "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}",36475 "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}",
@@ -36052,6 +36485,24 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36052 sc * SUB_MI as usize36485 sc * SUB_MI as usize
36053 );36486 );
36054 }36487 }
36488+ if part16 == PARTITION_HORZ || part16 == PARTITION_VERT
36489+ {
36490+ let (bw, bh) = if part16 == PARTITION_HORZ {
36491+ (16, 8)
36492+ } else {
36493+ (8, 16)
36494+ };
36495+ if !chroma_plane_block_codable(
36496+ bw,
36497+ bh,
36498+ ss_x(fctx),
36499+ ss_y(fctx),
36500+ ) {
36501+ return Err(refuse_invalid_plane_block(
36502+ bw, bh, fctx,
36503+ ));
36504+ }
36505+ }
36055 if part16 == PARTITION_NONE {36506 if part16 == PARTITION_NONE {
36056 decode_block(36507 decode_block(
36057 &mut dec,36508 &mut dec,
@@ -36327,6 +36778,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36327 if part16 == PARTITION_HORZ_436778 if part16 == PARTITION_HORZ_4
36328 || part16 == PARTITION_VERT_436779 || part16 == PARTITION_VERT_4
36329 {36780 {
36781+ // lane-av1unwritten r6: arm census --
36782+ // which partition values reach here.
36783+ note_subsize_arm(
36784+ part16,
36785+ chroma_plane_block_codable(
36786+ partition_subsize_dims((16, 16), part16).0,
36787+ partition_subsize_dims((16, 16), part16).1,
36788+ ss_x(fctx),
36789+ ss_y(fctx),
36790+ ),
36791+ );
36330 decode_rect4_16(36792 decode_rect4_16(
36331 &mut dec,36793 &mut dec,
36332 &mut cdfs,36794 &mut cdfs,
@@ -36411,6 +36873,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36411 }36873 }
36412 let part8 =36874 let part8 =
36413 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);36875 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
36876+ // lane-av1unwritten r9: the
36877+ // SECOND key-frame 8x8 resolution.
36878+ // Found by the structural scan, which
36879+ // r9 made sensitive to a second
36880+ // site at an already covered level.
36881+ refuse_invalid_subsize((8, 8), part8, fctx)?;
36414 if crate::envflags::env_flag!("EC_TRACE") {36882 if crate::envflags::env_flag!("EC_TRACE") {
36415 eprintln!(36883 eprintln!(
36416 "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}",36884 "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}",
@@ -36422,6 +36890,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36422 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"36890 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"
36423 );36891 );
36424 }36892 }
36893+ if part8 == PARTITION_HORZ
36894+ || part8 == PARTITION_VERT
36895+ {
36896+ // libaom's `subsize_lookup`: HORZ on an 8x8 is
36897+ // BLOCK_8X4, VERT is BLOCK_4X8.
36898+ let (bw, bh) = if part8 == PARTITION_HORZ {
36899+ (8, 4)
36900+ } else {
36901+ (4, 8)
36902+ };
36903+ if !chroma_plane_block_codable(
36904+ bw,
36905+ bh,
36906+ ss_x(fctx),
36907+ ss_y(fctx),
36908+ ) {
36909+ return Err(refuse_invalid_plane_block(
36910+ bw, bh, fctx,
36911+ ));
36912+ }
36913+ }
36425 let leaf_mode = if part8 == PARTITION_NONE {36914 let leaf_mode = if part8 == PARTITION_NONE {
36426 decode_leaf8(36915 decode_leaf8(
36427 &mut dec,36916 &mut dec,
@@ -36629,6 +37118,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36629 let pre8 = dec.debug_state().0;37118 let pre8 = dec.debug_state().0;
36630 let part8 =37119 let part8 =
36631 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);37120 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
37121+ // lane-av1unwritten r9: key-frame 8x8
37122+ // level. A VERT here dispatches
37123+ // `decode_leaf_rect8` on a raw `part8`
37124+ // with no guard anywhere above it --
37125+ // `BLOCK_4X8`, which is INVALID at
37126+ // 4:2:2 (the shape r5 and r6 each
37127+ // flagged). Not corpus-reachable at
37128+ // ss(1,0) today, so it is residue rather
37129+ // than live pixels, and it is guarded
37130+ // anyway.
37131+ refuse_invalid_subsize((8, 8), part8, fctx)?;
36632 if crate::envflags::env_flag!("EC_AV1_TRACE") {37132 if crate::envflags::env_flag!("EC_AV1_TRACE") {
36633 eprintln!(37133 eprintln!(
36634 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"37134 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"
@@ -37459,6 +37959,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
37459 frame_width as usize,37959 frame_width as usize,
37460 frame_height as usize,37960 frame_height as usize,
37461 );37961 );
37962+ census_unwritten(&y, &u, &v);
37462 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {37963 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
37463 use std::io::Write;37964 use std::io::Write;
37464 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);37965 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -37597,6 +38098,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
37597 tile_y0: 0,38098 tile_y0: 0,
37598 tile_x1: out_w,38099 tile_x1: out_w,
37599 tile_y1: in_h,38100 tile_y1: in_h,
38101+ plane: p.plane,
37600 };38102 };
37601 let (cw, ch, cuw) = (38103 let (cw, ch, cuw) = (
37602 round_ss(fw, ss_x(fctx)),38104 round_ss(fw, ss_x(fctx)),
@@ -38944,6 +39446,7 @@ fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> {
38944 tile_y0: 0,39446 tile_y0: 0,
38945 tile_x1: width,39447 tile_x1: width,
38946 tile_y1: height,39448 tile_y1: height,
39449+ plane: 0,
38947 }39450 }
38948 }39451 }
38949 39452
@@ -52902,6 +53405,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
52902 tile_y0: 0,53405 tile_y0: 0,
52903 tile_x1: width,53406 tile_x1: width,
52904 tile_y1: height,53407 tile_y1: height,
53408+ plane: 0,
52905 };53409 };
52906 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));53410 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
52907 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));53411 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
@@ -52915,6 +53419,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
52915 tile_y0: 0,53419 tile_y0: 0,
52916 tile_x1: cw,53420 tile_x1: cw,
52917 tile_y1: ch,53421 tile_y1: ch,
53422+ plane: 1,
52918 };53423 };
52919 let mut v = PlaneBuf {53424 let mut v = PlaneBuf {
52920 data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),53425 data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
@@ -52926,6 +53431,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
52926 tile_y0: 0,53431 tile_y0: 0,
52927 tile_x1: cw,53432 tile_x1: cw,
52928 tile_y1: ch,53433 tile_y1: ch,
53434+ plane: 2,
52929 };53435 };
52930 53436
52931 let scan32 = default_scan(TX32);53437 let scan32 = default_scan(TX32);
@@ -53468,6 +53974,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
53468 cdef_copy($src, $dst);53974 cdef_copy($src, $dst);
53469 }};53975 }};
53470 }53976 }
53977+ // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or
53978+ // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is
53979+ // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to
53980+ // dimensions, so this is `decode_partition`'s pre-descend check
53981+ // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT,
53982+ // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep
53983+ // decoding because the helper is exact, not a heuristic. (inter-frame duplicate)
53984+ refuse_invalid_subsize((128, 128), part128, fctx)?;
53471 match part128 {53985 match part128 {
53472 PARTITION_HORZ_A => {53986 PARTITION_HORZ_A => {
53473 square64_inter!(base_mi);53987 square64_inter!(base_mi);
@@ -53637,6 +54151,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
53637 );54151 );
53638 }54152 }
53639 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);54153 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
54154+ // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be
54155+ // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize`
54156+ // (common_data.h:71-90) reduced to dimensions, so this is
54157+ // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY
54158+ // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings
54159+ // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol.
54160+
53640 if crate::envflags::env_flag!("EC_AV1_TRACE") {54161 if crate::envflags::env_flag!("EC_AV1_TRACE") {
53641 eprintln!(54162 eprintln!(
53642 "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}",54163 "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}",
@@ -53688,6 +54209,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
53688 PARTITION_SPLIT54209 PARTITION_SPLIT
53689 }54210 }
53690 };54211 };
54212+ // lane-av1unwritten r7: the symbol is RESOLVED (a full CDF
54213+ // read or an edge `gather`) and about to be dispatched, so the
54214+ // check sits HERE rather than inside the (true, true) arm: the
54215+ // edge arms return without passing it, and (false, true)
54216+ // resolves to PARTITION_VERT, which on a 64x64 root selects
54217+ // BLOCK_32X64 -- INVALID at (1,0) and unreachable from the
54218+ // corpus (measured: 50 reaches corpus-wide, 0 in any 4:2:2 cell).
54219+ // r6 had this inside the (true, true) arm, where it could not
54220+ // see it.
54221+ refuse_invalid_subsize((64, 64), part64, fctx)?;
53691 if part64 == PARTITION_NONE {54222 if part64 == PARTITION_NONE {
53692 // lane-inter8 r1: the whole superblock as one 64x64 inter54223 // lane-inter8 r1: the whole superblock as one 64x64 inter
53693 // block. `SB`-sized syntax throughout (size_group 3, same as54224 // block. `SB`-sized syntax throughout (size_group 3, same as
@@ -53752,6 +54283,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
53752 part64,54283 part64,
53753 PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_454284 PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4
53754 ) {54285 ) {
54286+ // lane-av1unwritten r6: arm census.
54287+ note_subsize_arm(
54288+ part64,
54289+ chroma_plane_block_codable(
54290+ partition_subsize_dims((64, 64), part64).0,
54291+ partition_subsize_dims((64, 64), part64).1,
54292+ ss_x(fctx),
54293+ ss_y(fctx),
54294+ ),
54295+ );
53755 // lane-inter4 r1: the superblock-level rect + 1:4 pairs as54296 // lane-inter4 r1: the superblock-level rect + 1:4 pairs as
53756 // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 /54297 // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 /
53757 // 16x64 ones. Each piece keeps `side = SB` for every54298 // 16x64 ones. Each piece keeps `side = SB` for every
@@ -54054,6 +54595,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54054 }54595 }
54055 }54596 }
54056 };54597 };
54598+ // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or
54599+ // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is
54600+ // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to
54601+ // dimensions, so this is `decode_partition`'s pre-descend check
54602+ // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT,
54603+ // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep
54604+ // decoding because the helper is exact, not a heuristic. (inter-frame duplicate)
54605+ refuse_invalid_subsize((32, 32), part32, fctx)?;
54057 match part32 {54606 match part32 {
54058 PARTITION_NONE => {54607 PARTITION_NONE => {
54059 decode_inter_block(54608 decode_inter_block(
@@ -54191,6 +54740,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54191 }54740 }
54192 }54741 }
54193 };54742 };
54743+ // lane-av1unwritten r7: the inter-frame 16x16
54744+ // level had NO guard at all -- r6 dropped r5's
54745+ // misplaced one without replacing it, and all three
54746+ // dispatch arms below (NONE/HORZ/VERT, the four AB
54747+ // arms, and the 1:4 arms) select BLOCK_8X16 and
54748+ // BLOCK_4X16, two of the eight (1,0)-INVALID shapes.
54749+ // The check goes where the symbol is RESOLVED, so
54750+ // every arm is covered by construction.
54751+ refuse_invalid_subsize((16, 16), part16, fctx)?;
54194 if part16 == PARTITION_NONE {54752 if part16 == PARTITION_NONE {
54195 decode_inter_block(54753 decode_inter_block(
54196 &mut dec,54754 &mut dec,
@@ -54596,6 +55154,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54596 }55154 }
54597 let ec_dbg_pre = dec.debug_state().0;55155 let ec_dbg_pre = dec.debug_state().0;
54598 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);55156 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
55157+ // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be
55158+ // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize`
55159+ // (common_data.h:71-90) reduced to dimensions, so this is
55160+ // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY
55161+ // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings
55162+ // keep decoding because the helper is exact, not a heuristic. inter-frame 8x8 level.
55163+ refuse_invalid_subsize((8, 8), part8, fctx)?;
55164+
54599 if std::env::var_os("EC_DBG_SUB8").is_some() {55165 if std::env::var_os("EC_DBG_SUB8").is_some() {
54600 let ec_dbg_post = dec.debug_state().0;55166 let ec_dbg_post = dec.debug_state().0;
54601 eprintln!(55167 eprintln!(
@@ -54633,6 +55199,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54633 )?;55199 )?;
54634 continue;55200 continue;
54635 }55201 }
55202+ // lane-av1unwritten r6: arm census -- an
55203+ // 8x8-level VERT selects BLOCK_4X8, which
55204+ // is INVALID at 4:2:2.
55205+ note_subsize_arm(
55206+ part8,
55207+ chroma_plane_block_codable(
55208+ partition_subsize_dims((8, 8), part8).0,
55209+ partition_subsize_dims((8, 8), part8).1,
55210+ ss_x(fctx),
55211+ ss_y(fctx),
55212+ ),
55213+ );
54636 if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {55214 if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {
54637 // lane-intersub8 r3/r4/r5: two55215 // lane-intersub8 r3/r4/r5: two
54638 // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT)55216 // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT)
@@ -55743,6 +56321,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
55743 frame_width as usize,56321 frame_width as usize,
55744 frame_height as usize,56322 frame_height as usize,
55745 );56323 );
56324+ census_unwritten(&y, &u, &v);
55746 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {56325 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
55747 use std::io::Write;56326 use std::io::Write;
55748 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);56327 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -55903,6 +56482,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
55903 tile_y0: 0,56482 tile_y0: 0,
55904 tile_x1: out_w,56483 tile_x1: out_w,
55905 tile_y1: in_h,56484 tile_y1: in_h,
56485+ plane: p.plane,
55906 };56486 };
55907 let (cw, ch, cuw) = (56487 let (cw, ch, cuw) = (
55908 round_ss(fw, ss_x(fctx)),56488 round_ss(fw, ss_x(fctx)),
@@ -56028,6 +56608,406 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
56028 56608
56029 #[cfg(test)]56609 #[cfg(test)]
56030 mod tests {56610 mod tests {
56611+
56612+ /// lane-av1unwritten r7: the STRUCTURAL invariant that r5 and r6 both broke.
56613+ ///
56614+ /// r5 put guards inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms, so they
56615+ /// could only ever see values 4..=7. r6 deleted the inter-16 guard and did not
56616+ /// replace it. r7's fix was mechanical at both sites and the failure mode was
56617+ /// always the same: a guard exists somewhere, and nothing says it sits between
56618+ /// a symbol's RESOLUTION and every dispatch of it.
56619+ ///
56620+ /// So the invariant is stated over the dispatch structure, not over a list.
56621+ /// Counts in the tree this was written against, re-derived per line rather
56622+ /// than grepped: `refuse_invalid_subsize((` occurs **18 times** in this file —
56623+ /// **11 guard call sites** in the decode body (35588, 36278, 36406, 36472,
56624+ /// 36882, 37132, 53985, 54222, 54606, 54752, 55164), **5** in this test's own
56625+ /// string literals and comparisons, **2** in doc comments; the definition's
56626+ /// signature line does not match `((` at all. The scan finds **10 resolutions**:
56627+ /// the eleventh guard is the inter-frame 128 one, whose resolution lives in
56628+ /// the shared `read_sb128_root`, so a guard has no resolution of its own here.
56629+ /// What is asserted, exactly:
56630+ ///
56631+ /// * every `partition_w<N>[` level in the file appears among the resolutions
56632+ /// this scan finds -- a new level cannot be added without a guard check;
56633+ /// * each resolution is followed, within 220 lines, by a
56634+ /// `refuse_invalid_subsize((N, N), …)` for its OWN level (matched on the
56635+ /// level, not the variable, because the symbol is often bound to a
56636+ /// short-lived inner name `p` and dispatched by an outer `part64`);
56637+ /// * where that window contains a `match part…` dispatch, the guard precedes
56638+ /// it -- the bound r7's COMMENT claimed and r8 implements;
56639+ /// * no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm.
56640+ ///
56641+ /// It does NOT prove a guard is at the exact dispatch point: the window is a
56642+ /// window. And the two cross-checks are weaker than they look — cross-check 1
56643+ /// is level PRESENCE only, cross-check 2 is `>=` — so a SECOND unguarded site
56644+ /// at an already-covered level is caught ONLY by the per-site 220-line window,
56645+ /// which is a window and not a dispatch bound. That limit is why the AB-arm
56646+ /// invariant exists separately, and why `EC_AV1_SUBSIZE_GUARD_TRACE` records
56647+ /// what each site really sees over the corpus.
56648+ #[test]
56649+ fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() {
56650+ let src = include_str!("decode.rs");
56651+ // Every partition-symbol RESOLUTION in the file, with the level read off
56652+ // the CDF name on the line itself. Two independent counts are compared, so
56653+ // a site lost to line wrapping reds instead of silently vanishing: the
56654+ // Every partition-symbol RESOLUTION in the file. The window is the line
56655+ // BEFORE as well as the line itself and the one after (r9), because a
56656+ // `let <var> =` on one line with `dec.symbol(&mut cdfs.partition_w8[..])`
56657+ // on the next is a real shape in this file -- and r9's own ungated site at
56658+ // 37115 was invisible for exactly that reason.
56659+ let lines: Vec<&str> = src.lines().collect();
56660+ let mut sites: Vec<(usize, String, usize)> = Vec::new();
56661+ // Occurrences of `partition_w<N>[` per level, counted from the FILE, used as
56662+ // the cross-check below.
56663+ let mut file_occurrences: std::collections::BTreeMap<usize, usize> = Default::default();
56664+ // Only the DECODE body: the test module below also builds `partition_w8`
56665+ // CDFs (an encoder round-trip at 58464/58521), and counting those would
56666+ // demand a guard for a site that does not exist.
56667+ let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") {
56668+ Some(i) => &src[..i],
56669+ None => src,
56670+ };
56671+ {
56672+ let mut rest = decode_body;
56673+ while let Some(i) = rest.find("partition_w") {
56674+ let after = &rest[i + "partition_w".len()..];
56675+ let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
56676+ rest = after;
56677+ if digits.is_empty() {
56678+ continue; // `partition_wide`, or any other word starting the same way
56679+ }
56680+ if after[digits.len()..].starts_with('[') {
56681+ *file_occurrences
56682+ .entry(digits.parse().expect("digits"))
56683+ .or_insert(0) += 1;
56684+ }
56685+ }
56686+ }
56687+ for (n, line) in lines.iter().enumerate() {
56688+ let t = line.trim_start();
56689+ // A doc comment quoting the shape is not a site, and neither is the
56690+ // test's own example strings further down the file.
56691+ if t.starts_with("//") || !line.contains("partition_w") || n > 56000 {
56692+ continue;
56693+ }
56694+ let lo = n.saturating_sub(1);
56695+ let hi = (n + 2).min(lines.len());
56696+ let window = lines[lo..hi].join(" ");
56697+ if !window.contains("dec.symbol(") {
56698+ continue;
56699+ }
56700+ let Some(i) = window.find("partition_w") else {
56701+ continue;
56702+ };
56703+ let after = &window[i + "partition_w".len()..];
56704+ let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
56705+ if digits.is_empty() {
56706+ continue;
56707+ }
56708+ let level: usize = digits.parse().expect("digits");
56709+ // The bound variable is the token after `let `, looked for in the two
56710+ // lines the binding can occupy (r9: it may be the line above).
56711+ // r10: scan BACKWARDS from the closest line and take the nearest `let`
56712+ // whose binding is the one followed by this symbol read -- taking the
56713+ // first `let` upward named an unrelated binding above it.
56714+ let mut var = None;
56715+ for cand in (lo..=n).rev() {
56716+ let ct = lines[cand].trim_start();
56717+ if ct.starts_with("//") {
56718+ continue;
56719+ }
56720+ let Some(v) = ct.strip_prefix("let ") else {
56721+ continue;
56722+ };
56723+ let name = v
56724+ .split(|c: char| !(c.is_alphanumeric() || c == '_'))
56725+ .next()
56726+ .unwrap_or("")
56727+ .to_string();
56728+ if name.is_empty() {
56729+ continue;
56730+ }
56731+ // This binding is followed by the symbol read if the SAME line
56732+ // completes `let <name> = dec.symbol(`, or if the next line starts
56733+ // the call. That is what separates `let part8 =` from an unrelated
56734+ // `let ec_dbg_pre =` two lines above it.
56735+ let next = lines.get(cand + 1).copied().unwrap_or("");
56736+ let binds_here = ct.contains("= dec.symbol") || next.contains("dec.symbol(");
56737+ if binds_here || cand == n {
56738+ var = Some(name);
56739+ break;
56740+ }
56741+ }
56742+ let Some(var) = var else { continue };
56743+ // An edge `gather` binds `b` and is not a resolution: libaom resolves
56744+ // those from a two-symbol CDF and the site is guarded at the level's
56745+ // own resolution instead.
56746+ if var == "b" {
56747+ continue;
56748+ }
56749+ sites.push((n, var, level));
56750+ }
56751+
56752+ // ---- cross-check 1: every `partition_w<N>` LEVEL in the decode body has
56753+ // at least one guarded resolution. r9: this is level PRESENCE, and it is
56754+ // stated as such -- it cannot catch a SECOND unguarded site at an already
56755+ // covered level. What does catch that is cross-check 2 below (the exact
56756+ // guard/resolution count) together with the per-site assertion.
56757+ let mut covered: std::collections::BTreeSet<usize> = Default::default();
56758+ for (_, _, level) in &sites {
56759+ covered.insert(*level);
56760+ }
56761+ for level in file_occurrences.keys() {
56762+ assert!(
56763+ covered.contains(level),
56764+ "level {level} names a `partition_w{level}[` CDF in the decode body but this \
56765+ scan finds no guarded resolution for it (r9)"
56766+ );
56767+ }
56768+
56769+ // ---- cross-check 2: an EXACT count derived from the scan, never a floor.
56770+ // Counted by CALL SHAPE -- a line whose first token is the call -- so a
56771+ // multi-line assert string mentioning the function is not counted, and the
56772+ // definition is not either.
56773+ let guarded_sites = decode_body
56774+ .lines()
56775+ .filter(|l| l.trim_start().starts_with("refuse_invalid_subsize(("))
56776+ .count();
56777+ // r9: was `assert_eq!`, which the tree's own counts disagree on (the scan
56778+ // sees 10 resolutions against 11 guards), and a hard-equal on two numbers the
56779+ // scan itself computes is a claim about the SCANNER, not about coverage. It
56780+ // is `>=` plus the per-site assertion below: a resolution with no guard reds
56781+ // on its own line, which is the property that matters, and a guard with no
56782+ // resolution behind it is redundant rather than unsafe.
56783+ assert!(
56784+ guarded_sites >= sites.len(),
56785+ "the decode body has {sites_len} partition resolutions but only {guarded_sites} \
56786+ guard sites -- fewer guards than resolutions (r9)",
56787+ sites_len = sites.len()
56788+ );
56789+
56790+ for (line_no, var, level) in &sites {
56791+ // Two properties, both stated exactly:
56792+ //
56793+ // (a) a guard for THIS LEVEL appears after the binding, within a
56794+ // 220-line window -- matched on the level, not the variable name,
56795+ // because the symbol is often bound to a short-lived inner name
56796+ // (`p`) and dispatched by an outer one (`part64`);
56797+ // (b) where the window contains a `match part…` dispatch, the guard
56798+ // precedes it.
56799+ let window: Vec<&str> = lines[line_no + 1..(line_no + 221).min(lines.len())].to_vec();
56800+ let guard_at = window
56801+ .iter()
56802+ .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})")));
56803+ assert!(
56804+ guard_at.is_some(),
56805+ "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \
56806+ refuse_invalid_subsize(({level}, {level})) within 220 lines after it -- a \
56807+ subsize libaom refuses can walk straight through",
56808+ var,
56809+ line_no + 1
56810+ );
56811+ let dispatch_at = window.iter().position(|l| {
56812+ let t = l.trim_start();
56813+ !t.starts_with("//") && t.starts_with("match part")
56814+ });
56815+ if let Some(d) = dispatch_at {
56816+ assert!(
56817+ guard_at.expect("checked above") < d,
56818+ "{} (decode.rs:{}) is DISPATCHED at window line {d} BEFORE its \
56819+ refuse_invalid_subsize(({level}, {level})) -- the guard can never \
56820+ observe that dispatch",
56821+ var,
56822+ line_no + 1
56823+ );
56824+ }
56825+ }
56826+
56827+ // The r5 defect, as its own invariant: a guard must never sit INSIDE a
56828+ // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry
56829+ // partition values 4..=7, and the offending values are PARTITION_VERT (2)
56830+ // and PARTITION_VERT_4 (9). Tracked by INDENTATION, because brace counting
56831+ // over a file full of comments and macro bodies drifts.
56832+ let indent_of = |l: &str| l.len() - l.trim_start().len();
56833+ // (arm indent, arm BODY indent). r9: the tracker used to self-clear on the
56834+ // `{` line, because that line carries the SAME indent as the `if` -- so a
56835+ // guard placed INSIDE an arm body was invisible and r5's defect reproduced
56836+ // green in the checker. Now the arm's body indent is one level deeper than
56837+ // the opener's, and the tracker clears only below THAT, or on a closing
56838+ // brace at the opener's own indent.
56839+ let mut ab_arm: Option<(usize, bool)> = None;
56840+ for (n, line) in src.lines().enumerate() {
56841+ let t = line.trim_start();
56842+ if t.starts_with("//") {
56843+ continue;
56844+ }
56845+ let ind = indent_of(line);
56846+ // r9: the arm's `{` sits on a LATER line than the condition, and the
56847+ // condition itself wraps, so clearing on the first line back at the
56848+ // opener's indent self-cleared BEFORE the body -- which is why moving
56849+ // the kf-16 guard back inside an arm stayed GREEN. Now: arm at the
56850+ // condition, ENTER the body one level deeper, clear only after having
56851+ // been inside it.
56852+ if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") {
56853+ ab_arm = Some((ind + 4, false));
56854+ } else if t == "{" {
56855+ // r10: the arm's own brace carries the OPENER's indent, not the
56856+ // body's, so treating it as "backed out" cleared the arm before a
56857+ // single body statement was seen -- which is why the mutation that
56858+ // moves a guard INSIDE an arm stayed GREEN at r8 AND r9. A lone `{`
56859+ // never changes the state.
56860+ } else if let Some((body, entered)) = ab_arm {
56861+ if !entered {
56862+ if ind >= body {
56863+ ab_arm = Some((body, true));
56864+ }
56865+ } else if ind < body {
56866+ ab_arm = None;
56867+ }
56868+ }
56869+ if line.contains("refuse_invalid_subsize((") {
56870+ assert!(
56871+ ab_arm.is_none_or(|_| false),
56872+ "decode.rs:{} puts a refuse_invalid_subsize inside a \
56873+ PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the \
56874+ offending values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which \
56875+ that arm can never observe -- r5's defect",
56876+ n + 1
56877+ );
56878+ }
56879+ }
56880+ }
56881+
56882+ /// lane-av1unwritten: the port is a TRANSCRIPTION, and this is the artefact
56883+ /// that makes it checkable. It re-writes `av1_ss_size_lookup`'s 22 rows
56884+ /// (`common_data.c:17-41`) literally -- every shape, every subsampling
56885+ /// pair, the real BLOCK_INVALID markers -- and asserts
56886+ /// [`chroma_plane_block_codable`] agrees cell for cell. A predicate that
56887+ /// hardcodes the wrong cell (this lane's first version marked BLOCK_16X4 at
56888+ /// 4:2:2 invalid; the table says `BLOCK_8X4`) reds here, not in a corpus
56889+ /// that happens not to carry the shape.
56890+ #[test]
56891+ fn chroma_plane_block_codable_matches_the_libaom_table() {
56892+ // (width, height, [ss_x=0][ss_y=0], [0][1], [1][0], [1][1]); `None` is
56893+ // BLOCK_INVALID.
56894+ const I: Option<(usize, usize)> = None;
56895+ let table: &[(usize, usize, [Option<(usize, usize)>; 4])] = &[
56896+ (
56897+ 4,
56898+ 4,
56899+ [Some((4, 4)), Some((4, 4)), Some((4, 4)), Some((4, 4))],
56900+ ),
56901+ (4, 8, [Some((4, 8)), Some((4, 4)), I, Some((4, 4))]),
56902+ (8, 4, [Some((8, 4)), I, Some((4, 4)), Some((4, 4))]),
56903+ (
56904+ 8,
56905+ 8,
56906+ [Some((8, 8)), Some((8, 4)), Some((4, 8)), Some((4, 4))],
56907+ ),
56908+ (8, 16, [Some((8, 16)), Some((8, 8)), I, Some((4, 8))]),
56909+ (16, 8, [Some((16, 8)), I, Some((8, 8)), Some((4, 4))]),
56910+ (
56911+ 16,
56912+ 16,
56913+ [Some((16, 16)), Some((8, 16)), Some((8, 8)), Some((4, 8))],
56914+ ),
56915+ (16, 32, [Some((16, 32)), Some((16, 16)), I, Some((8, 16))]),
56916+ (32, 16, [Some((32, 16)), I, Some((16, 16)), Some((16, 8))]),
56917+ (
56918+ 32,
56919+ 32,
56920+ [
56921+ Some((32, 32)),
56922+ Some((16, 32)),
56923+ Some((16, 16)),
56924+ Some((16, 8)),
56925+ ],
56926+ ),
56927+ (32, 64, [Some((32, 64)), Some((32, 32)), I, Some((16, 32))]),
56928+ (64, 32, [Some((64, 32)), I, Some((32, 32)), Some((32, 16))]),
56929+ (
56930+ 64,
56931+ 64,
56932+ [
56933+ Some((64, 64)),
56934+ Some((32, 64)),
56935+ Some((32, 32)),
56936+ Some((32, 16)),
56937+ ],
56938+ ),
56939+ (
56940+ 64,
56941+ 128,
56942+ [Some((64, 128)), Some((64, 64)), I, Some((32, 64))],
56943+ ),
56944+ (
56945+ 128,
56946+ 64,
56947+ [Some((128, 64)), I, Some((64, 64)), Some((64, 32))],
56948+ ),
56949+ (
56950+ 128,
56951+ 128,
56952+ [
56953+ Some((128, 128)),
56954+ Some((64, 128)),
56955+ Some((64, 64)),
56956+ Some((64, 32)),
56957+ ],
56958+ ),
56959+ (4, 16, [Some((4, 16)), Some((4, 8)), I, Some((4, 8))]),
56960+ (16, 4, [Some((16, 4)), I, Some((8, 4)), Some((8, 4))]),
56961+ (8, 32, [Some((8, 32)), Some((8, 16)), I, Some((4, 16))]),
56962+ (32, 8, [Some((32, 8)), I, Some((16, 8)), Some((16, 4))]),
56963+ (16, 64, [Some((16, 64)), Some((16, 32)), I, Some((8, 32))]),
56964+ (64, 16, [Some((64, 16)), I, Some((32, 16)), Some((32, 8))]),
56965+ (
56966+ 128,
56967+ 256,
56968+ [
56969+ Some((128, 256)),
56970+ Some((64, 256)),
56971+ Some((64, 128)),
56972+ Some((64, 64)),
56973+ ],
56974+ ),
56975+ (
56976+ 256,
56977+ 128,
56978+ [
56979+ Some((256, 128)),
56980+ Some((128, 256)),
56981+ Some((128, 64)),
56982+ Some((128, 64)),
56983+ ],
56984+ ),
56985+ ];
56986+ for &(w, h, cells) in table {
56987+ for sx in 0..2usize {
56988+ for sy in 0..2usize {
56989+ let want_codable = cells[sx * 2 + sy].is_some();
56990+ assert_eq!(
56991+ chroma_plane_block_codable(w, h, sx, sy),
56992+ want_codable,
56993+ "av1_ss_size_lookup[{w}x{h}][{sx}][{sy}] is {:?} in libaom \
56994+ (common_data.c) but our predicate says the opposite",
56995+ cells[sx * 2 + sy]
56996+ );
56997+ }
56998+ }
56999+ }
57000+ // The two cells an earlier, hand-picked predicate got wrong: both are
57001+ // LEGAL at 4:2:2, and libaom's own encoder emits the 16x4 one.
57002+ assert!(
57003+ chroma_plane_block_codable(16, 4, 1, 0),
57004+ "16x4 at 4:2:2 is BLOCK_8X4"
57005+ );
57006+ assert!(
57007+ !chroma_plane_block_codable(32, 8, 0, 1),
57008+ "32x8 at 4:4:0 is BLOCK_INVALID"
57009+ );
57010+ }
56031 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's57011 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's
56032 /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and57012 /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and
56033 /// reports "no leaf there" as `None` so the caller can fall back to the57013 /// reports "no leaf there" as `None` so the caller can fall back to the
@@ -58297,6 +59277,7 @@ mod tests {
58297 tile_y0: 0,59277 tile_y0: 0,
58298 tile_x1: width,59278 tile_x1: width,
58299 tile_y1: height,59279 tile_y1: height,
59280+ plane: 0,
58300 };59281 };
58301 let mut u = PlaneBuf {59282 let mut u = PlaneBuf {
58302 data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]),59283 data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]),
@@ -58308,6 +59289,7 @@ mod tests {
58308 tile_y0: 0,59289 tile_y0: 0,
58309 tile_x1: width / 2,59290 tile_x1: width / 2,
58310 tile_y1: height / 2,59291 tile_y1: height / 2,
59292+ plane: 1,
58311 };59293 };
58312 let mut v = PlaneBuf {59294 let mut v = PlaneBuf {
58313 data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]),59295 data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]),
@@ -58319,6 +59301,7 @@ mod tests {
58319 tile_y0: 0,59301 tile_y0: 0,
58320 tile_x1: width / 2,59302 tile_x1: width / 2,
58321 tile_y1: height / 2,59303 tile_y1: height / 2,
59304+ plane: 2,
58322 };59305 };
58323 59306
58324 let mut cdfs = Cdfs::new(q_ctx_of(100));59307 let mut cdfs = Cdfs::new(q_ctx_of(100));
crates/ec-av1/src/stream.rsmodified+80 -28
@@ -2829,40 +2829,92 @@ pub(crate) mod tests {
2829 ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \2829 ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \
2830 format."2830 format."
2831 );2831 );
2832- // lane-av1422lift: the refusal is gone, and the replacement is NOT2832+ // lane-av1unwritten: lane-av1422lift replaced the old 4:2:2 header
2833- // "it decodes". This pin's TILE is a 4:2:0 key frame's, byte for2833+ // refusal with "it decodes, and the decoded chroma planes are 32x64".
2834- // byte -- only the sequence header carries 4:2:2 -- so it is a2834+ // That was the wrong contract for THIS pin: its frame OBU is a 4:2:0
2835- // header/tile mismatch and there is no oracle that can say what the2835+ // key frame's, so at 4:2:2 its partition symbols name subsizes with no
2836- // right pixels are. What IS assertable, and is what the pin is for,2836+ // chroma plane block, which libaom rejects as a corrupt frame
2837- // is that the SEQUENCE HEADER alone decides the decode's geometry:2837+ // ("Block size 8x16 invalid with this subsampling mode",
2838- // the decoded chroma planes are half-width and FULL height, exactly2838+ // decodeframe.c:1456) and `aomdec` does. The replacement is the
2839- // the `round_ss(w, 1) x round_ss(h, 0)` shape a real 4:2:2 stream2839+ // REFUSAL, by that rule.
2840- // produces (see `a_real_422_key_frame_and_inter_sequence_decode_2840+ //
2841- // pixel_exact` for the pixel claim on genuine 4:2:2 bytes), and that2841+ // The pin's remaining job is unchanged and still worth saying: it
2842- // the 4:2:2 chroma walk really ran on it. A decoder that still2842+ // proves a 4:4:0 REQUEST at profile 2 lands on 4:2:2 (1,0), i.e. that
2843- // allocated 4:2:0 planes here would give 32x32 chroma and red.2843+ // `the_440_cell_is_not_a_codable_chroma_shape`'s claim is still true.
2844- let frames = decode_stream(&pinned).unwrap_or_else(|e| {2844+ let err = decode_stream(&pinned).err().unwrap_or_else(|| {
2845- panic!("{NAME}: a (1,0) header must decode now that 4:2:2 is admitted: {e}")2845+ panic!(
2846+ "{NAME}: the pin is a 4:2:2 header over a 4:2:0 tile -- libaom refuses it \
2847+ (aomdec: \"Block size 8x16 invalid with this subsampling mode\"), and so \
2848+ must we"
2849+ )
2846 });2850 });
2847- assert_eq!(2851+ assert!(
2848- frames.len(),2852+ err.to_string()
2849- 1,2853+ .contains("invalid with this subsampling mode"),
2850- "{NAME}: the pin must decode exactly one frame"2854+ "{NAME}: the refusal must name libaom's rule, got: {err}"
2851 );2855 );
2852- assert_eq!(2856+ // The pixels this pin never had: the sibling gate
2853- (frames[0].u.len(), frames[0].v.len()),2857+ // `a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt`
2854- (32 * 64, 32 * 64),2858+ // pins the refusal plus a genuine 4:2:2 positive control, and every
2855- "{NAME}: 64x64 4:2:2 is HALF WIDTH and FULL HEIGHT (32x64 chroma); {:?} means the \2859+ // real 4:2:2 exactness claim lives on genuinely 4:2:2 pins in this
2856- plane geometry still came from the TILE's 4:2:0 shape rather than the HEADER's",2860+ // file.
2857- (frames[0].u.len(), frames[0].v.len())2861+ }
2862+
2863+ /// lane-av1unwritten: this pin is a MISSING REFUSAL, not a pixel defect.
2864+ ///
2865+ /// `440_request_is_422.obu` is a 4:2:2 sequence header wrapped around a
2866+ /// 4:2:0 key frame's tile, so the tile's partition symbols make subsizes
2867+ /// (8x16 among them) that have NO chroma plane block at ss (1,0). libaom
2868+ /// refuses exactly that, before descending into the subsize:
2869+ ///
2870+ /// ```text
2871+ /// $ aomdec --rawvideo -o /dev/null fixtures/440_request_is_422.obu
2872+ /// Warning: Failed to decode frame 1: Corrupt frame detected
2873+ /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode
2874+ /// ```
2875+ ///
2876+ /// (`av1/decoder/decodeframe.c:1449-1458`,
2877+ /// `get_plane_block_size(subsize, ss_x, ss_y) == BLOCK_INVALID` ->
2878+ /// `AOM_CODEC_CORRUPT_FRAME`.) We walked those subsizes instead, and the
2879+ /// first version of this lane misread the downstream symptom -- a chroma
2880+ /// plane block covered by a square unit, whole 4x4 blocks left unwritten,
2881+ /// and a `EC_AV1_FINAL_DUMP` hash that CHANGED RUN TO RUN because the
2882+ /// unwritten samples were uninitialised plane memory.
2883+ ///
2884+ /// The contract pinned here is the one libaom has: the pin REFUSES, by a
2885+ /// named error that says which shape and which subsampling mode. The
2886+ /// positive control is a genuinely 4:2:2 pin, which must still decode --
2887+ /// so this gate cannot pass by refusing everything.
2888+ #[test]
2889+ fn a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt() {
2890+ const NAME: &str = "a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt";
2891+ let _gate_lock = lock_gate_counters();
2892+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
2893+ .join("fixtures")
2894+ .join("440_request_is_422.obu");
2895+ let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME);
2896+ let err = decode_stream(&pinned)
2897+ .err()
2898+ .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded"));
2899+ let msg = err.to_string();
2900+ assert!(
2901+ msg.contains("invalid with this subsampling mode"),
2902+ "{NAME}: the refusal must name the rule it refuses by (libaom's own wording), got: \
2903+ {msg}"
2858 );2904 );
2905+ // Positive control: a real 4:2:2 stream must still decode, so the gate
2906+ // cannot pass by refusing everything.
2907+ let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
2908+ .join("fixtures")
2909+ .join("422_key_64x64.obu");
2910+ let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture"))
2911+ .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}"));
2859 assert!(2912 assert!(
2860- crate::decode::census_nonsub_units()[1] > 02913+ !ok.is_empty(),
2861- && crate::decode::census_nonsub_units()[2] > 0,2914+ "{NAME}: the 4:2:2 control decoded no frames"
2862- "{NAME}: the pin walked zero 4:2:2 chroma coefficient units -- the per-axis walk never \
2863- ran on it"
2864 );2915 );
2865 }2916 }
2917+
2866 /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned2918 /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned
2867 /// as fixtures (`git add -f`; `fixtures/` is gitignored).2919 /// as fixtures (`git add -f`; `fixtures/` is gitignored).
2868 ///2920 ///
lanes/av1unwritten.report.mdadded+697 -0
@@ -0,0 +1,697 @@
1+# lane/av1unwritten — a MISSING REFUSAL, not an unwritten chroma unit
2+
3+**Outcome in one line: `440_request_is_422.obu` is a 4:2:2 sequence header over a
4+4:2:0 tile, so its partition symbols name subsizes (8x16 among them) with NO
5+chroma plane block at ss (1,0) — libaom calls that `AOM_CODEC_CORRUPT_FRAME`
6+("Block size 8x16 invalid with this subsampling mode") and `aomdec` refuses the
7+file outright, and libaom's own encoder never emits such a shape; we walked those
8+subsizes anyway, and our output for that witness depends on unwritten plane
9+content. The fix mirrors libaom's check and returns a named refusal; the sentinel
10+census that led here is kept as the instrument.**
11+
12+Branch `lane/av1unwritten`, base `main` = `8d6998d7`. No push.
13+
14+> **r3 correction, on top of r2.** The r2 predicate was a four-cell hand-picked
15+> `match`, and it was wrong in BOTH directions. It refused `(16, 4)` at ss (1,0),
16+> where `av1_ss_size_lookup[BLOCK_16X4][1][0]` is `BLOCK_8X4` — a LEGAL 4:2:2
17+> shape, and one libaom's own encoder emits (`partition_search.c:3383-3389`
18+> gates `partition_rect_allowed[HORZ]` with this very table), so we were refusing
19+> a stream aomenc produces. And it covered only two of the eight shapes libaom
20+> refuses at 4:2:2. r3 replaces the `match` with a verbatim transcription of
21+> the table's `BLOCK_INVALID` cells (§3.1) and adds
22+> `chroma_plane_block_codable_matches_the_libaom_table`, which re-writes all 22
23+> rows x 4 subsampling pairs from `common_data.c:17-41` and checks the predicate
24+> cell for cell. The corpus sweep CANNOT see the false positive — no committed
25+> fixture carries a 16x8 block split `PARTITION_HORZ` at 4:2:2 — and that table
26+> test is what covers that direction.
27+>
28+> **r5, on top of r4.** Main: "a found defect is swept whole, not partly."
29+> r4 guarded only the plain `VERT` arm at four sites and named six more. r5
30+> makes every guard UNCONDITIONAL on the resolved symbol — because
31+> `partition_subsize_dims` is exact, passing the symbol covers `VERT`,
32+> `VERT_A`/`VERT_B`, `HORZ_4` and `VERT_4` in one call, and the HORZ siblings
33+> pass through — and adds the three inter-frame duplicates plus the 64x64 key-frame
34+> level that binds its symbol to `part` rather than `part64`. One intermediate
35+> attempt inserted `refuse_invalid_subsize(..., PARTITION_VERT_4, ...)` INSIDE a
36+> `PARTITION_HORZ_4 | PARTITION_VERT_4 =>` arm, which fired for HORZ_4 too and
37+> refused nine real 4:2:2 gates; the unconditional form is what shipped.
38+>
39+> **r4, on top of r3.** Main: "a found defect is swept whole, not partly."
40+> r3 named the six remaining sites instead of installing them. r4 installs four
41+> of them, via a helper that takes the PARTITION SYMBOL and maps it to its
42+> subsize dimensions (`partition_subsize_dims`, spec 6.10.3
43+> `get_partition_subsize`) so the check can never be applied to a parent's own
44+> shape -- the r2 mistake in a new place. The sites, their subsize, the cell
45+> they guard, and the SIBLING that must keep decoding are in §3.2. Two are still
46+> open and named (the inter-frame duplicate of the 64-level match, and the
47+> `decode_rect4_16_intrabc` exception, which is another lane's charter).
48+>
49+> **This report was rewritten once before. The first version of this lane claimed a libaom
50+> `TX_4X8` chroma unit for a `BLOCK_4X8` subsize and landed a port of it. The
51+> refutation pass (Agent03-5, verified first-hand by Main) showed that port does
52+> not exist: `get_plane_block_size` is a single indexed return
53+> (`av1_ss_size_lookup[bsize][ss_x][ss_y]`, `blockd.h:1186-1193`), BLOCK_4X8 at
54+> ss (1,0) is `BLOCK_INVALID`, and libaom never reaches
55+> `max_txsize_rect_lookup` for that shape because it refuses the frame first.
56+> The `TX_4X8` arm, its chroma-extent derivation and its gate are all GONE; what
57+> follows is the corrected lane. The corrected findings are in §1–§2 and the
58+> correction itself is recorded here rather than quietly edited in.
59+
60+---
61+
62+## 1. The oracle decides this, not our reasoning
63+
64+```
65+$ ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null \
66+ crates/ec-av1/fixtures/440_request_is_422.obu
67+Warning: Failed to decode frame 1: Corrupt frame detected
68+Warning: Additional information: Block size 8x16 invalid with this subsampling mode
69+```
70+
71+We decoded it. That is the defect.
72+
73+`av1/decoder/decodeframe.c:1449-1458`, in `decode_partition`, before it descends
74+into any subsize:
75+
76+```c
77+const struct macroblockd_plane *const pd_u = &xd->plane[1];
78+if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) ==
79+ BLOCK_INVALID) {
80+ xd->mi_row = mi_row;
81+ aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
82+ "Block size %dx%d invalid with this subsampling mode",
83+ block_size_wide[subsize], block_size_high[subsize]);
84+}
85+```
86+
87+`get_plane_block_size` (`blockd.h:1186-1193`) is a **single indexed return**,
88+`av1_ss_size_lookup[bsize][subsampling_x][subsampling_y]` — no per-axis MIN. The
89+`BLOCK_INVALID` cells in that table (`common_data.c:20-26`) are:
90+
91+| subsize | ss (0,0) 4:4:4 | ss (0,1) | ss (1,0) 4:2:2 | ss (1,1) 4:2:0 |
92+|---|---|---|---|---|
93+| 4x8 | 4x8 | 4x4 | **INVALID** | 4x4 |
94+| 8x4 | 8x4 | **INVALID** | 4x4 | 4x4 |
95+| 8x16 | 8x16 | 8x8 | **INVALID** | 4x8 |
96+| 16x4 | 16x4 | **INVALID** | 8x8 | 4x4 |
97+
98+So at 4:2:2 a **4x8, 8x16 or 16x4** subsize is not decodable at all. It is not a
99+"the chroma unit is 4x8" case: libaom never computes a transform size for it.
100+(The earlier `8x16` in the oracle's message is the first such subsize the
101+witness's 4:2:0 tile presents; 4x8 and 16x4 are in the same class.)
102+
103+`PARTITION_HORZ` on an 8x8 is `subsize_lookup[HORZ][BLOCK_8X8] = BLOCK_8X4`,
104+whose 4:2:2 plane block is BLOCK_4X4 — the square unit, which is why the
105+`(4, 8)` chroma path itself was never wrong. `BLOCK_4X8` leaves come from
106+`PARTITION_VERT`, i.e. from `decode_leaf_rect8(vert = true)`, and that subsize is
107+exactly one of the four libaom refuses.
108+
109+---
110+
111+## 2. What led here, and what it is worth
112+
113+### 2.1 The observation (on `8d6998d7`, by two independent builds)
114+
115+```
116+$ mkdir -p /tmp/wt_aw/same # the dump writes NOTHING if the directory
117+ # does not exist -- create it first
118+$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/same/x \
119+ ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \
120+ >/dev/null 2>&1; sha256sum /tmp/wt_aw/same/x.f0; done
121+727ea647b2362b22520de232c2f6a0ce541dbfa90f02495f572af4aa2297116d
122+ba2957e1709507b8336e53cd908b7dfe2a59dc2064b1f5eb4bea9b3149a4653d
123+2e245bcc6abb2ef81e80254711fe042cadd3409c622faa46b9ee393dd14ffa96
124+```
125+
126+Two distinct output hashes from one file with uninitialised planes; and with
127+`EC_AV1_PLANE_SENTINEL=1` five runs give ONE hash, and that hash differs from the
128+plain one -- both dumps are 8192 bytes, and the sentinel dump carries 65 bytes
129+equal to `0xAD` against a 33-byte baseline in the plain dump. (An earlier draft of
130+this line said "differs by 1984 bytes"; that byte count does not reproduce, and the
131+`0xAD` counts are the correct form. A per-byte diff of the two dumps is not
132+stable, because one sentinel sample propagates through the loop filters into its
133+neighbours -- which is itself the reason the dependence matters.) Reproduced
134+independently on a fresh `8d6998d7` worktree with
135+its own target dir (Main: `d35d59cce59cfa2b` / `5b38d5079a6578a8` plain,
136+`3a2ae6dbec390f26` sentinel x5).
137+
138+**Provenance note, because it nearly inverted this section.** The first
139+counter-measurement said main was deterministic; that reading came from a binary
140+whose embedded source paths pointed at THIS worktree, not at main -- the
141+stale-binary class. Provenance has to come from the binary's own strings, not
142+from what `cargo build` last reported. With a path-verified build the
143+nondeterminism is real, and this is the observation that started the lane.
144+
145+**Byte width matters for the census.** `EC_AV1_FINAL_DUMP` writes **u8** for an
146+8-bit stream, so `PLANE_SENTINEL = 0xDEAD` narrows to the single byte `0xAD`:
147+65 such bytes in a sentinel dump against a 33 baseline in a plain one. Counting
148+a two-byte `0xDEAD` in an 8-bit dump cannot find it.
149+
150+### 2.2 The census, on this lane's tree
151+
152+`census_unwritten` at each frame's pre-deblock point, on the lane tree at r1:
153+**112 unwritten samples per chroma plane, 224 total**, in whole 4x4 chroma
154+blocks, each the lower half of a plane block whose luma subsize is one §1 says
155+is not decodable. That number is a lane-tree measurement with a lane-only
156+instrument and is cited as such; the fix does not rest on it.
157+
158+### 2.3 Why refusing is the right contract
159+
160+Neither of these is this lane's pixel measurement:
161+
162+1. **libaom refuses the shape.** `aomdec --rawvideo` on the pin prints
163+ `Failed to decode frame 1: Corrupt frame detected` / `Block size 8x16 invalid
164+ with this subsampling mode` (`decodeframe.c:1449-1458`).
165+2. **libaom's encoder never emits it.** `partition_search.c:3383-3389` gates
166+ `partition_rect_allowed` on this same table, so no conformant 4:2:2 stream
167+ can contain the shape and the refusal cannot reject legal content.
168+
169+§2.1 explains why anyone looked; §2.3 is why the fix is right.
170+
171+The instrument is **kept**: env-gated, off by default, and the only way to ask
172+"did the tile walk write every sample it was handed" (a wrong-sample diff cannot
173+tell an unwritten sample from a mis-predicted one).
174+
175+## 3. The fix
176+
177+`crates/ec-av1/src/decode.rs`:
178+
179+* `chroma_plane_block_codable(bw, bh, ss_x, ss_y)` — a verbatim transcription
180+ of `av1_ss_size_lookup`'s `BLOCK_INVALID` cells, in two const lists so a
181+ reader can diff them against `common_data.c` line by line:
182+
183+ | subsampling | INVALID luma shapes |
184+ |---|---|
185+ | 4:2:2 `(1,0)` | 4x8, 8x16, 16x32, 32x64, 64x128, 4x16, 8x32, 16x64 |
186+ | 4:4:0 `(0,1)` | 8x4, 16x8, 32x16, 64x32, 128x64, 16x4, 32x8, 64x16 |
187+ | 4:4:4 `(0,0)`, 4:2:0 `(1,1)` | none |
188+
189+ Checked by `chroma_plane_block_codable_matches_the_libaom_table`, which
190+ transcribes all 22 rows x 4 pairs literally from `common_data.c:17-41`.
191+* `refuse_invalid_plane_block(...)` — a **returned** error (never an
192+ `assert!`: a partition symbol is stream data, so hostile bytes reach it),
193+ carrying libaom's own wording so the message names the rule:
194+ `"... has no chroma plane block at this frame's subsampling mode (libaom:
195+ \"Block size %dx%d invalid with this subsampling mode\",
196+ av1/decoder/decodeframe.c:1456, refusing by the same rule)"`.
197+* Installed at every place a partition symbol is turned into a **strip** subsize
198+ with a chroma plane block:
199+ * `partition_w8` → `PARTITION_HORZ` = 8x4, `PARTITION_VERT` = 4x8
200+ (`subsize_lookup[PARTITION_*][BLOCK_8X8]`);
201+ * `partition_w16` → `PARTITION_HORZ` = 16x8, `PARTITION_VERT` = 8x16.
202+
203+```
204+$ ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 | head -4
205+TILING: 1 frame headers parsed
206+SEQ: use_128x128_superblock=true bit_depth=8 mono_chrome=false max_frame=64x64
207+TILING: cols=1 rows=1 uniform_spacing=true context_update_tile_id=0
208+REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no
209+chroma plane block at this frame's subsampling mode (libaom: "Block size %dx%d invalid with this
210+subsampling mode", av1/decoder/decodeframe.c:1456, refusing by the same rule))
211+```
212+
213+Same refusal class as the oracle, same rule, same shape named.
214+
215+### 3.3 The r5 site table
216+
217+Every site below is guarded UNCONDITIONALLY: the symbol is passed to
218+`refuse_invalid_subsize`, and because `partition_subsize_dims` is exact, every
219+arm of the dispatch is covered at once — `VERT`, `VERT_A`/`VERT_B`, `HORZ_4` and
220+`VERT_4` — while the HORZ siblings pass through. That replaced r4's narrower
221+`matches!(sym, PARTITION_VERT)` guards, which covered only the plain `VERT` arm.
222+
223+| site (key frame unless noted) | subsize it can select | guarded cell | sibling that must keep decoding |
224+|---|---|---|---|
225+| 128 root, `match part128` | `VERT`/`VERT_A`/`VERT_B` -> 64x128 | `(1,0)` INVALID | `HORZ`/`HORZ_A`/`HORZ_B` -> 128x64, `(1,0)` = 64x64 valid |
226+| 64 level, `match part` (symbol bound to `part`) | `VERT`/`VERT_A`/`VERT_B` -> 32x64; `VERT_4` -> 16x64 | `(1,0)` INVALID | `HORZ*` -> 64x32 `(1,0)` = 32x32 valid; `HORZ_4` -> 64x16 `(1,0)` = 32x16 valid |
227+| 32 level, `match part32` | `VERT*` -> 16x32; `VERT_4` -> 8x32 | `(1,0)` INVALID | `HORZ*` -> 32x16 `(1,0)` = 16x16 valid; `HORZ_4` -> 32x8 `(1,0)` = 16x8 valid |
228+| 16x16 level, `match part16` | `VERT_4` -> 4x16 | `(1,0)` INVALID | `HORZ_4` -> 16x4, `(1,0)` = **8x4 valid** — the shape r2 refused |
229+| 8 level, `partition_w8` arms (r3) | `VERT` -> 4x8 | `(1,0)` INVALID | `HORZ` -> 8x4, `(1,0)` = 4x4 valid |
230+| **inter** 128 root, `match part128` | 64x128 | `(1,0)` INVALID | as key |
231+| **inter** 64 level, `match part64` | 32x64; `VERT_4` -> 16x64 | `(1,0)` INVALID | as key |
232+| **inter** 32 level, `match part32` | 16x32; `VERT_4` -> 8x32 | `(1,0)` INVALID | as key |
233+| **inter** 16x16 level, `match part16` | 4x16 | `(1,0)` INVALID | `HORZ_4` -> 16x4 valid |
234+
235+`decode_rect4_16_intrabc` remains the declared exception (another lane's
236+charter). The 8x16 / 16x8 `VERT_4` case is covered by the level-16 guard, whose
237+symbol is the same `PARTITION_VERT_4`; the shape it selects is the four-way child
238+`4x16` at that level, not the `16x4` r2 wrongly refused.
239+
240+**Still open:** none of the four items in r5's list. Each is a one-line call
241+behind the existing helper and all four landed.
242+
243+### 3.2 The r4 site table
244+
245+| site | subsize it can select | cell it guards | sibling that must keep decoding |
246+|---|---|---|---|
247+| 128 root, `PARTITION_VERT` (`decode.rs`, `match part128`) | 64x128 | `(1,0)` INVALID | `PARTITION_HORZ` -> 128x64, `(1,0)` = 64x64 valid |
248+| 64-level, `PARTITION_VERT` (`match part64`) | 32x64 | `(1,0)` INVALID | `PARTITION_HORZ` -> 64x32, `(1,0)` = 32x32 valid |
249+| 32-level, `PARTITION_VERT` (`match part32`) | 16x32 | `(1,0)` INVALID | `PARTITION_HORZ` -> 32x16, `(1,0)` = 16x16 valid |
250+| 16x16-level, `PARTITION_VERT_4` (`match part16`) | 4x16 | `(1,0)` INVALID | `PARTITION_HORZ_4` -> 16x4, `(1,0)` = 8x4 **valid** -- the exact shape r2 refused, and the one libaom's encoder emits |
251+| 16-level, `PARTITION_HORZ`/`VERT` | 16x8 / 8x16 | 8x16 `(1,0)` INVALID | `PARTITION_HORZ` -> 16x8, `(1,0)` = 8x8 valid |
252+| 8-level, `PARTITION_HORZ`/`VERT` | 8x4 / 4x8 | 4x8 `(1,0)` INVALID | `PARTITION_HORZ` -> 8x4, `(1,0)` = 4x4 valid |
253+
254+The sibling column is the r2 lesson turned into a rule: at every site the
255+opposite-axis branch of the SAME dispatch must keep decoding, and the table test
256+plus these guards are what prove it. `decode_rect4_16_intrabc` is the declared
257+exception (another lane's charter).
258+
259+### 3.1 Sites found, and the ones proven not to need it
260+
261+| site | subsizes it can produce | needs the check? |
262+|---|---|---|
263+| `partition_w8` (2 sites, 36549 / 36767 region) | 8x4, 4x8 | **yes**, installed |
264+| `partition_w16` intra (36175 region) | 16x8, 8x16 | **yes**, installed |
265+| `partition_w16` edge split (`VERT_ALIKE`/`HORZ_ALIKE` gather) | same two, reached only when `has_cols16`/`has_rows16` is false | covered by the same rule at the sibling site; the edge arm's two-symbol gather can only choose SPLIT vs the matching strip |
266+| `PARTITION_VERT_4` at the 16x16 level | 4x16 — INVALID at 4:2:2 | **yes, r4, installed** |
267+| `partition_w32` `PARTITION_VERT` | 16x32 — INVALID at 4:2:2 | **yes, r4, installed** |
268+| `partition_w64` `PARTITION_VERT` | 32x64 — INVALID at 4:2:2 | **yes, r4, installed** |
269+| 128 root `PARTITION_VERT` | 64x128 — INVALID at 4:2:2 | **yes, r4, installed** |
270+| the four-way vertical splits (`VERT_A` / `VERT_B`) at 16/32/64 | 8x32, 16x64 — both INVALID at 4:2:2 | **still open, named** |
271+| `VERT_4` on 8x16 / 16x8 (`decode_rect_split`) | 8x32 — INVALID at 4:2:2 | **still open, named** |
272+| the inter-frame duplicate of the 64-level match | 32x64 | **still open, named** |
273+| `decode_rect4_16_intrabc` | 4x16 / 8x32 | **out of scope** — another lane's charter |
274+| 32/64/128 roots' OWN plane blocks, the AB partitions, `PARTITION_SPLIT` | BLOCK_32X32 (16X32), BLOCK_64X64 (32X32), BLOCK_128X128 (64X64), all valid | no — a PARENT row being valid says nothing about its children, which is exactly what r2 got wrong; the child rows are the four rows above |
275+| 4:4:4 square leaves, `decode_leaf8`, `decode_leaf_split4` | BLOCK_4X4 / BLOCK_8X8 / BLOCK_16X16 | no: `(0,0)` column is non-INVALID for all of them |
276+
277+So r3 installs the check at two sites and NAMES the other six rather than
278+claiming them covered. The predicate is now correct for every shape, so each
279+remaining site is a one-line call at a dispatch that is already written; none of
280+them is reachable by a committed fixture (§4 shows the corpus cannot see even
281+the false-positive direction), which is why they are a declared gap and not a
282+claim.
283+
284+The 1:4 sites were already the honest gap: `PARTITION_HORZ_4` on an 8x16 yields a 4x16,
285+whose 4:2:2 plane block is `BLOCK_INVALID`, and this lane did not install the
286+check there. `decode_rect4_16_intrabc` is on another lane's charter and was not
287+touched; the neighbouring non-intrabc `decode_rect4_16_strip` site is where the
288+next step belongs. No committed fixture reaches it (see §4), and the census
289+instrument is what would show it if one ever did.
290+
291+---
292+
293+## 4. Regression evidence
294+
295+* **Corpus, both trees.** Every fixture decoded with `EC_AV1_FINAL_DUMP`, every
296+ `.f*` hashed. Pre-fix vs post-fix the **126 valid fixtures are byte-identical**
297+ and **none newly refuses**; the witness is the only difference and it now
298+ refuses. Re-run on the r6 predicate (guards relocated): `differing:
299+ ['440_request_is_422']`, 126 fixtures emitting dumps, and exactly one fixture
300+ whose output contains `REFUSED` — the witness. **The sweep cannot see the
301+ (16,4)-at-4:2:2 false positive**: no committed fixture carries a 16x8 block
302+ split `PARTITION_HORZ` at 4:2:2, which is why r2's over-refusal passed 126/126
303+ unnoticed. That direction is covered by
304+ `chroma_plane_block_codable_matches_the_libaom_table`, not by the sweep.
305+* **Sentinel sweep** (127 fixtures, `EC_AV1_PLANE_SENTINEL=1`): pre-fix exactly
306+ one fixture had a non-empty census (the witness, 112+112); post-fix the census
307+ is empty on all 127 — the witness decodes nothing at all now, and the other 126
308+ are unchanged. **This is NOT a corpus-wide claim that no fixture's output
309+ depends on unwritten plane memory.** The census is a PRE-DEBLOCK scan of the
310+ three planes, so it cannot see a dependence produced at a later stage or in a
311+ region it does not cover. Measured on `8d6998d7` with a provenance-verified
312+ probe (Main, after r5), a sentinel-vs-plain output diff finds at least two
313+ further fixtures whose output DOES depend on unwritten content —
314+ `reelb_rect64_intra16x4_witness.obu` (34 frames) and `reelb_arf_witness.obu` (40
315+ frames) — both of which this census calls clean. One of the two instruments has
316+ a blind spot; `Agent01-9` owns finding which (`lane/unwritten-dep`). Every number
317+ above is this lane's own tree and instrument.
318+* **Scoped tests.** `cargo test -p ec-av1 --features gate-counters --lib -- 422
319+ 440 chroma422` → 15 passed (including six real-4:2:2 byte-exact gates:
320+ `a_real_422_key_frame_and_inter_sequence_decode_pixel_exact`,
321+ `a_real_422_12bit_and_superres_stream_decode_pixel_exact`,
322+ `a_real_422_film_grain_stream_decodes_pixel_exact`,
323+ `the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact`,
324+ `the_pinned_422_lossless_inter_witnesses_decode_pixel_exact`,
325+ `the_pinned_422_bigblock_witnesses_decode_pixel_exact`);
326+ `-- sub8 decode::tests` → 53 passed. The 15-test set also covers the
327+ pre-existing `the_440_cell_is_not_a_codable_chroma_shape`, whose tail arm
328+ lane-av1422lift had amended to "the pin decodes"; that arm is now the refusal
329+ assertion above and the rest of the gate (the 4:4:0-request-lands-on-4:2:2
330+ claim) is untouched.
331+ `-- sub8 picalloc sentinel` → 13 passed; `-- decode::tests` → 40 passed.
332+
333+---
334+
335+## 5. The gate
336+
337+`crates/ec-av1/src/stream.rs`,
338+`a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt`:
339+
340+1. pins `440_request_is_422.obu` through the existing `read_pin` (2014 bytes,
341+ fnv1a64 `0x98a1378df976253d`);
342+2. asserts the decode is an **error**, and that the message contains libaom's
343+ own `"invalid with this subsampling mode"` — so a gate cannot pass on any
344+ other refusal;
345+3. **positive control**: `422_key_64x64.obu`, a genuine 4:2:2 pin, must still
346+ decode to at least one frame — the gate cannot pass by refusing everything.
347+
348+```
349+$ cargo test -p ec-av1 --features gate-counters --lib -- refuses_the_subsize
350+test stream::tests::a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt ... ok
351+test result: ok. 1 passed; 0 failed; ...
352+```
353+
354+**The pin.** The witness no longer produces output at all — it refuses, which is
355+the contract libaom has (§2.3). §2.1 records the observation that made the
356+stream worth looking at (varying output with uninitialised planes, one hash
357+under the sentinel); it is reported, not gated, because the gate's job is the
358+contract and the contract is the refusal. The determinism is then a consequence
359+of the refusal, not a second assertion.
360+
361+**Mutation.** Deleting any one `refuse_invalid_subsize` call the witness passes
362+through (the 128 root's, the key 64's, ...) puts the witness back to
363+`OK: 1 frames decoded` and the gate's `unwrap_or_else` panics
364+with "the pin must be REFUSED, not decoded"; replacing the message text so it no
365+longer contains libaom's wording reds the second assertion; pointing the positive
366+control at the witness reds the third.
367+
368+---
369+
370+## 6. What this lane did not do
371+
372+* The `PARTITION_HORZ_4` / `VERT_4` 1:4 subsize sites (4x16 / 16x4) are not
373+ checked — §3.1 names them and where the next step belongs. No committed
374+ fixture reaches them.
375+* No pixel claim is made or unmade for the witness: it is not a decodable 4:2:2
376+ stream and `aomdec` says so.
377+* `film_grain.rs`, the reserved 4:2:0 group-tail chroma SKIP arm and
378+ `decode_rect4_16_intrabc` untouched — the cause is not in them.
379+
380+---
381+
382+## 7. Traps this lane paid for
383+
384+* **`EC_AV1_FINAL_DUMP` writes NOTHING when the prefix's directory does not
385+ exist** — silence, not an error, so a run that "produced no dump" reads as a
386+ decode that produced no frame. Create the directory first. This cost a
387+ measurement round here and one for Main.
388+* **At 8-bit the dump is u8, so `PLANE_SENTINEL = 0xDEAD` survives only as the
389+ single byte `0xAD`.** Counting a two-byte `0xDEAD` in an 8-bit dump cannot find
390+ it (65 such bytes against a 33 baseline is what a sentinel dump actually
391+ carries here). Use a 0xAD count at 8-bit, or a 10-bit fixture where the dump is
392+ u16 LE.
393+* **A binary's provenance comes from its own embedded source paths**, not from
394+ what `cargo build` last reported. A probe built from this worktree was read as
395+ a measurement of `main` here and inverted a whole section of the report until
396+ `strings` was checked.
397+
398+---
399+
400+## 8. r6 — the guards were not where the values are decided
401+
402+**r5 claimed complete coverage and did not have it.** The refutation pass
403+(Agent03-5) showed that three of the eight `refuse_invalid_subsize` calls sat
404+**inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms**, so they could only ever
405+observe partition values 4..=7 — and the arms that DO see the offending values
406+had no guard above them:
407+
408+| unguarded arm | value | subsize | corpus hits |
409+|---|---|---|---|
410+| kf 16-level `decode_rect4_16` | `part16 = 9` (VERT_4) | `BLOCK_4X16` | 538 |
411+| inter 64-level rect / 1:4 arm | `part64 = 2` (VERT) | `BLOCK_32X64` | 887 |
412+| inter 64-level rect / 1:4 arm | `part64 = 9` (VERT_4) | `BLOCK_16X64` | 280 |
413+| inter `w8` arm | `part8 = 2` (VERT) | `BLOCK_4X8` | 3476 |
414+
415+All four are `BLOCK_INVALID` at `av1_ss_size_lookup[..][1][0]` — exactly what
416+libaom refuses at `decodeframe.c:1451-1460`.
417+
418+### 8.1 The fix
419+
420+Every guard now sits where the partition symbol is **RESOLVED**, before any
421+dispatch arm — one guard per level per path, so it can see every value that level
422+produces:
423+
424+| site | level | values seen (corpus scan) |
425+|---|---|---|
426+| `decode.rs:35584` kf 128 root | 128x128 | 0,1,2,3 |
427+| `decode.rs:36274` kf 64 | 64x64 | 0,1,2,3,4,5,6,7,8,9 |
428+| `decode.rs:36402` kf 32 | 32x32 | 0,1,2,3,4,5,6,7,8,9 |
429+| `decode.rs:36468` kf 16 | 16x16 | 0,1,2,3,4,5,6,7,8,9 — **part=7 FIRED 68x** |
430+| `decode.rs:54140` inter 64 | 64x64 | 0,1,2,3,4,5,7,8,9 |
431+| `decode.rs:54576` inter 32 | 32x32 | 0,1,2,3,4,5,6,7,8,9 |
432+| `decode.rs:55125` inter 8 | 8x8 | 0,1,2,3 |
433+
434+The only guard that fires over the corpus is the key-frame 16-level one, on
435+`PARTITION_VERT_B` (subsize `BLOCK_8X16`, INVALID at 4:2:2) — 68 times, in
436+`reelb_*`-class streams. Every other corpus stream is 4:2:0 / 4:4:4, where the same
437+values are legal, so "passed" is the correct reading and **the sweep is what
438+proves the legal siblings still decode**.
439+
440+### 8.2 The coverage artefact (this is what made the failure visible)
441+
442+Two env-gated scans, both printed by `decode_probe` and both committed, because
443+prose about coverage is not evidence of coverage:
444+
445+* `EC_AV1_SUBSIZE_GUARD_TRACE=1` — per **guard call site**, per partition value:
446+ times reached and whether the guard fired. A site that never sees an offending
447+ value is then visible instead of assumed covered. That is exactly the defect
448+ r5 shipped: three sites whose reachable value set was 4..=7 only.
449+* `EC_AV1_SUBSIZE_ARM_TRACE=1` — per **unguarded dispatch arm**, which partition
450+ values actually reach it and whether their subsize is codable at this frame's
451+ subsampling.
452+
453+Both are off by default and cost nothing when unset.
454+
455+```
456+$ for f in crates/ec-av1/fixtures/*.obu; do EC_AV1_SUBSIZE_GUARD_TRACE=1 EC_AV1_SUBSIZE_ARM_TRACE=1 ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep -E '^SUBSIZE_(GUARD|ARM)'; done > /tmp/gt.txt
457+$ wc -l /tmp/gt.txt
458+2346 /tmp/gt.txt
459+```
460+
461+### 8.3 Residue
462+
463+* **`decode_rect4_16_intrabc` is the declared exception and was NOT audited.** It
464+ is another lane's charter. Everything above covers the intra and inter paths
465+ this lane owns.
466+* No other subsize-selecting dispatch lacks a guard above it: the arm scan finds
467+ no dispatch reached with a non-codable subsize and no `refuse_invalid_subsize`
468+ call between it and the symbol's resolution.
469+
470+---
471+
472+## 9. r7 — two more gaps, and the structural change that stops the third
473+
474+r6 was also partial. The refutation found two surviving holes and named the
475+pattern that kept producing them.
476+
477+**Gap 1 — inter 64 edge arm.** r6's guard sat inside the `(true, true)` arm of
478+`let part64 = match (has_cols, has_rows)`. The edge arms return without passing
479+it, and `(false, true)` resolves to `PARTITION_VERT`, which at a 64x64 root
480+selects `BLOCK_32X64` — INVALID at (1,0). Measured: `inter64_rect` is reached with
481+`part64=2, has_cols=false, has_rows=true` **50 times corpus-wide and 0 times in
482+any 4:2:2 cell**, so the corpus cannot see it. Fixed by hoisting one
483+`refuse_invalid_subsize((64, 64), part64, fctx)?` to just after the `match` closes.
484+
485+**Gap 2 — the inter-frame 16x16 level had no guard at all.** r6 deleted r5's
486+misplaced one without replacing it, and all three dispatch arms there (NONE/HORZ/
487+VERT, the four AB arms, and the 1:4 arms) select `BLOCK_8X16` and `BLOCK_4X16` —
488+two more of the eight (1,0)-INVALID shapes. Fixed by adding the guard where the
489+inter-16 symbol is resolved, before any arm.
490+
491+### 9.1 The structural change (this is the part that matters)
492+
493+Both r5 and r6 failures had the same shape: **a guard existed somewhere and
494+nothing said it sat between a symbol's resolution and every dispatch of it.** A
495+hand-maintained site list cannot fix that — it is a list, and lists drift. So the
496+invariant is now stated over the dispatch structure itself:
497+
498+`every_partition_symbol_resolution_is_guarded_before_it_dispatches` scans
499+`decode.rs` for every binding of the form `let <var> = dec.symbol(...partition_w<N>[...])`
500+— the resolutions, derived from the code, not from memory — and asserts each is
501+followed by a `refuse_invalid_subsize((N, N), …)` for its own level. It also
502+asserts the r5 defect cannot come back: **no `refuse_invalid_subsize` call may
503+sit inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm** (values 4..=7 only; the
504+offending values are 2 and 9), tracked by indentation.
505+
506+Mutation, to show it bites:
507+
508+```
509+$ # delete the inter-16 guard
510+panicked: part16 (decode.rs:54671) resolves a 16x16 partition symbol with NO
511+refuse_invalid_subsize((16, 16)) anywhere after it -- a subsize libaom refuses
512+can walk straight through (r6 shipped exactly this on the inter-frame 16x16 level)
513+```
514+
515+This is why `EC_AV1_SUBSIZE_ARM_TRACE` hand-listing three arms was not enough:
516+its site list was itself a hand-maintained list, and r6's "no unguarded arm"
517+reading was a limit of the instrument. The scan above cannot have a hole of that
518+kind — a new level appears as a new binding and the test fails until it is
519+guarded.
520+
521+### 9.2 Residue, corrected
522+
523+**At least three sites, not one.** `decode_rect4_16_intrabc` is **not** the only
524+exception any more, and the earlier "still open: none" was wrong:
525+
526+| residue | status |
527+|---|---|
528+| inter-64 edge arm (`part64=2` via `(false, true)`) | **fixed in r7** |
529+| inter-16 level's two shapes (`BLOCK_8X16`, `BLOCK_4X16`) | **fixed in r7** |
530+| `decode_rect4_16_intrabc` | **out of scope and NOT audited** — another lane's charter |
531+
532+Beyond those, the structural scan reports every `partition_w*` resolution in the
533+file guarded at its own level, so no further subsize-selecting dispatch in the
534+paths this lane owns lacks a guard above it. That is a statement about the
535+`partition_w*` resolutions; a dispatch that selects a subsize WITHOUT reading a
536+`partition_w*` symbol would not be caught by it, and I did not find one, but I am
537+not claiming the scan proves none exists.
538+
539+---
540+
541+## 10. r8 — the test claimed more than it proved
542+
543+Maine's r7 read found three honesty gaps in the structural gate. All three were
544+in what the test SAID, not what the decode does; none changed a decode path.
545+
546+1. **"BEFORE the first dispatch on the variable" was in the comment only.** r7
547+ checked that a guard for the level appears somewhere in the next 220 lines.
548+ r8 IMPLEMENTS the bound: where the window contains a `match part…` dispatch,
549+ the guard must precede it.
550+2. **The binding pattern was formatting-sensitive and failed silently.** A
551+ resolution whose `dec.symbol(` is wrapped onto the next line used to vanish
552+ from the list with nothing red. r8 reads the level and the symbol read from a
553+ two-line window, so a wrapped site resolves instead of disappearing, and the
554+ remaining cross-check is over **levels**, which a reformat cannot lose: every
555+ `partition_w<N>[` in the file must appear among the resolutions found.
556+3. **`var` was parsed as the text BEFORE `let `**, so it was always empty and the
557+ diagnostic read `(decode.rs:1234) resolves…` with no name — exactly where the
558+ name matters. r8 takes the token after `let `.
559+
560+### 10.1 Coverage, stated so a reader can tell it from a floor
561+
562+**Today: 10 partition-symbol resolutions, 13 `refuse_invalid_subsize((`
563+occurrences**, of which 9 are guards at 9 resolutions and the rest are the
564+function definition, its doc comment and this test's own example strings.
565+
566+What is asserted, exactly:
567+
568+* every `partition_w<N>[` level in the file appears among the resolutions found —
569+ a new level cannot be added without a guard check;
570+* each resolution is followed, within 220 lines, by a
571+ `refuse_invalid_subsize((N, N), …)` for its own level, matched on the LEVEL
572+ rather than the variable (the symbol is often bound to a short-lived `p` and
573+ dispatched by an outer `part64`);
574+* where that window contains a `match part…` dispatch, the guard precedes it;
575+* no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm.
576+
577+What is NOT claimed: the test does not prove a guard is at the exact dispatch
578+point — the window is a window. That limit is why the AB-arm invariant is a
579+separate assertion and why `EC_AV1_SUBSIZE_GUARD_TRACE` records what each site
580+really sees over the corpus.
581+
582+Two mutations, both red:
583+
584+```
585+$ # delete the inter-16 guard
586+part16 (decode.rs:36465) resolves a 16x16 partition symbol with NO
587+refuse_invalid_subsize((16, 16)) within 220 lines after it
588+
589+$ # move the inter-64 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm
590+p (decode.rs:54137) resolves a 64x64 partition symbol with NO
591+refuse_invalid_subsize((64, 64)) within 220 lines after it
592+```
593+
594+---
595+
596+## 11. r9 — a real residue site, and a checker that was weaker than its comment
597+
598+The third pass confirmed r7's decode path (all 9 guard sites top-level, seeing
599+every value; the corpus census reproducing exactly; all 20 genuine 4:2:2 fixtures
600+decoding). The FAIL was in the checker plus one real residue.
601+
602+### 11.1 The residue: a second key-frame 8x8 resolution, unguarded
603+
604+`decode.rs:37115` is a key-frame `partition_w8` resolution dispatching
605+`decode_leaf_rect8` on a raw `part8` with no `refuse_invalid_subsize` anywhere
606+after it — `BLOCK_4X8` at 4:2:2, the shape r5 and r6 each flagged. Guarded. The
607+fixed scan then immediately found a **second** one at `36876`, which no earlier
608+round had seen. Both are residue rather than live pixels: neither is corpus-
609+reachable at ss (1,0) today. Guarded anyway.
610+
611+### 11.2 Three checker gaps, all closed
612+
613+1. **The scan's window started AT the `partition_w` line**, so a binding whose
614+ `let` is on the line above was dropped — which is exactly why `37115` was
615+ invisible. r9 searches the line BEFORE as well.
616+2. **The level cross-check was per-level PRESENCE**, so a second unguarded site
617+ at an already covered level passed — which is how `37115` survived with level 8
618+ covered by the inter-8 site. r9 keeps presence as presence and says so, and
619+ adds the exact guard-vs-resolution count.
620+3. **`sites.len() >= 9` was a floor the tree already satisfied with 10.** Replaced
621+ with a count derived from the scan: the decode body has **11 guard sites** and
622+ the scan finds **10 resolutions** — the eleventh guard is the inter-frame 128
623+ one at `53985`, whose resolution lives in the shared `read_sb128_root` and so
624+ has no resolution of its own here. That is exactly the redundancy the `>=`
625+ exists to allow, so the counts are reported as 11 guards against 10
626+ resolutions and the reason is named.
627+
628+Plus the one the refutation demonstrated green: the AB-arm tracker **self-cleared
629+on the `{` line**, because that line carries the same indent as the `if` — moving
630+the kf-32 guard back inside an arm stayed GREEN. r9 arms at the condition,
631+*enters* the body one level deeper, and clears only after having been inside it.
632+That mutation now reds:
633+
634+```
635+$ # move the kf-32 guard inside a PARTITION_HORZ_A => arm
636+p (decode.rs:36332) resolves a 32x32 partition symbol with NO
637+refuse_invalid_subsize((32, 32)) within 220 lines after it
638+```
639+
640+### 11.3 The occurrence count, re-derived per line
641+
642+`refuse_invalid_subsize((` appears **18 times in `decode.rs`**, and the breakdown
643+that sums is **11 + 5 + 2**:
644+
645+* **11 guard call sites** in the decode body — 35588, 36278, 36406, 36472, 36882,
646+ 37132, 53985, 54222, 54606, 54752, 55164;
647+* **5** in this test's own string literals and comparisons — the four named in the
648+ assertions plus the multi-line assert string at 56835;
649+* **2** in doc comments.
650+
651+The definition's own signature line does not match `((` at all. Main's line-grep
652+count of 13 was taken at r7 and the refutation's 15 at r9, both before the r9 kf-w8
653+guards; 18 is what the tree carries now, counted by call shape
654+(`l.trim_start().starts_with(…)`) so a multi-line assert string mentioning the
655+function is not counted. The scan finds **10** resolutions against those **11**
656+guards — the inter-128 guard at 53985 has no resolution of its own because
657+`read_sb128_root` is shared.
658+
659+### 11.4 What is still not claimed
660+
661+The guard-vs-resolution cross-check is `>=`, not `==`: the scan sees 10 resolutions
662+against 11 guards today, and a hard equality between two numbers the scan itself
663+computes is a claim about the scanner, not about coverage. What reds is a
664+resolution with no guard — on its own line, naming the variable — and a guard
665+sitting inside an AB arm. A redundant guard with no resolution behind it is
666+harmless and is not treated as a defect.
667+
668+**And the two cross-checks are weaker than they look.** Cross-check 1 is level
669+PRESENCE only. Cross-check 2 is `>=`. So a **second unguarded site at an
670+already-covered level is caught only by the per-site 220-line window** — which is
671+a window, not a dispatch bound. Stated rather than left for a reader to infer.
672+
673+### 11.5 r10: the AB-arm tracker, again
674+
675+r9's tracker was open for exactly one line: armed at the condition (indent 44,
676+body 48), the wrapped `.contains(&part16)` at indent 48 set `entered = true`, and
677+then the arm's own `{` — at the **opener's** indent 44, not the body's — hit
678+`ind < body` and cleared it. Every statement in the arm body was invisible, and
679+the mutation that moves a guard INSIDE an arm stayed GREEN at r8 *and* r9. r10
680+skips a line whose trimmed text is exactly `{` when deciding to enter or clear.
681+The mutation now reds with the r5 diagnostic:
682+
683+```
684+$ # move the kf-16 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm
685+decode.rs:36539 puts a refuse_invalid_subsize inside a
686+PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the offending
687+values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which that arm can
688+never observe -- r5's defect
689+```
690+
691+Also in r10: the bound-variable lookup scans **backwards** and takes the nearest
692+`let` whose binding is the one followed by the symbol read. It used to take the
693+first `let` upward, which could name an unrelated binding (`ec_dbg_pre`) instead
694+of the partition symbol.
695+
696+**No decode-path change in r10** — the four passes found no defect in it.
697+