From ff41e00f40913a2c86c3cc3e4fe817363d0bbe16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 1 Oct 2026 14:02:49 +0300 Subject: [PATCH] lane-av1unwritten r2: refuse the subsize libaom calls corrupt, not a TX_4X8 unit Refutation (Agent03-5, verified by Main) killed this lane's first fix: the TX_4X8 chroma arm it landed was a port of behaviour libaom does not have. get_plane_block_size is a single indexed return, av1_ss_size_lookup[bsize] [ss_x][ss_y] (blockd.h:1186-1193) -- no per-axis MIN -- and BLOCK_4X8 at ss (1,0) is BLOCK_INVALID, so libaom never reaches max_txsize_rect_lookup for that shape. That arm, its chroma-extent derivation and its coverage gate are all reverted. What is actually wrong is a MISSING REFUSAL. aomdec on the pinned witness: Failed to decode frame 1: Corrupt frame detected Additional information: Block size 8x16 invalid with this subsampling mode decode_partition checks exactly that before descending into a subsize (decodeframe.c:1449-1458): get_plane_block_size(subsize, ss_x, ss_y) == BLOCK_INVALID is AOM_CODEC_CORRUPT_FRAME. So a 4:2:2 header over a 4:2:0 tile names subsizes that have no chroma plane block, and the nondeterministic output was what decoding them anyway looks like downstream. Fix: chroma_plane_block_codable() (the four BLOCK_INVALID cells of av1_ss_size_lookup, nothing else) + refuse_invalid_plane_block(), a RETURNED error carrying libaom's own wording -- never an assert!, since a partition symbol is stream data. Installed where a partition symbol becomes a strip subsize with a chroma plane block: partition_w8 -> 8x4 / 4x8, partition_w16 -> 16x8 / 8x16. The PARTITION_HORZ_4 / VERT_4 1:4 sites (4x16 / 16x4) are a named gap, not silently left out. Gates: a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt (refusal + libaom's wording + a genuine 4:2:2 positive control so it cannot pass by refusing everything); the_440_cell_is_not_a_codable_chroma_shape's lane-av1422lift "it decodes" arm realigned to the same contract, its 4:4:0- request-lands-on-4:2:2 claim untouched. Corpus: all 127 fixtures decoded on both trees and every EC_AV1_FINAL_DUMP frame hashed -- the only difference is the witness, which now refuses; the other 126 are byte-identical. Kept: the EC_AV1_PLANE_SENTINEL-gated census instrument (census_unwritten, set_plane_sentinel, take_unwritten_samples, take_census_scanned) that found the class. Its comment no longer claims a flag it does not have. --- crates/ec-av1/src/decode.rs | 181 +++++++------- crates/ec-av1/src/stream.rs | 151 ++++++------ lanes/av1unwritten.report.md | 449 ++++++++++++++--------------------- 3 files changed, 350 insertions(+), 431 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 4cea1fb9..65652d39 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21235,9 +21235,10 @@ fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { } } -/// `EC_AV1_SENTINEL_CENSUS=1`: at each frame's pre-deblock point, print an +/// Enabled by `EC_AV1_PLANE_SENTINEL` (there is no separate flag for it): at +/// each frame's pre-deblock point, print an /// EXACT census of the samples the tile walk never wrote -- with -/// `EC_AV1_PLANE_SENTINEL=1` every plane still holding [`PLANE_SENTINEL`] at +/// it, every plane still holding [`PLANE_SENTINEL`] at /// this point is a sample no block reconstructed, and no legal sample can /// equal `0xDEAD` (reconstruction clamps to `(1 << bit_depth) - 1`). /// @@ -21342,6 +21343,54 @@ fn plane_sentinel_on() -> bool { || PLANE_SENTINEL_ON.with(std::cell::Cell::get) } +/// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this +/// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] != +/// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every +/// subsize before descending into it: +/// +/// ```c +/// if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == +/// BLOCK_INVALID) +/// aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, +/// "Block size %dx%d invalid with this subsampling mode", ...); +/// ``` +/// (`decodeframe.c:1449-1458`). Only the four cells that are ever BLOCK_INVALID +/// are listed, from that table's rows: +/// BLOCK_4X8 `{BLOCK_4X8, BLOCK_4X4 | BLOCK_INVALID, BLOCK_4X4}`, +/// BLOCK_8X4 `{BLOCK_8X4, BLOCK_INVALID | BLOCK_4X4, BLOCK_4X4}`, +/// BLOCK_8X16 `{BLOCK_8X16, BLOCK_8X8 | BLOCK_INVALID, BLOCK_4X8}`, +/// BLOCK_16X4 `{BLOCK_16X4, BLOCK_INVALID | BLOCK_8X8, BLOCK_4X4}`. +/// +/// So at 4:2:2 a 4x8, 8x16 or 16x4 subsize is NOT DECODABLE: libaom rejects +/// the frame outright and never reaches a transform size for it. This decoder +/// walked those subsizes anyway, and the chroma plane block it then covered was +/// a different shape than the luma one -- on the pinned +/// `440_request_is_422.obu` (a 4:2:2 sequence header over a 4:2:0 key frame's +/// tile) that left whole 4x4 chroma blocks unwritten and the output hash +/// CHANGED RUN TO RUN. `aomdec` on the same file: +/// `Failed to decode frame 1: Corrupt frame detected` / `Block size 8x16 +/// invalid with this subsampling mode`. +fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { + match (bw, bh) { + (4, 8) => (sx, sy) != (1, 0), + (8, 4) => (sx, sy) != (0, 1), + (8, 16) => (sx, sy) != (1, 0), + (16, 4) => (sx, sy) != (1, 0), + _ => true, + } +} + +/// [`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. +fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::FrameCtx) -> Error { + unsupported( + "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this \ + frame's subsampling mode (libaom: \"Block size %dx%d invalid with this subsampling \ + mode\", av1/decoder/decodeframe.c:1456, refusing by the same rule)", + ) +} + /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`, /// at most 4095), so a decode that hashes identically under the flag proves @@ -26454,9 +26503,8 @@ fn sub8_leaf_chroma422( // units -- which is exactly what the two chroma-reference leaves of the // `decode_leaf_split4` route below already emit, so the square arms stay // for lossless. - let rect48 = leaf_shape == (4, 8) && !lossless(fctx); let tx_w = 4 << ss_x(fctx); - let tx_h = (if rect48 { 8 } else { 4 }) << ss_y(fctx); + let tx_h = 4 << ss_y(fctx); let reach = Reach::of_tu_chroma( mi_bw, mi_bh, @@ -26472,95 +26520,15 @@ fn sub8_leaf_chroma422( py > 0 && px + (tx_w << ss_x(fctx)) < y.width, px > 0 && py + (tx_h << ss_y(fctx)) < y.height, ); - let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, if rect48 { 8 } else { 4 }); + let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint, // anchored at the same FLOORED luma x the write/prediction anchor below // uses -- `px` (the odd leaf's own luma x) steps half the span into the // RIGHT neighbour group (t422 frame-1 leaf (1,23): the unit reconstructs // chroma px 44..47 from luma 88..95, while a `px`-anchored source // averaged luma 92..99 and every CFL unit of the group mismatched). - let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, if rect48 { 8 } else { 4 })); - let grids: (Grid, Grid) = if rect48 { - // The 4:2:2 vert pair's ONE chroma reference codes the PAIR's whole - // 4x8 chroma plane block. libaom reaches the same unit through - // `decode_token_recon_block`'s plane/row/col loop with - // `tx_size = av1_get_tx_size(1, xd)` == TX_4X8 (stepr/stepc = 2/1 over - // `unit_height = ROUND_POWER_OF_TWO(min(mu_blocks_high + row, - // max_blocks_high), ss_y)` = 2 and `unit_width` = 1, i.e. one - // iteration), so [`leaf8_chroma422_unit`] -- the port of that walk for - // a BLOCK_8X8 leaf -- is the unit, unchanged. The DV arms supply the - // frame copy through `pred_override`, which is how the BLOCK_8X8 leaf - // hands the same two intrabc shapes over. - let (ub, vb) = match intrabc_dv { - Some(dv) => { - let mut ub = vec![0u16; 4 * 8]; - mc::predict_with_filter( - &u.data, - u.width, - u.true_width, - u.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), - mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, - 8, - mc::InterpFilterKind::Bilinear, - &mut ub, - fctx, - ); - let mut vb = vec![0u16; 4 * 8]; - mc::predict_with_filter( - &v.data, - v.width, - v.true_width, - v.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), - mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, - 8, - mc::InterpFilterKind::Bilinear, - &mut vb, - fctx, - ); - (Some(ub), Some(vb)) - } - None => (None, None), - }; - let u_grid = leaf8_chroma422_unit( - dec, - cdfs, - chroma_around[1], - uv_predict_mode, - angle_delta_uv, - reach, - 1, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - skip, - ub, - u, - cpx, - cpy, - smooth_neighbor_uv, - fctx, - )?; - let v_grid = leaf8_chroma422_unit( - dec, - cdfs, - chroma_around[2], - uv_predict_mode, - angle_delta_uv, - reach, - 2, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - skip, - vb, - v, - cpx, - cpy, - smooth_neighbor_uv, - fctx, - )?; - (u_grid, v_grid) - } else if let Some(dv) = intrabc_dv.filter(|_| skip) { + let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, 4)); + let grids: (Grid, Grid) = if let Some(dv) = intrabc_dv.filter(|_| skip) { // lane-av1422ctattr: a SKIPPED intrabc chroma leaf still predicts the // frame copy at its DV. libaom's `decode_token_recon_block` takes the // INTER arm for an intrabc block (`is_inter_block` counts it, @@ -36268,6 +36236,24 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( sc * SUB_MI as usize ); } + if part16 == PARTITION_HORZ || part16 == PARTITION_VERT + { + let (bw, bh) = if part16 == PARTITION_HORZ { + (16, 8) + } else { + (8, 16) + }; + if !chroma_plane_block_codable( + bw, + bh, + ss_x(fctx), + ss_y(fctx), + ) { + return Err(refuse_invalid_plane_block( + bw, bh, fctx, + )); + } + } if part16 == PARTITION_NONE { decode_block( &mut dec, @@ -36638,6 +36624,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" ); } + if part8 == PARTITION_HORZ + || part8 == PARTITION_VERT + { + // libaom's `subsize_lookup`: HORZ on an 8x8 is + // BLOCK_8X4, VERT is BLOCK_4X8. + let (bw, bh) = if part8 == PARTITION_HORZ { + (8, 4) + } else { + (4, 8) + }; + if !chroma_plane_block_codable( + bw, + bh, + ss_x(fctx), + ss_y(fctx), + ) { + return Err(refuse_invalid_plane_block( + bw, bh, fctx, + )); + } + } let leaf_mode = if part8 == PARTITION_NONE { decode_leaf8( &mut dec, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 71ecc863..87b5db5a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2829,93 +2829,92 @@ pub(crate) mod tests { ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \ format." ); - // lane-av1422lift: the refusal is gone, and the replacement is NOT - // "it decodes". This pin's TILE is a 4:2:0 key frame's, byte for - // byte -- only the sequence header carries 4:2:2 -- so it is a - // header/tile mismatch and there is no oracle that can say what the - // right pixels are. What IS assertable, and is what the pin is for, - // is that the SEQUENCE HEADER alone decides the decode's geometry: - // the decoded chroma planes are half-width and FULL height, exactly - // the `round_ss(w, 1) x round_ss(h, 0)` shape a real 4:2:2 stream - // produces (see `a_real_422_key_frame_and_inter_sequence_decode_ - // pixel_exact` for the pixel claim on genuine 4:2:2 bytes), and that - // the 4:2:2 chroma walk really ran on it. A decoder that still - // allocated 4:2:0 planes here would give 32x32 chroma and red. - let frames = decode_stream(&pinned).unwrap_or_else(|e| { - panic!("{NAME}: a (1,0) header must decode now that 4:2:2 is admitted: {e}") + // lane-av1unwritten: lane-av1422lift replaced the old 4:2:2 header + // refusal with "it decodes, and the decoded chroma planes are 32x64". + // That was the wrong contract for THIS pin: its frame OBU is a 4:2:0 + // key frame's, so at 4:2:2 its partition symbols name subsizes with no + // chroma plane block, which libaom rejects as a corrupt frame + // ("Block size 8x16 invalid with this subsampling mode", + // decodeframe.c:1456) and `aomdec` does. The replacement is the + // REFUSAL, by that rule. + // + // The pin's remaining job is unchanged and still worth saying: it + // proves a 4:4:0 REQUEST at profile 2 lands on 4:2:2 (1,0), i.e. that + // `the_440_cell_is_not_a_codable_chroma_shape`'s claim is still true. + let err = decode_stream(&pinned).err().unwrap_or_else(|| { + panic!( + "{NAME}: the pin is a 4:2:2 header over a 4:2:0 tile -- libaom refuses it \ + (aomdec: \"Block size 8x16 invalid with this subsampling mode\"), and so \ + must we" + ) }); - assert_eq!( - frames.len(), - 1, - "{NAME}: the pin must decode exactly one frame" + assert!( + err.to_string() + .contains("invalid with this subsampling mode"), + "{NAME}: the refusal must name libaom's rule, got: {err}" ); - assert_eq!( - (frames[0].u.len(), frames[0].v.len()), - (32 * 64, 32 * 64), - "{NAME}: 64x64 4:2:2 is HALF WIDTH and FULL HEIGHT (32x64 chroma); {:?} means the \ - plane geometry still came from the TILE's 4:2:0 shape rather than the HEADER's", - (frames[0].u.len(), frames[0].v.len()) - ); - assert!( - crate::decode::census_nonsub_units()[1] > 0 - && crate::decode::census_nonsub_units()[2] > 0, - "{NAME}: the pin walked zero 4:2:2 chroma coefficient units -- the per-axis walk never \ - ran on it" - ); - } - - /// lane-av1unwritten: the same pin decoded NONDETERMINISTICALLY. Its - /// 4:2:2 header hands the chroma planes 4x8 blocks (libaom's - /// `av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)` == TX_4X8), and this - /// decoder's `sub8_leaf_chroma422` wrote a single square TX_4X4 per - /// chroma reference -- so the bottom four chroma rows of every 8x8 - /// `PARTITION_HORZ` group were never written at all and the uninitialised - /// plane memory reached the output: five runs of the one file gave five - /// different `EC_AV1_FINAL_DUMP` hashes while every census count read - /// identical. - /// - /// The property pinned here is the one that stops that: with freshly - /// allocated planes filled with `PLANE_SENTINEL` (a value no legal sample - /// can equal), the decode must leave NO sample still holding it. A - /// wrong-sample diff cannot assert this -- it cannot tell an unwritten - /// sample from a mis-predicted one -- and `take_census_scanned` is read - /// alongside so a census that scanned nothing cannot pass as a census - /// that found nothing. - #[test] - fn a_422_header_over_a_420_tile_leaves_no_sample_unwritten() { - const NAME: &str = "a_422_header_over_a_420_tile_leaves_no_sample_unwritten"; - struct Sentinel(bool); - impl Drop for Sentinel { - fn drop(&mut self) { - crate::decode::set_plane_sentinel(self.0); - } - } + // The pixels this pin never had: the sibling gate + // `a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt` + // pins the refusal plus a genuine 4:2:2 positive control, and every + // real 4:2:2 exactness claim lives on genuinely 4:2:2 pins in this + // file. + } + + /// lane-av1unwritten: this pin is a MISSING REFUSAL, not a pixel defect. + /// + /// `440_request_is_422.obu` is a 4:2:2 sequence header wrapped around a + /// 4:2:0 key frame's tile, so the tile's partition symbols make subsizes + /// (8x16 among them) that have NO chroma plane block at ss (1,0). libaom + /// refuses exactly that, before descending into the subsize: + /// + /// ```text + /// $ aomdec --rawvideo -o /dev/null fixtures/440_request_is_422.obu + /// Warning: Failed to decode frame 1: Corrupt frame detected + /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode + /// ``` + /// + /// (`av1/decoder/decodeframe.c:1449-1458`, + /// `get_plane_block_size(subsize, ss_x, ss_y) == BLOCK_INVALID` -> + /// `AOM_CODEC_CORRUPT_FRAME`.) We walked those subsizes instead, and the + /// first version of this lane misread the downstream symptom -- a chroma + /// plane block covered by a square unit, whole 4x4 blocks left unwritten, + /// and a `EC_AV1_FINAL_DUMP` hash that CHANGED RUN TO RUN because the + /// unwritten samples were uninitialised plane memory. + /// + /// The contract pinned here is the one libaom has: the pin REFUSES, by a + /// named error that says which shape and which subsampling mode. The + /// positive control is a genuinely 4:2:2 pin, which must still decode -- + /// so this gate cannot pass by refusing everything. + #[test] + fn a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt() { + const NAME: &str = "a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt"; let _gate_lock = lock_gate_counters(); let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) .join("fixtures") .join("440_request_is_422.obu"); let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); - crate::decode::set_plane_sentinel(true); - let _sentinel = Sentinel(false); - crate::decode::take_unwritten_samples(); - crate::decode::take_census_scanned(); - let frames = - decode_stream(&pinned).unwrap_or_else(|e| panic!("{NAME}: the pin must decode: {e}")); - assert_eq!(frames.len(), 1, "{NAME}: the pin decodes exactly one frame"); - let scanned = crate::decode::take_census_scanned(); - let unwritten = crate::decode::take_unwritten_samples(); + let err = decode_stream(&pinned) + .err() + .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); + let msg = err.to_string(); assert!( - scanned >= 64 * 64 + 2 * 32 * 64, - "{NAME}: the sentinel census scanned only {scanned} samples -- a census that \ - looked at less than the whole frame proves nothing" + msg.contains("invalid with this subsampling mode"), + "{NAME}: the refusal must name the rule it refuses by (libaom's own wording), got: \ + {msg}" ); - assert_eq!( - unwritten, 0, - "{NAME}: {unwritten} samples of the frame were handed to the tile walk and never \ - written, so they reach the output as whatever the allocator left there (the five \ - different dump hashes this pin used to give)" + // Positive control: a real 4:2:2 stream must still decode, so the gate + // cannot pass by refusing everything. + let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures") + .join("422_key_64x64.obu"); + let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) + .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); + assert!( + !ok.is_empty(), + "{NAME}: the 4:2:2 control decoded no frames" ); } + /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned /// as fixtures (`git add -f`; `fixtures/` is gitignored). /// diff --git a/lanes/av1unwritten.report.md b/lanes/av1unwritten.report.md index 8bc957e6..99318c3d 100644 --- a/lanes/av1unwritten.report.md +++ b/lanes/av1unwritten.report.md @@ -1,325 +1,238 @@ -# lane/av1unwritten — a 4:2:2 chroma block the walk never covered +# lane/av1unwritten — a MISSING REFUSAL, not an unwritten chroma unit -**Outcome in one line: `sub8_leaf_chroma422` wrote ONE square `TX_4X4` where libaom -writes ONE `TX_4X8` (`av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)`), so every 4:2:2 -8x8 block coded `PARTITION_HORZ` left the bottom four chroma rows unwritten and -the uninitialised plane memory reached the output; the fix routes that shape to -the port that already exists for a `BLOCK_8X8` leaf (`leaf8_chroma422_unit`), and -a new sentinel-census gate pins "the walk wrote every sample it was handed".** +**Outcome in one line: `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 calls that `AOM_CODEC_CORRUPT_FRAME` +("Block size 8x16 invalid with this subsampling mode") and `aomdec` refuses the +file outright; we walked those subsizes, and the nondeterministic output was the +symptom. The fix mirrors libaom's own check and returns a named refusal; the +sentinel census that found the class is kept as the instrument.** Branch `lane/av1unwritten`, base `main` = `8d6998d7`. No push. +> **This report was rewritten.** The first version of this lane claimed a libaom +> `TX_4X8` chroma unit for a `BLOCK_4X8` subsize and landed a port of it. The +> refutation pass (Agent03-5, verified first-hand by Main) showed that port does +> not exist: `get_plane_block_size` is a single indexed return +> (`av1_ss_size_lookup[bsize][ss_x][ss_y]`, `blockd.h:1186-1193`), BLOCK_4X8 at +> ss (1,0) is `BLOCK_INVALID`, and libaom never reaches +> `max_txsize_rect_lookup` for that shape because it refuses the frame first. +> The `TX_4X8` arm, its chroma-extent derivation and its gate are all GONE; what +> follows is the corrected lane. The corrected findings are in §1–§2 and the +> correction itself is recorded here rather than quietly edited in. + --- -## 1. Reproduction: five runs, five hashes +## 1. The oracle decides this, not our reasoning ``` -$ cd /home/user/.cache/wt/av1unwritten -$ cargo build -p ec-av1 --example decode_probe --features gate-counters -$ mkdir -p /tmp/wt_aw -$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/u$i \ - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \ - >/dev/null 2>&1; sha256sum /tmp/wt_aw/u$i.f0; done -de5051156b7cfd00dc7ed5f2c6ad404e2a49822a8a728bc027a938aac00219f1 /tmp/wt_aw/u1.f0 -eb0e513ff07d9780b03e70861d1a7f507f540e4724f62384511a71e06c386aa9 /tmp/wt_aw/u2.f0 -2985b82874579807efb8bc88136d1b8f5f1f0121410cde26723d5be7e6ba8715 /tmp/wt_aw/u3.f0 -204645ad20d7e557d7b04f0027d9aafd5790fe685dc39bdf7cfb117d9dd1f0fc /tmp/wt_aw/u4.f0 -80908a1712c4fe78070a6a3ad57464e8bd6a9d0b8d73e86e8f9cf7ea7cbd3496 /tmp/wt_aw/u5.f0 +$ ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null \ + crates/ec-av1/fixtures/440_request_is_422.obu +Warning: Failed to decode frame 1: Corrupt frame detected +Warning: Additional information: Block size 8x16 invalid with this subsampling mode ``` -Five hashes from one file. Under `EC_AV1_PLANE_SENTINEL=1` the same five runs give -ONE hash — the output difference is exactly the samples the decode never wrote. - -### 1.1 The instrument (now committed) +We decoded it. That is the defect. -`EC_AV1_SENTINEL_CENSUS=1` (new, `decode::census_unwritten`, called at each -frame's pre-deblock point beside the existing `EC_AV1_PREFILT_DUMP16` rung, on -both the key-frame and inter-frame paths) scans each plane over its own -`true_width` x `true_height` extent and prints, per plane, the number of samples -still holding `PLANE_SENTINEL` plus every hole as per-row column spans. This is -the shipped form of the four-line temporary scan `lanes/av1422seed.report.md` §3 -used; the report explicitly noted it was *not* committed, which is why this lane -had to re-derive it. +`av1/decoder/decodeframe.c:1449-1458`, in `decode_partition`, before it descends +into any subsize: -``` -$ EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 \ - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 >/dev/null -SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 -SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=112 spans=24: - y36 x0..=3 y36 x12..=15 y37 x0..=3 y37 x12..=15 y38 x0..=3 y38 x12..=15 y39 x0..=3 y39 x12..=15 - y44 x4..=7 y44 x12..=15 y45 x4..=7 y45 x12..=15 y46 x4..=7 y46 x12..=15 y47 x4..=7 y47 x12..=15 - y52 x0..=7 y53 x0..=7 y54 x0..=7 y55 x0..=7 y60 x0..=3 y61 x0..=3 y62 x0..=3 y63 x0..=3 -SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=112 spans=24: (identical) +```c +const struct macroblockd_plane *const pd_u = &xd->plane[1]; +if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == + BLOCK_INVALID) { + xd->mi_row = mi_row; + aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, + "Block size %dx%d invalid with this subsampling mode", + block_size_wide[subsize], block_size_high[subsize]); +} ``` -**112 samples per chroma plane, 0 luma.** Both chroma planes, so the census is -not a one-sided artefact. +`get_plane_block_size` (`blockd.h:1186-1193`) is a **single indexed return**, +`av1_ss_size_lookup[bsize][subsampling_x][subsampling_y]` — no per-axis MIN. The +`BLOCK_INVALID` cells in that table (`common_data.c:20-26`) are: -### 1.2 The holes are whole 4x4 chroma blocks, and each is a whole block's bottom half +| subsize | ss (0,0) 4:4:4 | ss (0,1) | ss (1,0) 4:2:2 | ss (1,1) 4:2:0 | +|---|---|---|---|---| +| 4x8 | 4x8 | 4x4 | **INVALID** | 4x4 | +| 8x4 | 8x4 | **INVALID** | 4x4 | 4x4 | +| 8x16 | 8x16 | 8x8 | **INVALID** | 4x8 | +| 16x4 | 16x4 | **INVALID** | 8x8 | 4x4 | -Grouped as blocks, the six spans are six 4x4 chroma blocks (two of the spans are -8 wide = two blocks): +So at 4:2:2 a **4x8, 8x16 or 16x4** subsize is not decodable at all. It is not a +"the chroma unit is 4x8" case: libaom never computes a transform size for it. +(The earlier `8x16` in the oracle's message is the first such subsize the +witness's 4:2:0 tile presents; 4x8 and 16x4 are in the same class.) -| chroma block (x, y) | luma extent (2x, y..y+3) | owning luma group | -|---|---|---| -| (0..3, 36..39) | (0..7, 36..39) | 8x8 group at luma (0, 32), `PARTITION_HORZ` -> two `BLOCK_4X8` | -| (12..15, 36..39) | (24..31, 36..39) | 8x8 group at luma (24, 32), `PARTITION_HORZ` | -| (4..7, 44..47) | (8..15, 44..47) | 8x8 group at luma (8, 40), `PARTITION_HORZ` | -| (12..15, 44..47) | (24..31, 44..47) | 8x8 group at luma (24, 40), `PARTITION_HORZ` | -| (0..3, 52..55) + (4..7, 52..55) | (0..15, 52..55) | 8x8 groups at luma (0, 48) and (8, 48), `PARTITION_HORZ` | -| (0..3, 60..63) | (0..7, 60..63) | 8x8 group at luma (0, 56), `PARTITION_HORZ` | - -The blocks that *should* have written each hole did write their luma and their -top four chroma rows; the hole is always the **lower half of a 4x8 chroma plane -block**, never anything else. - -### 1.3 Which arm, and what the tile walk does not code - -Localised with a temporary probe (since removed) on the three -`PlaneBuf` sinks — every reconstruction store was recorded with its plane and -extent and the census's holes were attributed to owners: - -``` -SUB8_C422 lmi=(8,1) leaf=(4, 8) cpx=0 cpy=32 -SUB8_C422 lmi=(10,3) leaf=(4, 8) cpx=4 cpy=40 -SUB8_C422 lmi=(8,7) leaf=(4, 8) cpx=12 cpy=32 -SUB8_C422 lmi=(10,7) leaf=(4, 8) cpx=12 cpy=40 -SUB8_C422 lmi=(12,1) leaf=(4, 8) cpx=0 cpy=48 -SUB8_C422 lmi=(12,3) leaf=(4, 8) cpx=4 cpy=48 -SUB8_C422 lmi=(14,1) leaf=(4, 8) cpx=0 cpy=56 -SUB8_C422 lmi=(14,3) leaf=(4, 4) cpx=4 cpy=56 -SUB8_C422 lmi=(15,3) leaf=(4, 4) cpx=4 cpy=60 -``` - -Every arm is `sub8_leaf_chroma422` (`decode.rs`, reached from -`decode_leaf_rect8`'s three chroma-reference call sites and from -`decode_leaf_split4`). Each writes one **4x4** chroma unit at `(cpx, cpy)`. The -seven `leaf=(4, 8)` entries are the chroma references of the seven -`PARTITION_HORZ` groups in §1.2, and `cpy` is the group's TOP row — the bottom -row is never visited, by any arm, on any plane. +`PARTITION_HORZ` on an 8x8 is `subsize_lookup[HORZ][BLOCK_8X8] = BLOCK_8X4`, +whose 4:2:2 plane block is BLOCK_4X4 — the square unit, which is why the +`(4, 8)` chroma path itself was never wrong. `BLOCK_4X8` leaves come from +`PARTITION_VERT`, i.e. from `decode_leaf_rect8(vert = true)`, and that subsize is +exactly one of the four libaom refuses. --- -## 2. Is this reachable on a stream this decoder is supposed to accept? - -**Yes — the shape is legal AV1 syntax and a 4:2:2 stream can carry it. The -committed corpus happens to contain none.** +## 2. What the symptom looked like, and how the census found it -### 2.1 Corpus sentinel sweep (all 127 committed fixtures) +`440_request_is_422.obu` is what `examples/gen_coverage_cells.rs` produces when +the writer is handed `subsampling (0, 1)` at profile 2: the header lands on 4:2:2 +and the frame OBU behind it is a real 4:2:0 key frame's, byte for byte. The +header/tile chroma mismatch is exactly what produces a subsize whose plane block +does not exist. ``` -$ for f in crates/ec-av1/fixtures/*.obu; do \ - out=$(EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 timeout 120 \ - ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep SENTINEL_CENSUS); \ - if echo "$out" | grep -qv 'unwritten=0'; then echo "=== $(basename $f)"; \ - echo "$out" | grep -v 'unwritten=0'; fi; done -=== 440_request_is_422.obu -SENTINEL_CENSUS idx=0 plane=U ... unwritten=112 ... -SENTINEL_CENSUS idx=0 plane=V ... unwritten=112 ... +$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/u$i \ + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \ + >/dev/null 2>&1; sha256sum /tmp/wt_aw/u$i.f0; done +de5051156b7cfd00dc7ed5f2c6ad404e2a49822a8a728bc027a938aac00219f1 /tmp/wt_aw/u1.f0 +eb0e513ff07d9780b03e70861d1a7f507f540e4724f62384511a71e06c386aa9 /tmp/wt_aw/u2.f0 +2985b82874579807efb8bc88136d1b8f5f1f0121410cde26723d5be7e6ba8715 /tmp/wt_aw/u3.f0 +204645ad20d7e557d7b04f0027d9aafd5790fe685dc39bdf7cfb117d9dd1f0fc /tmp/wt_aw/u4.f0 +80908a1712c4fe78070a6a3ad57464e8bd6a9d0b8d73e86e8f9cf7ea7cbd3496 /tmp/wt_aw/u5.f0 ``` -126 of 127 fixtures — 4:2:0 (lossless, mixed-lossless, tall 8x16/16x8, odd -65x65, odd heights, altref, intrabc), 4:4:4 (lossless 128-root mu-chroma, -palette, rect4 444 at 8/10-bit), and 4:2:2 at 8/10/12-bit including -`Y_intrabc_10b.obu`, `X_intrabc_tiled.obu`, `W_intrabc.obu`, the `s422_*` -slices, grain and superres cells — have a **fully written** census on every -frame of every plane. Only the hand-built witness does not. - -### 2.2 Why the corpus cannot see it: the defective shape has zero reach on valid streams +Five hashes from one file, with every census count identical — the difference was +purely the samples the walk never wrote. -Same sweep, counting arm entries and how many carry the `leaf=(4, 8)` shape: +`EC_AV1_PLANE_SENTINEL=1` (the census has no separate flag) plus the new +`EC_AV1_SENTINEL_CENSUS` printout — the shipped form of the four-line temporary +scan `lanes/av1422seed.report.md` §3 used and explicitly did not commit — gave an +exact census at each frame's pre-deblock point: ``` -$ for f in crates/ec-av1/fixtures/*.obu; do \ - n=$(EC_RECON_TRACE=1 ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep -c SUB8_C422); \ - if [ "$n" != 0 ]; then v=$(... grep -c 'SUB8_C422.*leaf=(4, 8)'); \ - echo "$(basename $f) c422=$n vert48=$v"; fi; done -422_inter_160x128_3f.obu c422=29 vert48=0 -422_key_64x64.obu c422=2 vert48=0 -422_palette_intra_in_inter_384x240_17f c422=158 vert48=0 -422_residual_compound_warp_16f.obu c422=257 vert48=0 -422_residual_compound_warp_nolr_16f.obu c422=256 vert48=0 -440_request_is_422.obu c422=9 vert48=7 <-- the only one -W_intrabc.obu c422=391 vert48=0 -X_intrabc_tiled.obu c422=333 vert48=0 -Y_intrabc_10b.obu c422=539 vert48=0 -s422_12bit_160x128.obu c422=185 vert48=0 -s422_320x246.obu c422=162 vert48=0 -s422_322x240.obu c422=195 vert48=0 -s422_322x246.obu c422=155 vert48=0 -s422_352x242_10b.obu c422=169 vert48=0 -s422_416x242_10b.obu c422=176 vert48=0 -s422_416x250_10b.obu c422=198 vert48=0 -s422_grain_160x128.obu c422=45 vert48=0 -s422_superres_160x128.obu c422=45 vert48=0 +SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 +SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=112 spans=24: (six 4x4 blocks) +SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=112 spans=24: (identical) ``` -3528 real `sub8_leaf_chroma422` invocations across the 4:2:2 corpus, **zero** of -the `leaf=(4, 8)` shape. So: - -* the DEFECT is not corpus-faked — the arm is heavily used and every other shape - is right; -* the defect is latent, not observed, on valid streams, because no committed - 4:2:2 stream codes an 8x8 block with `PARTITION_HORZ`. - -**Latent does not mean absent.** AV1's 8x8 partition set is the full -`PARTITION_TYPES` (`partition_cdf_length`, `av1_common_int.h:1555-1560`: `bsize -<= BLOCK_8X8` gets all eight), so `PARTITION_HORZ` at 8x8 is codable, and libaom -decodes it through exactly the path below. The witness's tile is a genuine 4:2:0 -key frame's tile, so the `PARTITION_HORZ` groups it carries are ordinary legal -partition symbols — the header/tile chroma mismatch changes only the geometry -they are decoded against. - -### 2.3 What libaom does here (the derivation, from source) - -1. `av1/decoder/decodeframe.c`, `decode_partition` -> `parse_decode_block` - (`decodeframe.c:1229`) runs once **per leaf**, so a `PARTITION_HORZ` 8x8 group - reaches `decode_token_recon_block(pbi, td, r, BLOCK_4X8)` once per leaf. -2. `decode_token_recon_block` (`:993-1041`) skips the chroma planes when - `!xd->is_chroma_ref`. `is_chroma_reference` (`av1_common_int.h:1454-1461`) is - `((mi_row & 1) || !(bh & 1) || !ss_y) && ((mi_col & 1) || !(bw & 1) || !ss_x)`. - For `BLOCK_4X8` at ss (1,0): `bw=1` -> the column clause is `mi_col & 1`, so - **only the odd-column leaf codes chroma**; the row clause is `true` because - `!ss_y`. That is the crate's `!vert || i == 1` in `decode_leaf_rect8`, and it - is right. -3. For the chroma reference leaf, `tx_size = av1_get_tx_size(1, xd)` - (`blockd.h:1381-1388`) = `av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)` - (`blockd.h:1372-1379`) = `max_txsize_rect_lookup[get_plane_block_size( - BLOCK_4X8, 1, 0)]`. `get_plane_block_size` takes the **per-axis MIN** of the - two `av1_ss_size_lookup` entries, so `min(BLOCK_INVALID, BLOCK_4X8)` = - `BLOCK_4X8`, and `max_txsize_rect_lookup[BLOCK_4X8]` (`common_data.h:126-127`) - is **`TX_4X8`**. (At lossless, `av1_get_tx_size`'s first line returns `TX_4X4` - on every plane, `blockd.h:1383`.) -4. The walk loop at `:1011-1033` with `tx_size = TX_4X8`: - `max_block_wide/high` are in MI units (`blockd.h:1565-1594`) = 1 and 2; - `tx_size_high_unit[TX_4X8] = 2`, `stepc = tx_size_wide_unit[TX_4X8] = 1` - (`common_data.h:246-253`). `blk_row = 0` only, `blk_col = 0` only: - **one `TX_4X8` unit covering the whole 4x8 chroma plane block.** - -This decoder instead emitted a single `TX_4X4` (`read_plane(..., 4, TX4, ...)` -then `push_intra(..., 4, ...)`) — half the plane block. At lossless the existing -square model is the *correct* one (`TX_4X4` per unit, two stacked units), which -is why the arm's `leaf=(4, 4)` path and the `decode_leaf_split4` route are -untouched by this fix. +Whole 4x4 chroma blocks, and each was the lower half of the plane block of one of +the subsizes §1 says are not decodable. That is the whole chain: the walk +accepted a subsize libaom refuses, and the chroma plane block it then covered +was shaped differently from the luma one. + +The instrument is **kept**: it is env-gated, off by default, and it is the only +way to ask "did the tile walk write every sample it was handed" (a wrong-sample +diff cannot tell an unwritten sample from a mis-predicted one). --- ## 3. The fix -`crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma422`, one new branch: - -```rust -let rect48 = leaf_shape == (4, 8) && !lossless(fctx); -``` +`crates/ec-av1/src/decode.rs`: -When it holds, the arm hands the PAIR's whole 4x8 chroma plane block to -`leaf8_chroma422_unit` — the port that already exists for a `BLOCK_8X8` 4:2:2 -leaf (`TxbSet::ChromaRect8x4` + `SCAN_4X8` + `read_coeffs_rect(4, 8, ..)` + -`dequant_and_inverse_typed_wh(4, 8, ..)` + `push_intra_rect(.., 4, 8, ..)`, whose -own doc cites the identical `av1_get_max_uv_txsize` derivation). The two intrabc -shapes hand their frame copy over through that function's existing -`pred_override` parameter, which is how the `BLOCK_8X8` leaf passes the same two -cases. Alongside it, three sub-8-specific inputs follow the unit's new height: -the reach (`tx_h = 8 << ss_y`), the entropy context -(`around_mi_422_chroma(ctx_mi, 8, 8)`) and the CfL AC span -(`cfl_src_rect(floored_x, py, 8, 8)`). - -The three existing square arms stay for `leaf=(4, 4)` (the `decode_leaf_split4` -route, one `TX_4X4` per odd-column leaf, which tiles 4x8 correctly) and for -lossless (two stacked `TX_4X4`, which is what libaom walks there). - -**Why a real fix and not a detection/padding.** Refusal is not available: the -sequence header is self-consistent AV1 and the partition/mode syntax is -subsampling-independent, so the tile parses with no signal that the header and -the tile disagree — there is nothing to detect. Pre-filling the plane with 0 or -with a mid-grey would hide the class and still emit wrong pixels. Making the -walk cover the block it was handed is the only real answer, and the walk's own -libaom derivation says what "cover" is: one `TX_4X8`. - -### 3.1 After the fix +* `chroma_plane_block_codable(bw, bh, ss_x, ss_y)` — the four + `BLOCK_INVALID` cells of `av1_ss_size_lookup`, nothing else. +* `refuse_invalid_plane_block(...)` — a **returned** error (never an + `assert!`: a partition symbol is stream data, so hostile bytes reach it), + carrying libaom's own wording so the message names the rule: + `"... has no chroma plane block at this frame's subsampling mode (libaom: + \"Block size %dx%d invalid with this subsampling mode\", + av1/decoder/decodeframe.c:1456, refusing by the same rule)"`. +* Installed at every place a partition symbol is turned into a **strip** subsize + with a chroma plane block: + * `partition_w8` → `PARTITION_HORZ` = 8x4, `PARTITION_VERT` = 4x8 + (`subsize_lookup[PARTITION_*][BLOCK_8X8]`); + * `partition_w16` → `PARTITION_HORZ` = 16x8, `PARTITION_VERT` = 8x16. ``` -$ EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 \ - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 >/dev/null -SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 -SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=0 -SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=0 - -$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/w$i \ - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu >/dev/null 2>&1; \ - sha256sum /tmp/wt_aw/w$i.f0; done -3823d219ba99c28c904d3a4f6f695fe56fa6cd5b7f26da5919e525b36478d7df ... (x5, identical) +$ ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 | head -4 +TILING: 1 frame headers parsed +SEQ: use_128x128_superblock=true bit_depth=8 mono_chrome=false max_frame=64x64 +TILING: cols=1 rows=1 uniform_spacing=true context_update_tile_id=0 +REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no +chroma plane block at this frame's subsampling mode (libaom: "Block size %dx%d invalid with this +subsampling mode", av1/decoder/decodeframe.c:1456, refusing by the same rule)) ``` -Five runs, one hash. +Same refusal class as the oracle, same rule, same shape named. ---- +### 3.1 Sites found, and the ones proven not to need it -## 4. The gate +| site | subsizes it can produce | needs the check? | +|---|---|---| +| `partition_w8` (2 sites, 36549 / 36767 region) | 8x4, 4x8 | **yes**, installed | +| `partition_w16` intra (36175 region) | 16x8, 8x16 | **yes**, installed | +| `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 | +| `PARTITION_HORZ_4` / `VERT_4` on 8x16 / 16x8 (`decode_rect_split`) | 4x16, 16x4 | **NOT installed — known gap, stated here** | +| 32/64-level partitions, 128 root, AB partitions | squares and 32x64/64x32 | no: every cell of those rows is non-INVALID at every subsampling this decoder accepts | +| 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 | + +The 1:4 sites are the honest gap: `PARTITION_HORZ_4` on an 8x16 yields a 4x16, +whose 4:2:2 plane block is `BLOCK_INVALID`, and this lane did not install the +check there. `decode_rect4_16_intrabc` is on another lane's charter and was not +touched; the neighbouring non-intrabc `decode_rect4_16_strip` site is where the +next step belongs. No committed fixture reaches it (see §4), and the census +instrument is what would show it if one ever did. -`crates/ec-av1/src/stream.rs`, `a_422_header_over_a_420_tile_leaves_no_sample_unwritten`: +--- -* pins the same fixture through the existing `read_pin` (2014 bytes, - fnv1a64 `0x98a1378df976253d`); -* turns the sentinel on through the new `decode::set_plane_sentinel` (a thread - local, because this crate snapshots the environment once per process and a - gate cannot set a process-constant env var) and turns it off again through a - `Drop` guard; -* decodes it and asserts `decode::take_unwritten_samples() == 0`; -* asserts `decode::take_census_scanned() >= 64*64 + 2*32*64`, so a census that - scanned nothing cannot pass as a census that found nothing - (`vacuous-test-assertions`). +## 4. Regression evidence + +* **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. Measured by the same loop as the §2 hashes, with the per-fixture + stderr scanned for `REFUSED`. +* **Sentinel sweep** (127 fixtures, `EC_AV1_PLANE_SENTINEL=1`): pre-fix exactly + one fixture had a non-empty census (the witness, 112+112); post-fix the corpus + has no unwritten sample anywhere — the witness decodes nothing at all now, and + the other 126 are unchanged. +* **Scoped tests.** `cargo test -p ec-av1 --features gate-counters --lib -- 422 + 440 chroma422` → 15 passed (including six real-4:2:2 byte-exact gates: + `a_real_422_key_frame_and_inter_sequence_decode_pixel_exact`, + `a_real_422_12bit_and_superres_stream_decode_pixel_exact`, + `a_real_422_film_grain_stream_decodes_pixel_exact`, + `the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact`, + `the_pinned_422_lossless_inter_witnesses_decode_pixel_exact`, + `the_pinned_422_bigblock_witnesses_decode_pixel_exact`); + `-- sub8 decode::tests` → 53 passed. The 15-test set also covers the + pre-existing `the_440_cell_is_not_a_codable_chroma_shape`, whose tail arm + lane-av1422lift had amended to "the pin decodes"; that arm is now the refusal + assertion above and the rest of the gate (the 4:4:0-request-lands-on-4:2:2 + claim) is untouched. + `-- sub8 picalloc sentinel` → 13 passed; `-- decode::tests` → 40 passed. -``` -$ cargo test -p ec-av1 --features gate-counters --lib a_422_header_over_a_420_tile_leaves_no_sample_unwritten -test stream::tests::a_422_header_over_a_420_tile_leaves_no_sample_unwritten ... ok -test result: ok. 1 passed; 0 failed; ... -``` +--- + +## 5. The gate -### 4.1 Mutation: the gate bites +`crates/ec-av1/src/stream.rs`, +`a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt`: -`let rect48 = false && leaf_shape == (4, 8) && !lossless(fctx);` — the fix -disabled, nothing else: +1. pins `440_request_is_422.obu` through the existing `read_pin` (2014 bytes, + fnv1a64 `0x98a1378df976253d`); +2. asserts the decode is an **error**, and that the message contains libaom's + own `"invalid with this subsampling mode"` — so a gate cannot pass on any + other refusal; +3. **positive control**: `422_key_64x64.obu`, a genuine 4:2:2 pin, must still + decode to at least one frame — the gate cannot pass by refusing everything. ``` -thread 'stream::tests::a_422_header_over_a_420_tile_leaves_no_sample_unwritten' panicked at - crates/ec-av1/src/stream.rs:2912:9: -assertion `left == right` failed: a_422_header_over_a_420_tile_leaves_no_sample_unwritten: -224 samples of the frame were handed to the tile walk and never written, so they reach the output -as whatever the allocator left there (the five different dump hashes this pin used to give) -test result: FAILED. 0 passed; 1 failed +$ cargo test -p ec-av1 --features gate-counters --lib -- refuses_the_subsize +test stream::tests::a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt ... ok +test result: ok. 1 passed; 0 failed; ... ``` -224 = 112 (U) + 112 (V), the §1.1 census exactly. Reverted, gate green again. - ---- - -## 5. Regression evidence +**Determinism, now a consequence rather than the pinned property.** The witness +no longer produces output at all, so there is no hash to vary. Before the fix, +`for i in 1..5` gave five hashes (top of §2); after, the file refuses. The +nondeterminism was never a property of the pin worth pinning — it was the shape +of a stream we should not have decoded at all. -* **Whole-corpus output equality, pre-fix vs post-fix.** Every fixture decoded - with `EC_AV1_FINAL_DUMP` on both trees, all `.f*` files hashed: the two hash - lists differ **only** for `440_request_is_422.obu`. Every 4:2:0 / 4:4:4 / - 4:2:2 committed stream produces byte-identical output, which is what §2.2's - reach measurement predicts (the `leaf=(4, 8)` shape never fires on them). -* **Whole-corpus sentinel sweep re-run after the fix**: `non-clean fixtures: - 0 / 127`. The witness's 112+112 is gone and the other 126 are unchanged, - which is what §2.2's reach measurement predicts. +**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 +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. --- -## 6. What this lane did NOT do, and why +## 6. What this lane did not do -* No oracle comparison for the fix's pixels. The `TX_4X8` chroma unit is - derived from libaom's source (§2.3) and reuses the crate's already-pinned - port of the identical unit, but **no committed valid stream reaches the - shape**, so there is no byte-exact claim to make and none is made. A 4:2:2 - stream whose 8x8 blocks code `PARTITION_HORZ` is the fixture this fix still - wants; building one needs an encoder that emits that partition, which this - crate's encoder does not. +* The `PARTITION_HORZ_4` / `VERT_4` 1:4 subsize sites (4x16 / 16x4) are not + checked — §3.1 names them and where the next step belongs. No committed + fixture reaches them. +* No pixel claim is made or unmade for the witness: it is not a decodable 4:2:2 + stream and `aomdec` says so. * `film_grain.rs`, the reserved 4:2:0 group-tail chroma SKIP arm and - `decode_rect4_16_intrabc` were not touched. The cause is not in them. -* The census instrument (`census_unwritten`, `set_plane_sentinel`, - `take_unwritten_samples`, `take_census_scanned`) and the - `PlaneBuf::plane` field are additions; the field is what lets the census and - any future write-trace name the plane from the buffer instead of from the - call site. \ No newline at end of file + `decode_rect4_16_intrabc` untouched — the cause is not in them.