diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a54fef7b..84b720b1 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2722,10 +2722,20 @@ pub(crate) fn palette_split_tx_hits() -> usize { thread_local! { /// lane-av1444d10: chroma PREDICTION units on the 32-capped tiled chroma /// walk (`decode_block_rect`'s `uw/uh = min(chroma, 32)` units) that were - /// handed a WINDOWED slice of their block's palette buffer -- i.e. the - /// units that are NOT the block's top-left corner. Counts units, not - /// blocks, and only units whose block actually has a UV palette, so a - /// stream without a tiled palette chroma block leaves it at zero. + /// handed a STRICT sub-slice of their block's palette buffer -- i.e. the + /// units of a block the 32-cap actually TILED (`nw * nh > 1`). + /// + /// CORRECTED 2026-09-30 after the refutation pass `lanes/refute-av1444d10` + /// read the numbers back: the previous comment claimed it counted "the + /// units that are NOT the block's top-left corner", which is not what the + /// code did -- the hit was unconditional, so a block's corner unit fired it + /// too AND a single-unit block (whose window is a pure re-stride copy of + /// the whole buffer) fired it as well. That made a hit prove only that some + /// palette chroma block existed, not that the tiled arm ran. The `bigger` + /// guard now makes the counter discriminate. On the pinned fixture the + /// measured value is unchanged at 4 (one block with nw = 1, nh = 2 x two + /// planes x two unit rows); a stream whose palette chroma blocks are all + /// single-unit now leaves it at zero. static CHROMA_PALETTE_WINDOW_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } @@ -2980,6 +2990,18 @@ fn palette_window( w: usize, h: usize, ) -> Vec { + // `stride` is the BLOCK's own chroma width, so a caller that handed over a + // mismatched stride could read in-bounds GARBAGE instead of panicking -- + // a silent misread, which is the one failure mode this walk must not have. + // The refutation pass (`lanes/refute-av1444d10.report.md`, risk (e)) named + // that as the only thing keeping the tiled walk safe, so the invariant is + // closed loudly here instead of resting on an `unsupported` return + // elsewhere that a future shape could remove. + assert!( + w <= stride && ox + w <= stride && (oy + h) * stride <= buf.len(), + "palette window {w}x{h} at ({ox},{oy}) does not fit a {}-entry buffer at stride {stride}", + buf.len() + ); (0..h) .flat_map(|r| buf[(oy + r) * stride + ox..][..w].iter().copied()) .collect() @@ -20110,7 +20132,16 @@ fn decode_block_rect64( palette_window(pbuf, chroma_w, cu_col * uw, cu_row * uh, uw, uh), fctx, ); - hit!(CHROMA_PALETTE_WINDOW_HITS); + // Counted only when the window is a STRICT sub-slice of the + // block's buffer, i.e. when the 32-cap actually tiled the + // block: at nw * nh == 1 the window is a re-stride copy of + // the whole buffer and windowing is load-bearing for + // nothing. The `bigger` guard is what makes a hit PROOF + // that the tiled arm ran, rather than proof that some + // palette chroma block existed. + if bigger { + hit!(CHROMA_PALETTE_WINDOW_HITS); + } } read_plane( dec, @@ -20169,7 +20200,16 @@ fn decode_block_rect64( palette_window(pbuf, chroma_w, cu_col * uw, cu_row * uh, uw, uh), fctx, ); - hit!(CHROMA_PALETTE_WINDOW_HITS); + // Counted only when the window is a STRICT sub-slice of the + // block's buffer, i.e. when the 32-cap actually tiled the + // block: at nw * nh == 1 the window is a re-stride copy of + // the whole buffer and windowing is load-bearing for + // nothing. The `bigger` guard is what makes a hit PROOF + // that the tiled arm ran, rather than proof that some + // palette chroma block existed. + if bigger { + hit!(CHROMA_PALETTE_WINDOW_HITS); + } } push_intra_rect( plane_idx, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 4dd3274f..87730f62 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -50751,9 +50751,11 @@ exit 0 /// (2) 17 decode-order frames at 352x242 with FULL-RESOLUTION chroma, so /// a decoder that kept the 4:2:0 extent cannot pass the compare. /// (3) `decode::chroma_palette_window_hits()` read as a delta must be at - /// least 1: the fixed lines are the only thing that increments it, so a - /// gate that passes without them running would be - /// gate-blind-to-feature. (4) The oracle comparator this gate leans on has + /// least 1. After the refutation pass read the numbers back, that counter + /// is guarded on `nw * nh > 1`, so it fires ONLY for units of a block the + /// 32-cap actually tiled -- a hit is therefore proof that the tiled arm ran, + /// not merely that some palette chroma block existed, and a gate that + /// passed with the tiled arm removed would be gate-blind-to-feature. (4) The oracle comparator this gate leans on has /// its own per-plane one-byte-flip liveness control in the crate /// (`every_oracle_comparator_reds_on_a_one_byte_wrong_oracle`). #[test] diff --git a/lanes/refute-av1444d10.report.md b/lanes/refute-av1444d10.report.md new file mode 100644 index 00000000..421183aa --- /dev/null +++ b/lanes/refute-av1444d10.report.md @@ -0,0 +1,23 @@ +# refutation-av1444d10 — reviewer verdict on the 4:4:4 10-bit 352x242 palette-window fix (merge e4787782) + +Transcribed verbatim from the reviewer seat's output (agent Agent20-5), 2026-09-30. The ONLY edit is the P3 flag below, which main acted on in the same batch (the counter is now guarded on nw*nh>1 and its doc corrected; gate re-run green at 4 windowed units). The P3 finding's own BODY was stored truncated at its 1068-byte tail ("Fix the c…"); the gist -- the counter must be fixed or its doc corrected so that a hit proves the TILED arm ran -- is what was acted on, and a doc-only change was NOT taken as sufficient because the counter is used as the gate's non-vacuity arm. + +VERDICT: PASS +FLAGS: crates/ec-av1/src/decode.rs:2721-2731 (P3 doc-vs-behaviour, non-blocking) +EVIDENCE: (1) COMPARATOR LIVENESS: my own one-byte-wrong-oracle shim (wraps ~/.cache/aom-oracle/build/aomdec, flips bit0 of ONE byte of ${EC_AV1_FINAL_DUMP}.f0 at byte 328192) run through the gate's own comparator (EC_AV1_AOMDEC=$PWD/shim/aomdec-tamper, EC_AV1_REQUIRE_AOMDEC=1) turns the byte-exact cell RED with "1 bytes differ" at byte 328192 (ours 216 vs 217) — the count moved by exactly +1, and the comparison point is the census's first bad sample. Green baseline on the un-tampered oracle: "17 decode-order frame(s) (1 hidden) byte-exact vs aomdec, 4 windowed palette chroma unit(s)". The crate comparator reads the oracle's dump file bytes and diffs them against ours (stream.rs:10836-10855) — not a self-comparison, so it is the live kind, unlike the withdrawn av1422 re-measurement. +(2) CLAIM 2, my own instrument: a temporary #[cfg(test)] module in my worktree ran aomdec with EC_AV1_FINAL_DUMP against our set_final_dump_prefix dumps and counted wrong u16 SAMPLES per plane over all 17 decode-order frames (352x242 10-bit 4:4:4; dump layout Y,U,V each 352*242 samples). TIP: Y=0 U=0 V=0 on every frame, 0/0/0 total. FIX OUT (only the two palette_window calls reverted, counter left in place): Y=0 U=1166 V=1413, per-frame U = 53,54,54,54,170,54,162,54,58,54,61,54,54,61,61,54,54 and V = 51,51,51,52,160,52,158,52,58,52,158,52,51,156,156,52,51 — a term-for-term match with the report's table. First bad sample on both planes: decode frame 0, row 224, col 64, ours 209 vs oracle 216 (U). +(3) MUTATION PROOF reproduced by name: reverting the two windows reds the gate at stream.rs:10848 with "decode-order frame 0 of 17 (16 shown, 1 hidden) differs from the oracle at byte 328192 (ours 209 vs 216), 104 bytes differ" — identical to the report. Green again on restore (worktree diff empty afterwards). +(4) CLAIM 4 measured on the lane's own sweep .obu files (not the report's numbers): 320x242, 320x250, 352x250, 416x242, 416x250 all 0/0/0 over 17 decode frames AFTER, and 320x242 also 0/0/0 BEFORE the fix. 352x242's sweep .obu is byte-identical to the committed fixture (sha256 84df2f37…a0ad2, 24875 B), so the provenance chain holds. +(5) CLAIM 7 reproduced in a clean worktree at e4787782 with EC_AV1_REQUIRE_AOMDEC=1: "cargo test -p ec-av1 --lib -- 444 420 lossless warp intra --skip bitrate_target_lands_within_5_percent_over_48_frames" -> test result: ok. 178 passed; 0 failed; 2 ignored; 623 filtered out (345.66s). +(6) SEMANTIC CHANGE BEYOND THE TWO WINDOWS (claim 4 of my brief): the diff is exactly 2 sites, 10 insertions / 2 deletions, no offsets or guards touched. The no-op-at-nw*nh==1 property is verified, not assumed: cu_col/cu_row are both 0 when nw*nh==1, so palette_window(buf, chroma_w, 0, 0, uw, uh) with uw=chroma_w, uh=chroma_h is a re-stride copy; and the buffer's own stride equals chroma_w because the map is built by decode_color_index_map_wh(…, cw, ch) with cw=(bw>>ss_x).max(4), and the only case where cw>chroma_w (chroma_w<4, e.g. 4:2:0 bw=4) returns `unsupported` earlier at the (uw,uh) match arm before the palette windowing is reached. Both arms' set_palette_pred are consumed exactly once by the same reconstruct/inline_intra path as before (take_palette_pred at decode.rs:4026/4113), so no new stale-override window. +(7) CLAIM 8 audited mechanically, not by reading: of 98 set_palette_pred sites, all 6 multi-line ones are palette_window hand-offs; every whole-buffer .clone() hand-off that sits lexically near a unit loop was checked by hand (12776, 17281 = single-push whole-block arms; 25542 = an inter-copy 4x4 unit whose buffer is built per unit). No remaining whole-buffer hand-off inside a tiled unit loop. The two 4x8 sub-8 windows that pass ox=0 with only unit_row are single-column walks, so omitting unit_col is correct there. +(8) CLAIM 6's counter: an EC_NWTRACE probe on the pinned fixture shows exactly 4 windowed units = ONE block with nw=1, nh=2, x 2 planes (U,V) x 2 unit rows, so MIN_WINDOWED_UNITS=4 is the exact measured value, and every hit is a genuinely tiled unit. nw>1 is reached NOWHERE in the committed fixture corpus: a corpus-wide sweep (all 106 .obu, tracer on both fixed sites) produced 16 windowed units, all with nw=1; zero with nw>=2. +(9) CLAIM 3 partially re-run: the full 106-fixture before/after oracle sweep (95/1/9/1 -> 96/0/9/1) was NOT re-run — it is ~106 aomdec decodes x2 builds. What I did run: the pinned cell, the six sweep cells, the 178-test regression scope with the oracle REQUIRED, and a corpus-wide decode sweep of all 106 fixtures under my tracer (96 decoded, 10 refused, no panics) — consistent with 9 4:2:2 refusals plus the request-only 440 file, but I did not re-measure per-fixture byte-exactness on the other 95. +RISK: (a) The gate's pixel arm is silently SKIPPED unless an oracle is present — every run above set EC_AV1_REQUIRE_AOMDEC=1; a green run without it proves nothing about pixels. (b) The nw>1 (horizontal) windowing arm of the fixed code is UNMEASURED: it is unreachable in all 106 committed fixtures and in all six 4:4:4 sweep cells. It is correct by construction (a unit's window is cu_col*uw at the block's own chroma_w stride, matching libaom's per-unit ref pointer), but a 4:4:4 stream with a 64-wide luma rect block carrying a UV palette (chroma_w=64 -> uw=32, nw=2) is what it would take, and no such fixture exists. (c) CHROMA_PALETTE_WINDOW_HITS fires on EVERY palette chroma unit, including single-unit blocks where the window is a no-op, so the counter alone does not prove the tiled path ran; the floor of 4 and the byte compare carry that, and the floor would need re-measuring if a second palette-chroma fixture is ever added to the same test. (d) Do not trust the report's claim 3 numbers as re-measured — they are plausible and consistent with everything I measured, but I did not re-run the two-build 106-fixture sweep. (e) The window indexes buf[(oy+r)*stride+ox..][..w] and would panic (or, with a mismatched stride, misread) if a future block shape ever gave cw != chroma_w; today that shape returns `unsupported` first, which is the only thing keeping it safe. + +## Flags (structured) +### P3 Counter doc claims it counts only non-top-left units; it counts every palette chroma unit +file: crates/ec-av1/src/decode.rs:2721-2731 confidence: 0.75 + +The doc comment on CHROMA_PALETTE_WINDOW_HITS (decode.rs:2721-2731, added by eb73ef89) says it counts 'units that are NOT the block's top-left corner', but the hit! sits unconditionally next to set_palette_pred(palette_window(...)) on both fixed lines, so it also fires for nw*nh==1 blocks where the window is a pure re-stride copy of the whole buffer — the exact units the comment says it excludes. Measured on the pinned fixture the two coincide (all 4 hits are nw=1, nh=2), so nothing is mis-gated today, but a reader auditing non-vacuity would conclude the counter proves the TILED arm ran, which the counter cannot distinguish: a stream whose palette chroma blocks are all single-unit would still produce hits >= 1 and pass the reachability assert. Fix the comment to say 'units handed a windowed slice (all palette chroma units on the 32-capped walk; the window is a no-op when nw*nh==1)' and let the MIN_WINDOWED_UNITS floor plus the byte compare carry the tiled-arm claim, or gate the hit! on bigger (nw*nh > 1) if the tiled arm is what it is meant to witness. +