forge
Explore
Log in

Don't you dare go Hollow

lane-av1unwritten r7: the last two holes, and the structural check that stops the third

Browse files at this commit

b8a900300edd2c47ed7053dffc3f115e414b6151Ahmet Kaan GümüşParent: 6eedd60
Two gaps survived r6, both measured by the refutation with its own build.

Gap 1 -- inter 64 edge arm. r6's guard sat inside the (true, true) arm of
`let part64 = match (has_cols, has_rows)`; the edge arms return without passing
it, and (false, true) resolves to PARTITION_VERT, which at a 64x64 root selects
BLOCK_32X64 -- INVALID at (1,0). Measured 50 corpus-wide reaches and 0 in any
4:2:2 cell, so the corpus cannot see it. Hoisted one
refuse_invalid_subsize((64, 64), part64, fctx)? to just after the match closes.

Gap 2 -- the inter-frame 16x16 level had NO guard at all: r6 deleted r5's
misplaced one without replacing it, and all three dispatch arms there (NONE/HORZ/
VERT, the four AB arms, the 1:4 arms) select BLOCK_8X16 and BLOCK_4X16, two more
of the eight (1,0)-INVALID shapes. Guard added where that symbol is resolved.

Structural change, because r5 and r6 failed the same way -- a guard existed
somewhere and nothing said it sat between a symbol's RESOLUTION and every dispatch
of it. New gate
every_partition_symbol_resolution_is_guarded_before_it_dispatches derives the
site list from the code itself (every `let <var> = dec.symbol(...partition_w<N>
[...]` binding) rather than from memory, requires a refuse_invalid_subsize((N, N))
for each one's own level, and separately asserts the r5 defect cannot return: no
guard may sit inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm, tracked by
indentation. Mutation shown: deleting the inter-16 guard reds it with
"part16 (decode.rs:54671) resolves a 16x16 partition symbol with NO
refuse_invalid_subsize((16, 16)) anywhere after it".

That is also why EC_AV1_SUBSIZE_ARM_TRACE's hand-listed three arms was not enough:
its site list was a list. The scan above cannot have that hole -- a new level
appears as a new binding and the test fails until it is guarded.

Residue corrected: at least three sites, not one. The inter-64 edge arm and the
inter-16 shapes are fixed; decode_rect4_16_intrabc remains out of scope and NOT
AUDITED (another lane's charter). The report no longer says intrabc was the only
exception, and states the limit of the scan: it covers partition_w* resolutions,
and a dispatch selecting a subsize without reading such a symbol would not be
caught by it.

r7: 30 tests green. Corpus scan 2750 lines, exactly one guard firing
(16x16 part=7, PARTITION_VERT_B -> BLOCK_8X16). The witness refuses; a genuine
4:2:2 pin still decodes (422_key_64x64 -> OK: 1 frames decoded, 64x64).
crates/ec-av1/src/decode.rsmodified+125 -1
@@ -54140,7 +54140,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54140 // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY54140 // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY
54141 // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings54141 // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings
54142 // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol.54142 // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol.
54143- refuse_invalid_subsize((64, 64), p, fctx)?;
54144 54143
54145 if crate::envflags::env_flag!("EC_AV1_TRACE") {54144 if crate::envflags::env_flag!("EC_AV1_TRACE") {
54146 eprintln!(54145 eprintln!(
@@ -54193,6 +54192,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54193 PARTITION_SPLIT54192 PARTITION_SPLIT
54194 }54193 }
54195 };54194 };
54195+ // lane-av1unwritten r7: the symbol is RESOLVED (a full CDF
54196+ // read or an edge `gather`) and about to be dispatched, so the
54197+ // check sits HERE rather than inside the (true, true) arm: the
54198+ // edge arms return without passing it, and (false, true)
54199+ // resolves to PARTITION_VERT, which on a 64x64 root selects
54200+ // BLOCK_32X64 -- INVALID at (1,0) and unreachable from the
54201+ // corpus (measured: 50 reaches corpus-wide, 0 in any 4:2:2 cell).
54202+ // r6 had this inside the (true, true) arm, where it could not
54203+ // see it.
54204+ refuse_invalid_subsize((64, 64), part64, fctx)?;
54196 if part64 == PARTITION_NONE {54205 if part64 == PARTITION_NONE {
54197 // lane-inter8 r1: the whole superblock as one 64x64 inter54206 // lane-inter8 r1: the whole superblock as one 64x64 inter
54198 // block. `SB`-sized syntax throughout (size_group 3, same as54207 // block. `SB`-sized syntax throughout (size_group 3, same as
@@ -54714,6 +54723,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54714 }54723 }
54715 }54724 }
54716 };54725 };
54726+ // lane-av1unwritten r7: the inter-frame 16x16
54727+ // level had NO guard at all -- r6 dropped r5's
54728+ // misplaced one without replacing it, and all three
54729+ // dispatch arms below (NONE/HORZ/VERT, the four AB
54730+ // arms, and the 1:4 arms) select BLOCK_8X16 and
54731+ // BLOCK_4X16, two of the eight (1,0)-INVALID shapes.
54732+ // The check goes where the symbol is RESOLVED, so
54733+ // every arm is covered by construction.
54734+ refuse_invalid_subsize((16, 16), part16, fctx)?;
54717 if part16 == PARTITION_NONE {54735 if part16 == PARTITION_NONE {
54718 decode_inter_block(54736 decode_inter_block(
54719 &mut dec,54737 &mut dec,
@@ -56574,6 +56592,112 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
56574 #[cfg(test)]56592 #[cfg(test)]
56575 mod tests {56593 mod tests {
56576 56594
56595+ /// lane-av1unwritten r7: the STRUCTURAL invariant that r5 and r6 both broke.
56596+ ///
56597+ /// r5 put guards inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms, so they
56598+ /// could only ever see values 4..=7. r6 deleted the inter-16 guard and did not
56599+ /// replace it. r7's fix was mechanical at both sites and the failure mode was
56600+ /// always the same: a guard exists somewhere, and nothing says it sits between
56601+ /// a symbol's RESOLUTION and every dispatch of it.
56602+ ///
56603+ /// So the invariant is stated over the dispatch structure, not over a list:
56604+ /// every place that RESOLVES a partition symbol from a `partition_w*` CDF is
56605+ /// found by scanning for exactly that binding, and each must be followed -- at
56606+ /// the same nesting depth, before any `match`/`if` that dispatches on the
56607+ /// variable -- by a `refuse_invalid_subsize((W, W), <var>, fctx)` call whose W
56608+ /// is the level's own block size. A hand-maintained site list would have
56609+ /// passed r5 and r6 unchanged.
56610+ #[test]
56611+ fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() {
56612+ let src = include_str!("decode.rs");
56613+ // (variable, level side) for every symbol resolution, taken from the
56614+ // binding lines themselves -- the dispatch structure, not memory.
56615+ let mut sites: Vec<(usize, String, usize)> = Vec::new();
56616+ for (n, line) in src.lines().enumerate() {
56617+ // `let <var> = dec.symbol(...partition_w<LEVEL>[...])` -- the level is
56618+ // read off the CDF name on the line itself, so adding a level shows up
56619+ // here without touching this test.
56620+ let Some((var, tail)) = line.split_once("let ") else {
56621+ continue;
56622+ };
56623+ let var = var.trim().to_string();
56624+ // A doc comment quoting the shape is not a resolution site.
56625+ if line.trim_start().starts_with("//") {
56626+ continue;
56627+ }
56628+ if !tail.contains("= dec.symbol") || !tail.contains("partition_w") {
56629+ continue;
56630+ }
56631+ let after = &tail[tail.find("partition_w").expect("checked") + "partition_w".len()..];
56632+ let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
56633+ // `partition_w16[ctx]` is a resolution; `partition_wide` / any other
56634+ // word that merely starts with "partition_w" is not.
56635+ if digits.is_empty() {
56636+ continue;
56637+ }
56638+ sites.push((n, var, digits.parse().expect("digits")));
56639+ }
56640+ assert!(
56641+ sites.len() >= 7,
56642+ "the scan found only {} partition resolutions -- it is not seeing the dispatch \
56643+ structure",
56644+ sites.len()
56645+ );
56646+ for (line_no, var, level) in &sites {
56647+ // The guard must appear in the lines that FOLLOW this binding and
56648+ // BEFORE the first dispatch on the variable.
56649+ let window: Vec<&str> = src.lines().skip(line_no + 1).take(220).collect();
56650+ // The guard for this level, matched on the LEVEL rather than the
56651+ // variable name: the symbol is often bound to a short-lived inner name
56652+ // (`p`) and dispatched by an outer one (`part64`), and that indirection
56653+ // is exactly what let r5's misplaced guards read as coverage.
56654+ let guard_at = window
56655+ .iter()
56656+ .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})")));
56657+ assert!(
56658+ guard_at.is_some(),
56659+ "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \
56660+ refuse_invalid_subsize(({level}, {level})) anywhere after it -- a subsize \
56661+ libaom refuses can walk straight through (r6 shipped exactly this on the \
56662+ inter-frame 16x16 level)",
56663+ var,
56664+ line_no + 1
56665+ );
56666+ }
56667+
56668+ // The r5 defect, as its own invariant: a guard must never sit INSIDE a
56669+ // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry
56670+ // partition values 4..=7, and the offending values are PARTITION_VERT (2)
56671+ // and PARTITION_VERT_4 (9). Tracked by INDENTATION, because brace counting
56672+ // over a file full of comments and macro bodies drifts.
56673+ let indent_of = |l: &str| l.len() - l.trim_start().len();
56674+ let mut ab_arm_indent: Option<usize> = None;
56675+ for (n, line) in src.lines().enumerate() {
56676+ let t = line.trim_start();
56677+ if t.starts_with("//") {
56678+ continue;
56679+ }
56680+ let ind = indent_of(line);
56681+ if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") {
56682+ ab_arm_indent = Some(ind);
56683+ } else if let Some(a) = ab_arm_indent
56684+ && ind <= a
56685+ {
56686+ ab_arm_indent = None;
56687+ }
56688+ if line.contains("refuse_invalid_subsize((") {
56689+ assert!(
56690+ ab_arm_indent.is_none_or(|a| ind <= a),
56691+ "decode.rs:{} puts a refuse_invalid_subsize inside a \
56692+ PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the \
56693+ offending values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which \
56694+ that arm can never observe -- r5's defect",
56695+ n + 1
56696+ );
56697+ }
56698+ }
56699+ }
56700+
56577 /// lane-av1unwritten: the port is a TRANSCRIPTION, and this is the artefact56701 /// lane-av1unwritten: the port is a TRANSCRIPTION, and this is the artefact
56578 /// that makes it checkable. It re-writes `av1_ss_size_lookup`'s 22 rows56702 /// that makes it checkable. It re-writes `av1_ss_size_lookup`'s 22 rows
56579 /// (`common_data.c:17-41`) literally -- every shape, every subsampling56703 /// (`common_data.c:17-41`) literally -- every shape, every subsampling
lanes/av1unwritten.report.mdmodified+69 -0
@@ -466,3 +466,72 @@ $ wc -l /tmp/gt.txt
466 * No other subsize-selecting dispatch lacks a guard above it: the arm scan finds466 * 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`467 no dispatch reached with a non-codable subsize and no `refuse_invalid_subsize`
468 call between it and the symbol's resolution.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.