diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 3e566208..c55665b9 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -29,6 +29,11 @@ fn main() { } }; let report = || { + // lane-av1unwritten r6: the subsize-guard coverage table (per call + // site, per partition value, reached vs fired). Env-gated + // (`EC_AV1_SUBSIZE_GUARD_TRACE`), so it is empty unless asked for. + ec_av1::decode::dump_subsize_guard_scan(); + ec_av1::decode::dump_subsize_arm_scan(); // The census below reads ec-av1's gate counters; without the crate's // `gate-counters` feature every one of them is compiled out and reads 0. if !cfg!(feature = "gate-counters") { diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 323624c5..11883778 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21485,11 +21485,32 @@ fn partition_subsize_dims(bsize: (usize, usize), part: usize) -> (usize, usize) /// selected, exactly as `decode_partition` does at `decodeframe.c:1449-1458` /// before descending into it. Returns libaom's named refusal for the caller to /// propagate. +#[track_caller] fn refuse_invalid_subsize( bsize: (usize, usize), part: usize, fctx: &crate::decode::FrameCtx, ) -> Result<()> { + // lane-av1unwritten r6: the coverage artefact. A guard that sits INSIDE a + // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm can only ever observe 4..=7, so + // "the guard is present" is not evidence that an offending value is caught -- + // which is exactly how r5's three misplaced guards read as coverage. This + // records, per CALL SITE and per partition value, how often the guard was + // reached and how often it fired, so a site that never sees an offending + // value is visible instead of assumed covered. + if crate::envflags::env_flag!("EC_AV1_SUBSIZE_GUARD_TRACE") { + note_subsize_guard( + std::panic::Location::caller(), + bsize, + part, + chroma_plane_block_codable( + partition_subsize_dims(bsize, part).0, + partition_subsize_dims(bsize, part).1, + ss_x(fctx), + ss_y(fctx), + ), + ); + } let (bw, bh) = partition_subsize_dims(bsize, part); if chroma_plane_block_codable(bw, bh, ss_x(fctx), ss_y(fctx)) { Ok(()) @@ -21498,6 +21519,88 @@ fn refuse_invalid_subsize( } } +/// lane-av1unwritten r6: the OTHER half of the coverage artefact. The guard +/// table says what the guards see; this says what each DISPATCH ARM sees, so a +/// dispatch reached with an offending partition value and no guard above it is a +/// visible hole rather than an absence nobody noticed. `decode_probe` calls +/// [`dump_subsize_arm_scan`] at exit under `EC_AV1_SUBSIZE_ARM_TRACE`. +static SUBSIZE_ARM: std::sync::LazyLock< + std::sync::Mutex>, +> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default())); + +#[track_caller] +pub(crate) fn note_subsize_arm(part: usize, codable: bool) { + if !crate::envflags::env_flag!("EC_AV1_SUBSIZE_ARM_TRACE") { + return; + } + let site = std::panic::Location::caller(); + let key = ( + format!("{}:{}", site.file(), site.line()).leak() as &'static str, + part * 2 + usize::from(codable), + ); + if let Ok(mut m) = SUBSIZE_ARM.lock() { + *m.entry(key).or_insert(0) += 1; + } +} + +/// Prints and clears the [`note_subsize_arm`] table. +pub fn dump_subsize_arm_scan() { + let Ok(mut m) = SUBSIZE_ARM.lock() else { + return; + }; + for ((site, k), n) in m.iter() { + eprintln!( + "SUBSIZE_ARM site={site} part={} codable={} reached={n}", + k / 2, + if k % 2 == 1 { "true" } else { "false" }, + ); + } + m.clear(); +} + +/// Per-site, per-value counters for [`refuse_invalid_subsize`], plus the dump +/// that makes the reach/guard split readable. `EC_AV1_SUBSIZE_GUARD_TRACE` +/// records; `dump_subsize_guard_scan` prints (and clears) the table. +static SUBSIZE_GUARD: std::sync::LazyLock< + std::sync::Mutex>, +> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default())); + +fn note_subsize_guard( + site: &'static std::panic::Location<'static>, + bsize: (usize, usize), + part: usize, + codable: bool, +) { + let key = ( + format!("{}:{}", site.file(), site.line()).leak() as &'static str, + bsize.0 * 256 + bsize.1, + part, + codable, + ); + if let Ok(mut m) = SUBSIZE_GUARD.lock() { + *m.entry(key).or_insert(0) += 1; + } +} + +/// Prints and clears the [`refuse_invalid_subsize`] table: one line per +/// (site, block, partition value) with the times reached and whether the guard +/// fired. `decode_probe` calls this at exit. +pub fn dump_subsize_guard_scan() { + let Ok(mut m) = SUBSIZE_GUARD.lock() else { + return; + }; + for ((site, bsize, part, codable), n) in m.iter() { + eprintln!( + "SUBSIZE_GUARD site={site} bsize={}x{} part={part} codable={codable} \ + reached={n}{}", + bsize / 256, + bsize % 256, + if *codable { "" } else { " FIRED" }, + ); + } + m.clear(); +} + /// [`chroma_plane_block_codable`] as libaom's refusal: a returned error naming /// the shape and the subsampling mode, never an `assert!` -- a partition symbol /// is stream data, so a hostile file can reach it. @@ -36359,6 +36462,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( ); } let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); + // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be + // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` + // (common_data.h:71-90) reduced to dimensions, so this is + // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY + // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings + // keep decoding because the helper is exact, not a heuristic. key-frame 16x16 level. + refuse_invalid_subsize((16, 16), part16, fctx)?; + if crate::envflags::env_flag!("EC_TRACE") { eprintln!( "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}", @@ -36511,14 +36622,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( let br = (mi_row0 + 2, mi_col0 + 2); let mut done: Vec<((usize, usize), usize)> = Vec::new(); - // lane-av1unwritten r4: the - // 16x16-level 1:4 split -- - // VERT_4 selects BLOCK_4X16, - // INVALID at 4:2:2; HORZ_4 - // selects BLOCK_16X4, whose (1,0) - // cell is BLOCK_8X4 (valid, the - // shape r2 wrongly refused). - refuse_invalid_subsize((16, 16), part16, fctx)?; match part16 { PARTITION_HORZ_A => { let m_tl = @@ -36675,6 +36778,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( if part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4 { + // lane-av1unwritten r6: arm census -- + // which partition values reach here. + note_subsize_arm( + part16, + chroma_plane_block_codable( + partition_subsize_dims((16, 16), part16).0, + partition_subsize_dims((16, 16), part16).1, + ss_x(fctx), + ss_y(fctx), + ), + ); decode_rect4_16( &mut dec, &mut cdfs, @@ -54020,6 +54134,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); } let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); + // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be + // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` + // (common_data.h:71-90) reduced to dimensions, so this is + // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY + // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings + // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol. + refuse_invalid_subsize((64, 64), p, fctx)?; + if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!( "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", @@ -54135,6 +54257,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( part64, PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 ) { + // lane-av1unwritten r6: arm census. + note_subsize_arm( + part64, + chroma_plane_block_codable( + partition_subsize_dims((64, 64), part64).0, + partition_subsize_dims((64, 64), part64).1, + ss_x(fctx), + ss_y(fctx), + ), + ); // lane-inter4 r1: the superblock-level rect + 1:4 pairs as // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / // 16x64 ones. Each piece keeps `side = SB` for every @@ -54306,11 +54438,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( )? }; } - // lane-av1unwritten r4: VERT on a 64x64 block selects - // BLOCK_32X64 -- INVALID at 4:2:2. HORZ on the same block - // selects BLOCK_64X32, whose (1,0) cell is BLOCK_32X32 - // (valid) and MUST keep decoding. - refuse_invalid_subsize((64, 64), part64, fctx)?; match part64 { PARTITION_HORZ_A => { ab_square32!(tl); @@ -54798,14 +54925,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ) }; } - // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or - // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is - // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to - // dimensions, so this is `decode_partition`'s pre-descend check - // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT, - // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep - // decoding because the helper is exact, not a heuristic. (inter-frame duplicate) - refuse_invalid_subsize((16, 16), part16, fctx)?; match part16 { PARTITION_HORZ_A => { inter_leaf8!(at16, tl); @@ -55000,6 +55119,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } let ec_dbg_pre = dec.debug_state().0; let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be + // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` + // (common_data.h:71-90) reduced to dimensions, so this is + // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY + // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings + // keep decoding because the helper is exact, not a heuristic. inter-frame 8x8 level. + refuse_invalid_subsize((8, 8), part8, fctx)?; + if std::env::var_os("EC_DBG_SUB8").is_some() { let ec_dbg_post = dec.debug_state().0; eprintln!( @@ -55037,6 +55164,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( )?; continue; } + // lane-av1unwritten r6: arm census -- an + // 8x8-level VERT selects BLOCK_4X8, which + // is INVALID at 4:2:2. + note_subsize_arm( + part8, + chroma_plane_block_codable( + partition_subsize_dims((8, 8), part8).0, + partition_subsize_dims((8, 8), part8).1, + ss_x(fctx), + ss_y(fctx), + ), + ); if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { // lane-intersub8 r3/r4/r5: two // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT) diff --git a/lanes/av1unwritten.report.md b/lanes/av1unwritten.report.md index 0f597b3f..fd8ffc0b 100644 --- a/lanes/av1unwritten.report.md +++ b/lanes/av1unwritten.report.md @@ -124,8 +124,14 @@ ba2957e1709507b8336e53cd908b7dfe2a59dc2064b1f5eb4bea9b3149a4653d ``` Two distinct output hashes from one file with uninitialised planes; and with -`EC_AV1_PLANE_SENTINEL=1` five runs give ONE hash, which differs from the plain -one (1984 bytes). Reproduced independently on a fresh `8d6998d7` worktree with +`EC_AV1_PLANE_SENTINEL=1` five runs give ONE hash, and that hash differs from the +plain one -- both dumps are 8192 bytes, and the sentinel dump carries 65 bytes +equal to `0xAD` against a 33-byte baseline in the plain dump. (An earlier draft of +this line said "differs by 1984 bytes"; that byte count does not reproduce, and the +`0xAD` counts are the correct form. A per-byte diff of the two dumps is not +stable, because one sentinel sample propagates through the loop filters into its +neighbours -- which is itself the reason the dependence matters.) Reproduced +independently on a fresh `8d6998d7` worktree with its own target dir (Main: `d35d59cce59cfa2b` / `5b38d5079a6578a8` plain, `3a2ae6dbec390f26` sentinel x5). @@ -289,7 +295,7 @@ instrument is what would show it if one ever did. * **Corpus, both trees.** Every fixture decoded with `EC_AV1_FINAL_DUMP`, every `.f*` hashed. Pre-fix vs post-fix the **126 valid fixtures are byte-identical** and **none newly refuses**; the witness is the only difference and it now - refuses. Re-run on the r5 predicate: `differing: + refuses. Re-run on the r6 predicate (guards relocated): `differing: ['440_request_is_422']`, 126 fixtures emitting dumps, and exactly one fixture whose output contains `REFUSED` — the witness. **The sweep cannot see the (16,4)-at-4:2:2 false positive**: no committed fixture carries a 16x8 block @@ -352,8 +358,9 @@ under the sentinel); it is reported, not gated, because the gate's job is the contract and the contract is the refusal. The determinism is then a consequence of the refusal, not a second assertion. -**Mutation.** Deleting the two `chroma_plane_block_codable` call sites puts the -witness back to `OK: 1 frames decoded` and the gate's `unwrap_or_else` panics +**Mutation.** Deleting any one `refuse_invalid_subsize` call the witness passes +through (the 128 root's, the key 64's, ...) puts the witness back to +`OK: 1 frames decoded` and the gate's `unwrap_or_else` panics with "the pin must be REFUSED, not decoded"; replacing the message text so it no longer contains libaom's wording reds the second assertion; pointing the positive control at the witness reds the third. @@ -387,3 +394,75 @@ control at the witness reds the third. what `cargo build` last reported. A probe built from this worktree was read as a measurement of `main` here and inverted a whole section of the report until `strings` was checked. + +--- + +## 8. r6 — the guards were not where the values are decided + +**r5 claimed complete coverage and did not have it.** The refutation pass +(Agent03-5) showed that three of the eight `refuse_invalid_subsize` calls sat +**inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms**, so they could only ever +observe partition values 4..=7 — and the arms that DO see the offending values +had no guard above them: + +| unguarded arm | value | subsize | corpus hits | +|---|---|---|---| +| kf 16-level `decode_rect4_16` | `part16 = 9` (VERT_4) | `BLOCK_4X16` | 538 | +| inter 64-level rect / 1:4 arm | `part64 = 2` (VERT) | `BLOCK_32X64` | 887 | +| inter 64-level rect / 1:4 arm | `part64 = 9` (VERT_4) | `BLOCK_16X64` | 280 | +| inter `w8` arm | `part8 = 2` (VERT) | `BLOCK_4X8` | 3476 | + +All four are `BLOCK_INVALID` at `av1_ss_size_lookup[..][1][0]` — exactly what +libaom refuses at `decodeframe.c:1451-1460`. + +### 8.1 The fix + +Every guard now sits where the partition symbol is **RESOLVED**, before any +dispatch arm — one guard per level per path, so it can see every value that level +produces: + +| site | level | values seen (corpus scan) | +|---|---|---| +| `decode.rs:35584` kf 128 root | 128x128 | 0,1,2,3 | +| `decode.rs:36274` kf 64 | 64x64 | 0,1,2,3,4,5,6,7,8,9 | +| `decode.rs:36402` kf 32 | 32x32 | 0,1,2,3,4,5,6,7,8,9 | +| `decode.rs:36468` kf 16 | 16x16 | 0,1,2,3,4,5,6,7,8,9 — **part=7 FIRED 68x** | +| `decode.rs:54140` inter 64 | 64x64 | 0,1,2,3,4,5,7,8,9 | +| `decode.rs:54576` inter 32 | 32x32 | 0,1,2,3,4,5,6,7,8,9 | +| `decode.rs:55125` inter 8 | 8x8 | 0,1,2,3 | + +The only guard that fires over the corpus is the key-frame 16-level one, on +`PARTITION_VERT_B` (subsize `BLOCK_8X16`, INVALID at 4:2:2) — 68 times, in +`reelb_*`-class streams. Every other corpus stream is 4:2:0 / 4:4:4, where the same +values are legal, so "passed" is the correct reading and **the sweep is what +proves the legal siblings still decode**. + +### 8.2 The coverage artefact (this is what made the failure visible) + +Two env-gated scans, both printed by `decode_probe` and both committed, because +prose about coverage is not evidence of coverage: + +* `EC_AV1_SUBSIZE_GUARD_TRACE=1` — per **guard call site**, per partition value: + times reached and whether the guard fired. A site that never sees an offending + value is then visible instead of assumed covered. That is exactly the defect + r5 shipped: three sites whose reachable value set was 4..=7 only. +* `EC_AV1_SUBSIZE_ARM_TRACE=1` — per **unguarded dispatch arm**, which partition + values actually reach it and whether their subsize is codable at this frame's + subsampling. + +Both are off by default and cost nothing when unset. + +``` +$ 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 +$ wc -l /tmp/gt.txt +2346 /tmp/gt.txt +``` + +### 8.3 Residue + +* **`decode_rect4_16_intrabc` is the declared exception and was NOT audited.** It + is another lane's charter. Everything above covers the intra and inter paths + this lane owns. +* No other subsize-selecting dispatch lacks a guard above it: the arm scan finds + no dispatch reached with a non-codable subsize and no `refuse_invalid_subsize` + call between it and the symbol's resolution.