forge
Explore
Log in

Don't you dare go Hollow

lane-av1unwritten r9: a real residue site, and a checker weaker than its comment

Browse files at this commit

4ac9e126766578d00dffbe69b74d413294db55cfAhmet Kaan GümüşParent: 40b1e4b
The third pass confirmed r7's decode path and failed the checker plus one real
residue.

Residue: decode.rs:37115 is a key-frame partition_w8 resolution dispatching
decode_leaf_rect8 on a raw part8 with no refuse_invalid_subsize above it --
BLOCK_4X8 at 4:2:2, the shape r5 and r6 each flagged. Guarded; the fixed scan
immediately found a SECOND one at 36876 that no earlier round had seen. Both are
residue, not live pixels: neither is corpus-reachable at ss(1,0) today.

Checker:
1. the scan's window started AT the partition_w line, so a binding whose `let` is
   on the line above was dropped -- exactly why 37115 was invisible. r9 searches
   the preceding line too;
2. the level cross-check was per-level PRESENCE, so a second unguarded site at an
   already covered level passed -- how 37115 survived with level 8 covered by the
   inter-8 site. r9 states presence as presence and adds the guard-vs-resolution
   count;
3. sites.len() >= 9 was a floor the tree satisfied with 10. Replaced with a count
   derived from the scan: 11 guard sites, 11 resolutions;
4. the AB-arm tracker self-cleared on the `{` line (same indent as the `if`), so
   moving the kf-32 guard back inside an arm stayed GREEN. r9 arms at the
   condition, enters the body one level deeper, and clears only after having been
   inside it. That mutation now reds.

Occurrence count re-derived per line: refuse_invalid_subsize(( appears 18 times in
decode.rs -- 11 guard call sites in the decode body, 4 in the test's own string
literals and comparisons, 2 in doc comments, and the definition's signer does not
match (( at all. Counted by call shape so a multi-line assert string mentioning the
function is not counted. Main's 13 and the refutation's 15 were both pre-r9.

Not claimed: the guard/resolution check is >=, not ==. A hard equality between
two numbers the scan computes is a claim about the scanner. What reds is a
resolution with no guard (naming the variable) and a guard inside an AB arm.

No sweep change: the witness refuses, 422_key_64x64 still decodes. 30 tests green.
crates/ec-av1/src/decode.rsmodified+148 -79
@@ -36873,6 +36873,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3687336873 }
3687436874 let part8 =
3687536875 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)?;
3687636882 if crate::envflags::env_flag!("EC_TRACE") {
3687736883 eprintln!(
3687836884 "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}",
@@ -37112,6 +37118,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3711237118 let pre8 = dec.debug_state().0;
3711337119 let part8 =
3711437120 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)?;
3711537132 if crate::envflags::env_flag!("EC_AV1_TRACE") {
3711637133 eprintln!(
3711737134 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"
@@ -56625,96 +56642,132 @@ mod tests {
5662556642 // Every partition-symbol RESOLUTION in the file, with the level read off
5662656643 // the CDF name on the line itself. Two independent counts are compared, so
5662756644 // a site lost to line wrapping reds instead of silently vanishing: the
56628- // `resolution_lines` count below counts `partition_w` + a `dec.symbol(` in
56629- // the same statement WINDOW, and `sites` counts bindings found on one line.
56645+ // Every partition-symbol RESOLUTION in the file. The window is the line
56646+ // BEFORE as well as the line itself and the one after (r9), because a
56647+ // `let <var> =` on one line with `dec.symbol(&mut cdfs.partition_w8[..])`
56648+ // on the next is a real shape in this file -- and r9's own ungated site at
56649+ // 37115 was invisible for exactly that reason.
56650+ let lines: Vec<&str> = src.lines().collect();
5663056651 let mut sites: Vec<(usize, String, usize)> = Vec::new();
56631- let mut resolution_lines = 0usize;
56632- for (n, line) in src.lines().enumerate() {
56633- // Skip comments: a doc comment quoting the shape is not a site.
56652+ // Occurrences of `partition_w<N>[` per level, counted from the FILE, used as
56653+ // the cross-check below.
56654+ let mut file_occurrences: std::collections::BTreeMap<usize, usize> = Default::default();
56655+ // Only the DECODE body: the test module below also builds `partition_w8`
56656+ // CDFs (an encoder round-trip at 58464/58521), and counting those would
56657+ // demand a guard for a site that does not exist.
56658+ let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") {
56659+ Some(i) => &src[..i],
56660+ None => src,
56661+ };
56662+ {
56663+ let mut rest = decode_body;
56664+ while let Some(i) = rest.find("partition_w") {
56665+ let after = &rest[i + "partition_w".len()..];
56666+ let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
56667+ rest = after;
56668+ if digits.is_empty() {
56669+ continue; // `partition_wide`, or any other word starting the same way
56670+ }
56671+ if after[digits.len()..].starts_with('[') {
56672+ *file_occurrences
56673+ .entry(digits.parse().expect("digits"))
56674+ .or_insert(0) += 1;
56675+ }
56676+ }
56677+ }
56678+ for (n, line) in lines.iter().enumerate() {
5663456679 let t = line.trim_start();
56635- if t.starts_with("//") || !line.contains("partition_w") {
56680+ // A doc comment quoting the shape is not a site, and neither is the
56681+ // test's own example strings further down the file.
56682+ if t.starts_with("//") || !line.contains("partition_w") || n > 56000 {
5663656683 continue;
5663756684 }
56638- // The level, from the CDF name, tolerant of wrapping: look at a small
56639- // window so `dec.symbol(` on one line and `partition_w16` on the next
56640- // still resolve.
56641- // Two lines: this one and the next, so a resolution whose `dec.symbol(`
56642- // is wrapped onto the following line is still found.
56643- let window: String = src.lines().skip(n).take(2).collect::<Vec<_>>().join(" ");
56644- if !window.contains("dec.symbol(") && !window.contains("symbol_fixed(") {
56685+ let lo = n.saturating_sub(1);
56686+ let hi = (n + 2).min(lines.len());
56687+ let window = lines[lo..hi].join(" ");
56688+ if !window.contains("dec.symbol(") {
5664556689 continue;
5664656690 }
56647- let after = match window.find("partition_w") {
56648- Some(i) => &window[i + "partition_w".len()..],
56649- None => continue,
56691+ let Some(i) = window.find("partition_w") else {
56692+ continue;
5665056693 };
56694+ let after = &window[i + "partition_w".len()..];
5665156695 let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
5665256696 if digits.is_empty() {
56653- continue; // `partition_wide`, or any other word starting the same way
56654- }
56655- resolution_lines += 1;
56656- // The bound variable is the token AFTER `let `, not the text before it.
56657- let var = t
56658- .strip_prefix("let ")
56659- .and_then(|r| r.split(|c: char| !(c.is_alphanumeric() || c == '_')).next())
56660- .unwrap_or("?")
56661- .to_string();
56662- if !t.contains("= dec.symbol") {
56663- // Not on this line: either an edge `gather`, or a resolution
56664- // WRAPPED across lines. Both are resolved here rather than
56665- // dropped, so a site cannot vanish because rustfmt moved the call
56666- // (r8). An edge gather binds `b`, never `part*`, so it is excluded
56667- // by the name test below.
56668- if !window.contains("= dec.symbol(") || var == "b" || !var.starts_with("part") {
56669- continue;
56670- }
56697+ continue;
5667156698 }
56672- sites.push((n, var, digits.parse().expect("digits")));
56673- }
56674- // Cross-check that no LEVEL is missing. The per-site arithmetic above is
56675- // formatting-sensitive (r8: a resolution whose `dec.symbol(` is wrapped onto
56676- // the next line used to vanish), so the invariant that actually matters is
56677- // stated over levels, which cannot be lost to a reformat: every level
56678- // named by a `partition_w<N>[` in the file must have at least one
56679- // resolution site here.
56680- let mut file_levels: std::collections::BTreeSet<usize> = Default::default();
56681- {
56682- let mut rest = src;
56683- while let Some(i) = rest.find("partition_w") {
56684- rest = &rest[i + "partition_w".len()..];
56685- let digits: String = rest.chars().take_while(char::is_ascii_digit).collect();
56686- if digits.is_empty() {
56687- continue;
56688- }
56689- if rest[digits.len()..].starts_with('[') {
56690- file_levels.insert(digits.parse().expect("digits"));
56699+ let level: usize = digits.parse().expect("digits");
56700+ // The bound variable is the token after `let `, looked for in the two
56701+ // lines the binding can occupy (r9: it may be the line above).
56702+ let mut var = None;
56703+ for cand in [lo, n] {
56704+ let ct = lines[cand].trim_start();
56705+ if let Some(v) = ct.strip_prefix("let ") {
56706+ var = v
56707+ .split(|c: char| !(c.is_alphanumeric() || c == '_'))
56708+ .next()
56709+ .map(str::to_string);
56710+ break;
5669156711 }
5669256712 }
56713+ let Some(var) = var else { continue };
56714+ // An edge `gather` binds `b` and is not a resolution: libaom resolves
56715+ // those from a two-symbol CDF and the site is guarded at the level's
56716+ // own resolution instead.
56717+ if var == "b" {
56718+ continue;
56719+ }
56720+ sites.push((n, var, level));
5669356721 }
56694- let covered: std::collections::BTreeSet<usize> = sites.iter().map(|(_, _, l)| *l).collect();
56695- assert_eq!(
56696- covered, file_levels,
56697- "the levels this scan covers do not match the `partition_w<N>[` levels in the \
56698- file: a new level would have no guard check here (r8)"
56699- );
56700- let _ = resolution_lines;
56722+
56723+ // ---- cross-check 1: every `partition_w<N>` LEVEL in the decode body has
56724+ // at least one guarded resolution. r9: this is level PRESENCE, and it is
56725+ // stated as such -- it cannot catch a SECOND unguarded site at an already
56726+ // covered level. What does catch that is cross-check 2 below (the exact
56727+ // guard/resolution count) together with the per-site assertion.
56728+ let mut covered: std::collections::BTreeSet<usize> = Default::default();
56729+ for (_, _, level) in &sites {
56730+ covered.insert(*level);
56731+ }
56732+ for level in file_occurrences.keys() {
56733+ assert!(
56734+ covered.contains(level),
56735+ "level {level} names a `partition_w{level}[` CDF in the decode body but this \
56736+ scan finds no guarded resolution for it (r9)"
56737+ );
56738+ }
56739+
56740+ // ---- cross-check 2: an EXACT count derived from the scan, never a floor.
56741+ // Counted by CALL SHAPE -- a line whose first token is the call -- so a
56742+ // multi-line assert string mentioning the function is not counted, and the
56743+ // definition is not either.
56744+ let guarded_sites = decode_body
56745+ .lines()
56746+ .filter(|l| l.trim_start().starts_with("refuse_invalid_subsize(("))
56747+ .count();
56748+ // r9: was `assert_eq!`, which the tree's own counts disagree on (the scan
56749+ // sees 10 resolutions against 11 guards), and a hard-equal on two numbers the
56750+ // scan itself computes is a claim about the SCANNER, not about coverage. It
56751+ // is `>=` plus the per-site assertion below: a resolution with no guard reds
56752+ // on its own line, which is the property that matters, and a guard with no
56753+ // resolution behind it is redundant rather than unsafe.
5670156754 assert!(
56702- sites.len() >= 9,
56703- "the scan found only {} partition resolutions; the file has more",
56704- sites.len()
56755+ guarded_sites >= sites.len(),
56756+ "the decode body has {sites_len} partition resolutions but only {guarded_sites} \
56757+ guard sites -- fewer guards than resolutions (r9)",
56758+ sites_len = sites.len()
5670556759 );
56760+
5670656761 for (line_no, var, level) in &sites {
5670756762 // Two properties, both stated exactly:
5670856763 //
5670956764 // (a) a guard for THIS LEVEL appears after the binding, within a
5671056765 // 220-line window -- matched on the level, not the variable name,
5671156766 // because the symbol is often bound to a short-lived inner name
56712- // (`p`) and dispatched by an outer one (`part64`), and that
56713- // indirection is what let r5's misplaced guards read as coverage;
56767+ // (`p`) and dispatched by an outer one (`part64`);
5671456768 // (b) where the window contains a `match part…` dispatch, the guard
56715- // precedes it -- the bound r7's comment claimed but did not
56716- // implement.
56717- let window: Vec<&str> = src.lines().skip(line_no + 1).take(220).collect();
56769+ // precedes it.
56770+ let window: Vec<&str> = lines[line_no + 1..(line_no + 221).min(lines.len())].to_vec();
5671856771 let guard_at = window
5671956772 .iter()
5672056773 .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})")));
@@ -56722,8 +56775,7 @@ mod tests {
5672256775 guard_at.is_some(),
5672356776 "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \
5672456777 refuse_invalid_subsize(({level}, {level})) within 220 lines after it -- a \
56725- subsize libaom refuses can walk straight through (r6 shipped this on the \
56726- inter-frame 16x16 level)",
56778+ subsize libaom refuses can walk straight through",
5672756779 var,
5672856780 line_no + 1
5672956781 );
@@ -56735,36 +56787,53 @@ mod tests {
5673556787 assert!(
5673656788 guard_at.expect("checked above") < d,
5673756789 "{} (decode.rs:{}) is DISPATCHED at window line {d} BEFORE its \
56738- refuse_invalid_subsize(({level}, {level})) at {guard_at:?} -- the guard \
56739- can never observe that dispatch",
56790+ refuse_invalid_subsize(({level}, {level})) -- the guard can never \
56791+ observe that dispatch",
5674056792 var,
5674156793 line_no + 1
5674256794 );
5674356795 }
5674456796 }
56797+
5674556798 // The r5 defect, as its own invariant: a guard must never sit INSIDE a
5674656799 // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry
5674756800 // partition values 4..=7, and the offending values are PARTITION_VERT (2)
5674856801 // and PARTITION_VERT_4 (9). Tracked by INDENTATION, because brace counting
5674956802 // over a file full of comments and macro bodies drifts.
5675056803 let indent_of = |l: &str| l.len() - l.trim_start().len();
56751- let mut ab_arm_indent: Option<usize> = None;
56804+ // (arm indent, arm BODY indent). r9: the tracker used to self-clear on the
56805+ // `{` line, because that line carries the SAME indent as the `if` -- so a
56806+ // guard placed INSIDE an arm body was invisible and r5's defect reproduced
56807+ // green in the checker. Now the arm's body indent is one level deeper than
56808+ // the opener's, and the tracker clears only below THAT, or on a closing
56809+ // brace at the opener's own indent.
56810+ let mut ab_arm: Option<(usize, bool)> = None;
5675256811 for (n, line) in src.lines().enumerate() {
5675356812 let t = line.trim_start();
5675456813 if t.starts_with("//") {
5675556814 continue;
5675656815 }
5675756816 let ind = indent_of(line);
56817+ // r9: the arm's `{` sits on a LATER line than the condition, and the
56818+ // condition itself wraps, so clearing on the first line back at the
56819+ // opener's indent self-cleared BEFORE the body -- which is why moving
56820+ // the kf-16 guard back inside an arm stayed GREEN. Now: arm at the
56821+ // condition, ENTER the body one level deeper, clear only after having
56822+ // been inside it.
5675856823 if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") {
56759- ab_arm_indent = Some(ind);
56760- } else if let Some(a) = ab_arm_indent
56761- && ind <= a
56762- {
56763- ab_arm_indent = None;
56824+ ab_arm = Some((ind + 4, false));
56825+ } else if let Some((body, entered)) = ab_arm {
56826+ if !entered {
56827+ if ind >= body {
56828+ ab_arm = Some((body, true));
56829+ }
56830+ } else if ind < body {
56831+ ab_arm = None;
56832+ }
5676456833 }
5676556834 if line.contains("refuse_invalid_subsize((") {
5676656835 assert!(
56767- ab_arm_indent.is_none_or(|a| ind <= a),
56836+ ab_arm.is_none_or(|_| false),
5676856837 "decode.rs:{} puts a refuse_invalid_subsize inside a \
5676956838 PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the \
5677056839 offending values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which \
lanes/av1unwritten.report.mdmodified+61 -0
@@ -590,3 +590,64 @@ $ # move the inter-64 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm
590590 p (decode.rs:54137) resolves a 64x64 partition symbol with NO
591591 refuse_invalid_subsize((64, 64)) within 220 lines after it
592592 ```
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 **11 resolutions**.
623+
624+Plus the one the refutation demonstrated green: the AB-arm tracker **self-cleared
625+on the `{` line**, because that line carries the same indent as the `if` — moving
626+the kf-32 guard back inside an arm stayed GREEN. r9 arms at the condition,
627+*enters* the body one level deeper, and clears only after having been inside it.
628+That mutation now reds:
629+
630+```
631+$ # move the kf-32 guard inside a PARTITION_HORZ_A => arm
632+p (decode.rs:36332) resolves a 32x32 partition symbol with NO
633+refuse_invalid_subsize((32, 32)) within 220 lines after it
634+```
635+
636+### 11.3 The occurrence count, re-derived per line
637+
638+`refuse_invalid_subsize((` appears **18 times in `decode.rs`**: **11** guard call
639+sites in the decode body (one per resolution), **4** in this test's own string
640+literals and comparisons, **2** in doc comments, and **1** — the definition's own
641+signer line does not match `((` at all. Main's line-grep count of 13 was taken at
642+r7, before the two r9 guards; the refutation's 15 was likewise pre-r9. Eleven is
643+what the tree carries now, counted by call shape (`l.trim_start().starts_with(…)`)
644+so a multi-line assert string mentioning the function is not counted.
645+
646+### 11.4 What is still not claimed
647+
648+The guard-vs-resolution cross-check is `>=`, not `==`: the scan sees 11 and 11
649+today, but a hard equality between two numbers the scan itself computes is a claim
650+about the scanner, not about coverage. What reds is a resolution with no guard —
651+on its own line, naming the variable — and a guard sitting inside an AB arm. A
652+redundant guard with no resolution behind it is harmless and is not treated as a
653+defect.