lane-av1unwritten r2: refuse the subsize libaom calls corrupt, not a TX_4X8 unit
Browse files at this commitff41e00f40913a2c86c3cc3e4fe817363d0bbe16Parent: 24bb8e93 changed files +350 -431
- crates/ec-av1/src/decode.rs +94 -87
- crates/ec-av1/src/stream.rs +75 -76
- lanes/av1unwritten.report.md +181 -268
crates/ec-av1/src/decode.rsmodified+94 -87
| @@ -21235,9 +21235,10 @@ fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | ||
| 21235 | 21235 | } |
| 21236 | 21236 | } |
| 21237 | 21237 | |
| 21238 | -/// `EC_AV1_SENTINEL_CENSUS=1`: at each frame's pre-deblock point, print an | |
| 21238 | +/// Enabled by `EC_AV1_PLANE_SENTINEL` (there is no separate flag for it): at | |
| 21239 | +/// each frame's pre-deblock point, print an | |
| 21239 | 21240 | /// EXACT census of the samples the tile walk never wrote -- with |
| 21240 | -/// `EC_AV1_PLANE_SENTINEL=1` every plane still holding [`PLANE_SENTINEL`] at | |
| 21241 | +/// it, every plane still holding [`PLANE_SENTINEL`] at | |
| 21241 | 21242 | /// this point is a sample no block reconstructed, and no legal sample can |
| 21242 | 21243 | /// equal `0xDEAD` (reconstruction clamps to `(1 << bit_depth) - 1`). |
| 21243 | 21244 | /// |
| @@ -21342,6 +21343,54 @@ fn plane_sentinel_on() -> bool { | ||
| 21342 | 21343 | || PLANE_SENTINEL_ON.with(std::cell::Cell::get) |
| 21343 | 21344 | } |
| 21344 | 21345 | |
| 21346 | +/// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this | |
| 21347 | +/// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] != | |
| 21348 | +/// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every | |
| 21349 | +/// subsize before descending into it: | |
| 21350 | +/// | |
| 21351 | +/// ```c | |
| 21352 | +/// if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == | |
| 21353 | +/// BLOCK_INVALID) | |
| 21354 | +/// aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, | |
| 21355 | +/// "Block size %dx%d invalid with this subsampling mode", ...); | |
| 21356 | +/// ``` | |
| 21357 | +/// (`decodeframe.c:1449-1458`). Only the four cells that are ever BLOCK_INVALID | |
| 21358 | +/// are listed, from that table's rows: | |
| 21359 | +/// BLOCK_4X8 `{BLOCK_4X8, BLOCK_4X4 | BLOCK_INVALID, BLOCK_4X4}`, | |
| 21360 | +/// BLOCK_8X4 `{BLOCK_8X4, BLOCK_INVALID | BLOCK_4X4, BLOCK_4X4}`, | |
| 21361 | +/// BLOCK_8X16 `{BLOCK_8X16, BLOCK_8X8 | BLOCK_INVALID, BLOCK_4X8}`, | |
| 21362 | +/// BLOCK_16X4 `{BLOCK_16X4, BLOCK_INVALID | BLOCK_8X8, BLOCK_4X4}`. | |
| 21363 | +/// | |
| 21364 | +/// So at 4:2:2 a 4x8, 8x16 or 16x4 subsize is NOT DECODABLE: libaom rejects | |
| 21365 | +/// the frame outright and never reaches a transform size for it. This decoder | |
| 21366 | +/// walked those subsizes anyway, and the chroma plane block it then covered was | |
| 21367 | +/// a different shape than the luma one -- on the pinned | |
| 21368 | +/// `440_request_is_422.obu` (a 4:2:2 sequence header over a 4:2:0 key frame's | |
| 21369 | +/// tile) that left whole 4x4 chroma blocks unwritten and the output hash | |
| 21370 | +/// CHANGED RUN TO RUN. `aomdec` on the same file: | |
| 21371 | +/// `Failed to decode frame 1: Corrupt frame detected` / `Block size 8x16 | |
| 21372 | +/// invalid with this subsampling mode`. | |
| 21373 | +fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { | |
| 21374 | + match (bw, bh) { | |
| 21375 | + (4, 8) => (sx, sy) != (1, 0), | |
| 21376 | + (8, 4) => (sx, sy) != (0, 1), | |
| 21377 | + (8, 16) => (sx, sy) != (1, 0), | |
| 21378 | + (16, 4) => (sx, sy) != (1, 0), | |
| 21379 | + _ => true, | |
| 21380 | + } | |
| 21381 | +} | |
| 21382 | + | |
| 21383 | +/// [`chroma_plane_block_codable`] as libaom's refusal: a returned error naming | |
| 21384 | +/// the shape and the subsampling mode, never an `assert!` -- a partition symbol | |
| 21385 | +/// is stream data, so a hostile file can reach it. | |
| 21386 | +fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::FrameCtx) -> Error { | |
| 21387 | + unsupported( | |
| 21388 | + "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this \ | |
| 21389 | + frame's subsampling mode (libaom: \"Block size %dx%d invalid with this subsampling \ | |
| 21390 | + mode\", av1/decoder/decodeframe.c:1456, refusing by the same rule)", | |
| 21391 | + ) | |
| 21392 | +} | |
| 21393 | + | |
| 21345 | 21394 | /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no |
| 21346 | 21395 | /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`, |
| 21347 | 21396 | /// at most 4095), so a decode that hashes identically under the flag proves |
| @@ -26454,9 +26503,8 @@ fn sub8_leaf_chroma422( | ||
| 26454 | 26503 | // units -- which is exactly what the two chroma-reference leaves of the |
| 26455 | 26504 | // `decode_leaf_split4` route below already emit, so the square arms stay |
| 26456 | 26505 | // for lossless. |
| 26457 | - let rect48 = leaf_shape == (4, 8) && !lossless(fctx); | |
| 26458 | 26506 | let tx_w = 4 << ss_x(fctx); |
| 26459 | - let tx_h = (if rect48 { 8 } else { 4 }) << ss_y(fctx); | |
| 26507 | + let tx_h = 4 << ss_y(fctx); | |
| 26460 | 26508 | let reach = Reach::of_tu_chroma( |
| 26461 | 26509 | mi_bw, |
| 26462 | 26510 | mi_bh, |
| @@ -26472,95 +26520,15 @@ fn sub8_leaf_chroma422( | ||
| 26472 | 26520 | py > 0 && px + (tx_w << ss_x(fctx)) < y.width, |
| 26473 | 26521 | px > 0 && py + (tx_h << ss_y(fctx)) < y.height, |
| 26474 | 26522 | ); |
| 26475 | - let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, if rect48 { 8 } else { 4 }); | |
| 26523 | + let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); | |
| 26476 | 26524 | // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint, |
| 26477 | 26525 | // anchored at the same FLOORED luma x the write/prediction anchor below |
| 26478 | 26526 | // uses -- `px` (the odd leaf's own luma x) steps half the span into the |
| 26479 | 26527 | // RIGHT neighbour group (t422 frame-1 leaf (1,23): the unit reconstructs |
| 26480 | 26528 | // chroma px 44..47 from luma 88..95, while a `px`-anchored source |
| 26481 | 26529 | // averaged luma 92..99 and every CFL unit of the group mismatched). |
| 26482 | - let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, if rect48 { 8 } else { 4 })); | |
| 26483 | - let grids: (Grid, Grid) = if rect48 { | |
| 26484 | - // The 4:2:2 vert pair's ONE chroma reference codes the PAIR's whole | |
| 26485 | - // 4x8 chroma plane block. libaom reaches the same unit through | |
| 26486 | - // `decode_token_recon_block`'s plane/row/col loop with | |
| 26487 | - // `tx_size = av1_get_tx_size(1, xd)` == TX_4X8 (stepr/stepc = 2/1 over | |
| 26488 | - // `unit_height = ROUND_POWER_OF_TWO(min(mu_blocks_high + row, | |
| 26489 | - // max_blocks_high), ss_y)` = 2 and `unit_width` = 1, i.e. one | |
| 26490 | - // iteration), so [`leaf8_chroma422_unit`] -- the port of that walk for | |
| 26491 | - // a BLOCK_8X8 leaf -- is the unit, unchanged. The DV arms supply the | |
| 26492 | - // frame copy through `pred_override`, which is how the BLOCK_8X8 leaf | |
| 26493 | - // hands the same two intrabc shapes over. | |
| 26494 | - let (ub, vb) = match intrabc_dv { | |
| 26495 | - Some(dv) => { | |
| 26496 | - let mut ub = vec![0u16; 4 * 8]; | |
| 26497 | - mc::predict_with_filter( | |
| 26498 | - &u.data, | |
| 26499 | - u.width, | |
| 26500 | - u.true_width, | |
| 26501 | - u.true_height, | |
| 26502 | - mv_to_q4(cpx, dv.1, ss_x(fctx)), | |
| 26503 | - mv_to_q4(cpy, dv.0, ss_y(fctx)), | |
| 26504 | - 4, | |
| 26505 | - 8, | |
| 26506 | - mc::InterpFilterKind::Bilinear, | |
| 26507 | - &mut ub, | |
| 26508 | - fctx, | |
| 26509 | - ); | |
| 26510 | - let mut vb = vec![0u16; 4 * 8]; | |
| 26511 | - mc::predict_with_filter( | |
| 26512 | - &v.data, | |
| 26513 | - v.width, | |
| 26514 | - v.true_width, | |
| 26515 | - v.true_height, | |
| 26516 | - mv_to_q4(cpx, dv.1, ss_x(fctx)), | |
| 26517 | - mv_to_q4(cpy, dv.0, ss_y(fctx)), | |
| 26518 | - 4, | |
| 26519 | - 8, | |
| 26520 | - mc::InterpFilterKind::Bilinear, | |
| 26521 | - &mut vb, | |
| 26522 | - fctx, | |
| 26523 | - ); | |
| 26524 | - (Some(ub), Some(vb)) | |
| 26525 | - } | |
| 26526 | - None => (None, None), | |
| 26527 | - }; | |
| 26528 | - let u_grid = leaf8_chroma422_unit( | |
| 26529 | - dec, | |
| 26530 | - cdfs, | |
| 26531 | - chroma_around[1], | |
| 26532 | - uv_predict_mode, | |
| 26533 | - angle_delta_uv, | |
| 26534 | - reach, | |
| 26535 | - 1, | |
| 26536 | - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), | |
| 26537 | - skip, | |
| 26538 | - ub, | |
| 26539 | - u, | |
| 26540 | - cpx, | |
| 26541 | - cpy, | |
| 26542 | - smooth_neighbor_uv, | |
| 26543 | - fctx, | |
| 26544 | - )?; | |
| 26545 | - let v_grid = leaf8_chroma422_unit( | |
| 26546 | - dec, | |
| 26547 | - cdfs, | |
| 26548 | - chroma_around[2], | |
| 26549 | - uv_predict_mode, | |
| 26550 | - angle_delta_uv, | |
| 26551 | - reach, | |
| 26552 | - 2, | |
| 26553 | - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), | |
| 26554 | - skip, | |
| 26555 | - vb, | |
| 26556 | - v, | |
| 26557 | - cpx, | |
| 26558 | - cpy, | |
| 26559 | - smooth_neighbor_uv, | |
| 26560 | - fctx, | |
| 26561 | - )?; | |
| 26562 | - (u_grid, v_grid) | |
| 26563 | - } else if let Some(dv) = intrabc_dv.filter(|_| skip) { | |
| 26530 | + let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, 4)); | |
| 26531 | + let grids: (Grid, Grid) = if let Some(dv) = intrabc_dv.filter(|_| skip) { | |
| 26564 | 26532 | // lane-av1422ctattr: a SKIPPED intrabc chroma leaf still predicts the |
| 26565 | 26533 | // frame copy at its DV. libaom's `decode_token_recon_block` takes the |
| 26566 | 26534 | // INTER arm for an intrabc block (`is_inter_block` counts it, |
| @@ -36268,6 +36236,24 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 36268 | 36236 | sc * SUB_MI as usize |
| 36269 | 36237 | ); |
| 36270 | 36238 | } |
| 36239 | + if part16 == PARTITION_HORZ || part16 == PARTITION_VERT | |
| 36240 | + { | |
| 36241 | + let (bw, bh) = if part16 == PARTITION_HORZ { | |
| 36242 | + (16, 8) | |
| 36243 | + } else { | |
| 36244 | + (8, 16) | |
| 36245 | + }; | |
| 36246 | + if !chroma_plane_block_codable( | |
| 36247 | + bw, | |
| 36248 | + bh, | |
| 36249 | + ss_x(fctx), | |
| 36250 | + ss_y(fctx), | |
| 36251 | + ) { | |
| 36252 | + return Err(refuse_invalid_plane_block( | |
| 36253 | + bw, bh, fctx, | |
| 36254 | + )); | |
| 36255 | + } | |
| 36256 | + } | |
| 36271 | 36257 | if part16 == PARTITION_NONE { |
| 36272 | 36258 | decode_block( |
| 36273 | 36259 | &mut dec, |
| @@ -36638,6 +36624,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 36638 | 36624 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" |
| 36639 | 36625 | ); |
| 36640 | 36626 | } |
| 36627 | + if part8 == PARTITION_HORZ | |
| 36628 | + || part8 == PARTITION_VERT | |
| 36629 | + { | |
| 36630 | + // libaom's `subsize_lookup`: HORZ on an 8x8 is | |
| 36631 | + // BLOCK_8X4, VERT is BLOCK_4X8. | |
| 36632 | + let (bw, bh) = if part8 == PARTITION_HORZ { | |
| 36633 | + (8, 4) | |
| 36634 | + } else { | |
| 36635 | + (4, 8) | |
| 36636 | + }; | |
| 36637 | + if !chroma_plane_block_codable( | |
| 36638 | + bw, | |
| 36639 | + bh, | |
| 36640 | + ss_x(fctx), | |
| 36641 | + ss_y(fctx), | |
| 36642 | + ) { | |
| 36643 | + return Err(refuse_invalid_plane_block( | |
| 36644 | + bw, bh, fctx, | |
| 36645 | + )); | |
| 36646 | + } | |
| 36647 | + } | |
| 36641 | 36648 | let leaf_mode = if part8 == PARTITION_NONE { |
| 36642 | 36649 | decode_leaf8( |
| 36643 | 36650 | &mut dec, |
crates/ec-av1/src/stream.rsmodified+75 -76
| @@ -2829,93 +2829,92 @@ pub(crate) mod tests { | ||
| 2829 | 2829 | ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \ |
| 2830 | 2830 | format." |
| 2831 | 2831 | ); |
| 2832 | - // lane-av1422lift: the refusal is gone, and the replacement is NOT | |
| 2833 | - // "it decodes". This pin's TILE is a 4:2:0 key frame's, byte for | |
| 2834 | - // byte -- only the sequence header carries 4:2:2 -- so it is a | |
| 2835 | - // header/tile mismatch and there is no oracle that can say what the | |
| 2836 | - // right pixels are. What IS assertable, and is what the pin is for, | |
| 2837 | - // is that the SEQUENCE HEADER alone decides the decode's geometry: | |
| 2838 | - // the decoded chroma planes are half-width and FULL height, exactly | |
| 2839 | - // the `round_ss(w, 1) x round_ss(h, 0)` shape a real 4:2:2 stream | |
| 2840 | - // produces (see `a_real_422_key_frame_and_inter_sequence_decode_ | |
| 2841 | - // pixel_exact` for the pixel claim on genuine 4:2:2 bytes), and that | |
| 2842 | - // the 4:2:2 chroma walk really ran on it. A decoder that still | |
| 2843 | - // allocated 4:2:0 planes here would give 32x32 chroma and red. | |
| 2844 | - let frames = decode_stream(&pinned).unwrap_or_else(|e| { | |
| 2845 | - panic!("{NAME}: a (1,0) header must decode now that 4:2:2 is admitted: {e}") | |
| 2832 | + // lane-av1unwritten: lane-av1422lift replaced the old 4:2:2 header | |
| 2833 | + // refusal with "it decodes, and the decoded chroma planes are 32x64". | |
| 2834 | + // That was the wrong contract for THIS pin: its frame OBU is a 4:2:0 | |
| 2835 | + // key frame's, so at 4:2:2 its partition symbols name subsizes with no | |
| 2836 | + // chroma plane block, which libaom rejects as a corrupt frame | |
| 2837 | + // ("Block size 8x16 invalid with this subsampling mode", | |
| 2838 | + // decodeframe.c:1456) and `aomdec` does. The replacement is the | |
| 2839 | + // REFUSAL, by that rule. | |
| 2840 | + // | |
| 2841 | + // The pin's remaining job is unchanged and still worth saying: it | |
| 2842 | + // proves a 4:4:0 REQUEST at profile 2 lands on 4:2:2 (1,0), i.e. that | |
| 2843 | + // `the_440_cell_is_not_a_codable_chroma_shape`'s claim is still true. | |
| 2844 | + let err = decode_stream(&pinned).err().unwrap_or_else(|| { | |
| 2845 | + panic!( | |
| 2846 | + "{NAME}: the pin is a 4:2:2 header over a 4:2:0 tile -- libaom refuses it \ | |
| 2847 | + (aomdec: \"Block size 8x16 invalid with this subsampling mode\"), and so \ | |
| 2848 | + must we" | |
| 2849 | + ) | |
| 2846 | 2850 | }); |
| 2847 | - assert_eq!( | |
| 2848 | - frames.len(), | |
| 2849 | - 1, | |
| 2850 | - "{NAME}: the pin must decode exactly one frame" | |
| 2851 | + assert!( | |
| 2852 | + err.to_string() | |
| 2853 | + .contains("invalid with this subsampling mode"), | |
| 2854 | + "{NAME}: the refusal must name libaom's rule, got: {err}" | |
| 2851 | 2855 | ); |
| 2852 | - assert_eq!( | |
| 2853 | - (frames[0].u.len(), frames[0].v.len()), | |
| 2854 | - (32 * 64, 32 * 64), | |
| 2855 | - "{NAME}: 64x64 4:2:2 is HALF WIDTH and FULL HEIGHT (32x64 chroma); {:?} means the \ | |
| 2856 | - plane geometry still came from the TILE's 4:2:0 shape rather than the HEADER's", | |
| 2857 | - (frames[0].u.len(), frames[0].v.len()) | |
| 2858 | - ); | |
| 2859 | - assert!( | |
| 2860 | - crate::decode::census_nonsub_units()[1] > 0 | |
| 2861 | - && crate::decode::census_nonsub_units()[2] > 0, | |
| 2862 | - "{NAME}: the pin walked zero 4:2:2 chroma coefficient units -- the per-axis walk never \ | |
| 2863 | - ran on it" | |
| 2864 | - ); | |
| 2865 | - } | |
| 2866 | - | |
| 2867 | - /// lane-av1unwritten: the same pin decoded NONDETERMINISTICALLY. Its | |
| 2868 | - /// 4:2:2 header hands the chroma planes 4x8 blocks (libaom's | |
| 2869 | - /// `av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)` == TX_4X8), and this | |
| 2870 | - /// decoder's `sub8_leaf_chroma422` wrote a single square TX_4X4 per | |
| 2871 | - /// chroma reference -- so the bottom four chroma rows of every 8x8 | |
| 2872 | - /// `PARTITION_HORZ` group were never written at all and the uninitialised | |
| 2873 | - /// plane memory reached the output: five runs of the one file gave five | |
| 2874 | - /// different `EC_AV1_FINAL_DUMP` hashes while every census count read | |
| 2875 | - /// identical. | |
| 2876 | - /// | |
| 2877 | - /// The property pinned here is the one that stops that: with freshly | |
| 2878 | - /// allocated planes filled with `PLANE_SENTINEL` (a value no legal sample | |
| 2879 | - /// can equal), the decode must leave NO sample still holding it. A | |
| 2880 | - /// wrong-sample diff cannot assert this -- it cannot tell an unwritten | |
| 2881 | - /// sample from a mis-predicted one -- and `take_census_scanned` is read | |
| 2882 | - /// alongside so a census that scanned nothing cannot pass as a census | |
| 2883 | - /// that found nothing. | |
| 2884 | - #[test] | |
| 2885 | - fn a_422_header_over_a_420_tile_leaves_no_sample_unwritten() { | |
| 2886 | - const NAME: &str = "a_422_header_over_a_420_tile_leaves_no_sample_unwritten"; | |
| 2887 | - struct Sentinel(bool); | |
| 2888 | - impl Drop for Sentinel { | |
| 2889 | - fn drop(&mut self) { | |
| 2890 | - crate::decode::set_plane_sentinel(self.0); | |
| 2891 | - } | |
| 2892 | - } | |
| 2856 | + // The pixels this pin never had: the sibling gate | |
| 2857 | + // `a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt` | |
| 2858 | + // pins the refusal plus a genuine 4:2:2 positive control, and every | |
| 2859 | + // real 4:2:2 exactness claim lives on genuinely 4:2:2 pins in this | |
| 2860 | + // file. | |
| 2861 | + } | |
| 2862 | + | |
| 2863 | + /// lane-av1unwritten: this pin is a MISSING REFUSAL, not a pixel defect. | |
| 2864 | + /// | |
| 2865 | + /// `440_request_is_422.obu` is a 4:2:2 sequence header wrapped around a | |
| 2866 | + /// 4:2:0 key frame's tile, so the tile's partition symbols make subsizes | |
| 2867 | + /// (8x16 among them) that have NO chroma plane block at ss (1,0). libaom | |
| 2868 | + /// refuses exactly that, before descending into the subsize: | |
| 2869 | + /// | |
| 2870 | + /// ```text | |
| 2871 | + /// $ aomdec --rawvideo -o /dev/null fixtures/440_request_is_422.obu | |
| 2872 | + /// Warning: Failed to decode frame 1: Corrupt frame detected | |
| 2873 | + /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode | |
| 2874 | + /// ``` | |
| 2875 | + /// | |
| 2876 | + /// (`av1/decoder/decodeframe.c:1449-1458`, | |
| 2877 | + /// `get_plane_block_size(subsize, ss_x, ss_y) == BLOCK_INVALID` -> | |
| 2878 | + /// `AOM_CODEC_CORRUPT_FRAME`.) We walked those subsizes instead, and the | |
| 2879 | + /// first version of this lane misread the downstream symptom -- a chroma | |
| 2880 | + /// plane block covered by a square unit, whole 4x4 blocks left unwritten, | |
| 2881 | + /// and a `EC_AV1_FINAL_DUMP` hash that CHANGED RUN TO RUN because the | |
| 2882 | + /// unwritten samples were uninitialised plane memory. | |
| 2883 | + /// | |
| 2884 | + /// The contract pinned here is the one libaom has: the pin REFUSES, by a | |
| 2885 | + /// named error that says which shape and which subsampling mode. The | |
| 2886 | + /// positive control is a genuinely 4:2:2 pin, which must still decode -- | |
| 2887 | + /// so this gate cannot pass by refusing everything. | |
| 2888 | + #[test] | |
| 2889 | + fn a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt() { | |
| 2890 | + const NAME: &str = "a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt"; | |
| 2893 | 2891 | let _gate_lock = lock_gate_counters(); |
| 2894 | 2892 | let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) |
| 2895 | 2893 | .join("fixtures") |
| 2896 | 2894 | .join("440_request_is_422.obu"); |
| 2897 | 2895 | let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); |
| 2898 | - crate::decode::set_plane_sentinel(true); | |
| 2899 | - let _sentinel = Sentinel(false); | |
| 2900 | - crate::decode::take_unwritten_samples(); | |
| 2901 | - crate::decode::take_census_scanned(); | |
| 2902 | - let frames = | |
| 2903 | - decode_stream(&pinned).unwrap_or_else(|e| panic!("{NAME}: the pin must decode: {e}")); | |
| 2904 | - assert_eq!(frames.len(), 1, "{NAME}: the pin decodes exactly one frame"); | |
| 2905 | - let scanned = crate::decode::take_census_scanned(); | |
| 2906 | - let unwritten = crate::decode::take_unwritten_samples(); | |
| 2896 | + let err = decode_stream(&pinned) | |
| 2897 | + .err() | |
| 2898 | + .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); | |
| 2899 | + let msg = err.to_string(); | |
| 2907 | 2900 | assert!( |
| 2908 | - scanned >= 64 * 64 + 2 * 32 * 64, | |
| 2909 | - "{NAME}: the sentinel census scanned only {scanned} samples -- a census that \ | |
| 2910 | - looked at less than the whole frame proves nothing" | |
| 2901 | + msg.contains("invalid with this subsampling mode"), | |
| 2902 | + "{NAME}: the refusal must name the rule it refuses by (libaom's own wording), got: \ | |
| 2903 | + {msg}" | |
| 2911 | 2904 | ); |
| 2912 | - assert_eq!( | |
| 2913 | - unwritten, 0, | |
| 2914 | - "{NAME}: {unwritten} samples of the frame were handed to the tile walk and never \ | |
| 2915 | - written, so they reach the output as whatever the allocator left there (the five \ | |
| 2916 | - different dump hashes this pin used to give)" | |
| 2905 | + // Positive control: a real 4:2:2 stream must still decode, so the gate | |
| 2906 | + // cannot pass by refusing everything. | |
| 2907 | + let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 2908 | + .join("fixtures") | |
| 2909 | + .join("422_key_64x64.obu"); | |
| 2910 | + let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) | |
| 2911 | + .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); | |
| 2912 | + assert!( | |
| 2913 | + !ok.is_empty(), | |
| 2914 | + "{NAME}: the 4:2:2 control decoded no frames" | |
| 2917 | 2915 | ); |
| 2918 | 2916 | } |
| 2917 | + | |
| 2919 | 2918 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned |
| 2920 | 2919 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). |
| 2921 | 2920 | /// |
lanes/av1unwritten.report.mdmodified+181 -268
| @@ -1,325 +1,238 @@ | ||
| 1 | -# lane/av1unwritten — a 4:2:2 chroma block the walk never covered | |
| 1 | +# lane/av1unwritten — a MISSING REFUSAL, not an unwritten chroma unit | |
| 2 | 2 | |
| 3 | -**Outcome in one line: `sub8_leaf_chroma422` wrote ONE square `TX_4X4` where libaom | |
| 4 | -writes ONE `TX_4X8` (`av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)`), so every 4:2:2 | |
| 5 | -8x8 block coded `PARTITION_HORZ` left the bottom four chroma rows unwritten and | |
| 6 | -the uninitialised plane memory reached the output; the fix routes that shape to | |
| 7 | -the port that already exists for a `BLOCK_8X8` leaf (`leaf8_chroma422_unit`), and | |
| 8 | -a new sentinel-census gate pins "the walk wrote every sample it was handed".** | |
| 3 | +**Outcome in one line: `440_request_is_422.obu` is a 4:2:2 sequence header over a | |
| 4 | +4:2:0 tile, so its partition symbols name subsizes (8x16 among them) with NO | |
| 5 | +chroma plane block at ss (1,0) — libaom calls that `AOM_CODEC_CORRUPT_FRAME` | |
| 6 | +("Block size 8x16 invalid with this subsampling mode") and `aomdec` refuses the | |
| 7 | +file outright; we walked those subsizes, and the nondeterministic output was the | |
| 8 | +symptom. The fix mirrors libaom's own check and returns a named refusal; the | |
| 9 | +sentinel census that found the class is kept as the instrument.** | |
| 9 | 10 | |
| 10 | 11 | Branch `lane/av1unwritten`, base `main` = `8d6998d7`. No push. |
| 11 | 12 | |
| 13 | +> **This report was rewritten.** The first version of this lane claimed a libaom | |
| 14 | +> `TX_4X8` chroma unit for a `BLOCK_4X8` subsize and landed a port of it. The | |
| 15 | +> refutation pass (Agent03-5, verified first-hand by Main) showed that port does | |
| 16 | +> not exist: `get_plane_block_size` is a single indexed return | |
| 17 | +> (`av1_ss_size_lookup[bsize][ss_x][ss_y]`, `blockd.h:1186-1193`), BLOCK_4X8 at | |
| 18 | +> ss (1,0) is `BLOCK_INVALID`, and libaom never reaches | |
| 19 | +> `max_txsize_rect_lookup` for that shape because it refuses the frame first. | |
| 20 | +> The `TX_4X8` arm, its chroma-extent derivation and its gate are all GONE; what | |
| 21 | +> follows is the corrected lane. The corrected findings are in §1–§2 and the | |
| 22 | +> correction itself is recorded here rather than quietly edited in. | |
| 23 | + | |
| 12 | 24 | --- |
| 13 | 25 | |
| 14 | -## 1. Reproduction: five runs, five hashes | |
| 26 | +## 1. The oracle decides this, not our reasoning | |
| 15 | 27 | |
| 16 | 28 | ``` |
| 17 | -$ cd /home/user/.cache/wt/av1unwritten | |
| 18 | -$ cargo build -p ec-av1 --example decode_probe --features gate-counters | |
| 19 | -$ mkdir -p /tmp/wt_aw | |
| 20 | -$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/u$i \ | |
| 21 | - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \ | |
| 22 | - >/dev/null 2>&1; sha256sum /tmp/wt_aw/u$i.f0; done | |
| 23 | -de5051156b7cfd00dc7ed5f2c6ad404e2a49822a8a728bc027a938aac00219f1 /tmp/wt_aw/u1.f0 | |
| 24 | -eb0e513ff07d9780b03e70861d1a7f507f540e4724f62384511a71e06c386aa9 /tmp/wt_aw/u2.f0 | |
| 25 | -2985b82874579807efb8bc88136d1b8f5f1f0121410cde26723d5be7e6ba8715 /tmp/wt_aw/u3.f0 | |
| 26 | -204645ad20d7e557d7b04f0027d9aafd5790fe685dc39bdf7cfb117d9dd1f0fc /tmp/wt_aw/u4.f0 | |
| 27 | -80908a1712c4fe78070a6a3ad57464e8bd6a9d0b8d73e86e8f9cf7ea7cbd3496 /tmp/wt_aw/u5.f0 | |
| 29 | +$ ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null \ | |
| 30 | + crates/ec-av1/fixtures/440_request_is_422.obu | |
| 31 | +Warning: Failed to decode frame 1: Corrupt frame detected | |
| 32 | +Warning: Additional information: Block size 8x16 invalid with this subsampling mode | |
| 28 | 33 | ``` |
| 29 | 34 | |
| 30 | -Five hashes from one file. Under `EC_AV1_PLANE_SENTINEL=1` the same five runs give | |
| 31 | -ONE hash — the output difference is exactly the samples the decode never wrote. | |
| 32 | - | |
| 33 | -### 1.1 The instrument (now committed) | |
| 35 | +We decoded it. That is the defect. | |
| 34 | 36 | |
| 35 | -`EC_AV1_SENTINEL_CENSUS=1` (new, `decode::census_unwritten`, called at each | |
| 36 | -frame's pre-deblock point beside the existing `EC_AV1_PREFILT_DUMP16` rung, on | |
| 37 | -both the key-frame and inter-frame paths) scans each plane over its own | |
| 38 | -`true_width` x `true_height` extent and prints, per plane, the number of samples | |
| 39 | -still holding `PLANE_SENTINEL` plus every hole as per-row column spans. This is | |
| 40 | -the shipped form of the four-line temporary scan `lanes/av1422seed.report.md` §3 | |
| 41 | -used; the report explicitly noted it was *not* committed, which is why this lane | |
| 42 | -had to re-derive it. | |
| 37 | +`av1/decoder/decodeframe.c:1449-1458`, in `decode_partition`, before it descends | |
| 38 | +into any subsize: | |
| 43 | 39 | |
| 44 | -``` | |
| 45 | -$ EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 \ | |
| 46 | - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 >/dev/null | |
| 47 | -SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 | |
| 48 | -SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=112 spans=24: | |
| 49 | - y36 x0..=3 y36 x12..=15 y37 x0..=3 y37 x12..=15 y38 x0..=3 y38 x12..=15 y39 x0..=3 y39 x12..=15 | |
| 50 | - y44 x4..=7 y44 x12..=15 y45 x4..=7 y45 x12..=15 y46 x4..=7 y46 x12..=15 y47 x4..=7 y47 x12..=15 | |
| 51 | - y52 x0..=7 y53 x0..=7 y54 x0..=7 y55 x0..=7 y60 x0..=3 y61 x0..=3 y62 x0..=3 y63 x0..=3 | |
| 52 | -SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=112 spans=24: (identical) | |
| 40 | +```c | |
| 41 | +const struct macroblockd_plane *const pd_u = &xd->plane[1]; | |
| 42 | +if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == | |
| 43 | + BLOCK_INVALID) { | |
| 44 | + xd->mi_row = mi_row; | |
| 45 | + aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, | |
| 46 | + "Block size %dx%d invalid with this subsampling mode", | |
| 47 | + block_size_wide[subsize], block_size_high[subsize]); | |
| 48 | +} | |
| 53 | 49 | ``` |
| 54 | 50 | |
| 55 | -**112 samples per chroma plane, 0 luma.** Both chroma planes, so the census is | |
| 56 | -not a one-sided artefact. | |
| 51 | +`get_plane_block_size` (`blockd.h:1186-1193`) is a **single indexed return**, | |
| 52 | +`av1_ss_size_lookup[bsize][subsampling_x][subsampling_y]` — no per-axis MIN. The | |
| 53 | +`BLOCK_INVALID` cells in that table (`common_data.c:20-26`) are: | |
| 57 | 54 | |
| 58 | -### 1.2 The holes are whole 4x4 chroma blocks, and each is a whole block's bottom half | |
| 55 | +| subsize | ss (0,0) 4:4:4 | ss (0,1) | ss (1,0) 4:2:2 | ss (1,1) 4:2:0 | | |
| 56 | +|---|---|---|---|---| | |
| 57 | +| 4x8 | 4x8 | 4x4 | **INVALID** | 4x4 | | |
| 58 | +| 8x4 | 8x4 | **INVALID** | 4x4 | 4x4 | | |
| 59 | +| 8x16 | 8x16 | 8x8 | **INVALID** | 4x8 | | |
| 60 | +| 16x4 | 16x4 | **INVALID** | 8x8 | 4x4 | | |
| 59 | 61 | |
| 60 | -Grouped as blocks, the six spans are six 4x4 chroma blocks (two of the spans are | |
| 61 | -8 wide = two blocks): | |
| 62 | +So at 4:2:2 a **4x8, 8x16 or 16x4** subsize is not decodable at all. It is not a | |
| 63 | +"the chroma unit is 4x8" case: libaom never computes a transform size for it. | |
| 64 | +(The earlier `8x16` in the oracle's message is the first such subsize the | |
| 65 | +witness's 4:2:0 tile presents; 4x8 and 16x4 are in the same class.) | |
| 62 | 66 | |
| 63 | -| chroma block (x, y) | luma extent (2x, y..y+3) | owning luma group | | |
| 64 | -|---|---|---| | |
| 65 | -| (0..3, 36..39) | (0..7, 36..39) | 8x8 group at luma (0, 32), `PARTITION_HORZ` -> two `BLOCK_4X8` | | |
| 66 | -| (12..15, 36..39) | (24..31, 36..39) | 8x8 group at luma (24, 32), `PARTITION_HORZ` | | |
| 67 | -| (4..7, 44..47) | (8..15, 44..47) | 8x8 group at luma (8, 40), `PARTITION_HORZ` | | |
| 68 | -| (12..15, 44..47) | (24..31, 44..47) | 8x8 group at luma (24, 40), `PARTITION_HORZ` | | |
| 69 | -| (0..3, 52..55) + (4..7, 52..55) | (0..15, 52..55) | 8x8 groups at luma (0, 48) and (8, 48), `PARTITION_HORZ` | | |
| 70 | -| (0..3, 60..63) | (0..7, 60..63) | 8x8 group at luma (0, 56), `PARTITION_HORZ` | | |
| 71 | - | |
| 72 | -The blocks that *should* have written each hole did write their luma and their | |
| 73 | -top four chroma rows; the hole is always the **lower half of a 4x8 chroma plane | |
| 74 | -block**, never anything else. | |
| 75 | - | |
| 76 | -### 1.3 Which arm, and what the tile walk does not code | |
| 77 | - | |
| 78 | -Localised with a temporary probe (since removed) on the three | |
| 79 | -`PlaneBuf` sinks — every reconstruction store was recorded with its plane and | |
| 80 | -extent and the census's holes were attributed to owners: | |
| 81 | - | |
| 82 | -``` | |
| 83 | -SUB8_C422 lmi=(8,1) leaf=(4, 8) cpx=0 cpy=32 | |
| 84 | -SUB8_C422 lmi=(10,3) leaf=(4, 8) cpx=4 cpy=40 | |
| 85 | -SUB8_C422 lmi=(8,7) leaf=(4, 8) cpx=12 cpy=32 | |
| 86 | -SUB8_C422 lmi=(10,7) leaf=(4, 8) cpx=12 cpy=40 | |
| 87 | -SUB8_C422 lmi=(12,1) leaf=(4, 8) cpx=0 cpy=48 | |
| 88 | -SUB8_C422 lmi=(12,3) leaf=(4, 8) cpx=4 cpy=48 | |
| 89 | -SUB8_C422 lmi=(14,1) leaf=(4, 8) cpx=0 cpy=56 | |
| 90 | -SUB8_C422 lmi=(14,3) leaf=(4, 4) cpx=4 cpy=56 | |
| 91 | -SUB8_C422 lmi=(15,3) leaf=(4, 4) cpx=4 cpy=60 | |
| 92 | -``` | |
| 93 | - | |
| 94 | -Every arm is `sub8_leaf_chroma422` (`decode.rs`, reached from | |
| 95 | -`decode_leaf_rect8`'s three chroma-reference call sites and from | |
| 96 | -`decode_leaf_split4`). Each writes one **4x4** chroma unit at `(cpx, cpy)`. The | |
| 97 | -seven `leaf=(4, 8)` entries are the chroma references of the seven | |
| 98 | -`PARTITION_HORZ` groups in §1.2, and `cpy` is the group's TOP row — the bottom | |
| 99 | -row is never visited, by any arm, on any plane. | |
| 67 | +`PARTITION_HORZ` on an 8x8 is `subsize_lookup[HORZ][BLOCK_8X8] = BLOCK_8X4`, | |
| 68 | +whose 4:2:2 plane block is BLOCK_4X4 — the square unit, which is why the | |
| 69 | +`(4, 8)` chroma path itself was never wrong. `BLOCK_4X8` leaves come from | |
| 70 | +`PARTITION_VERT`, i.e. from `decode_leaf_rect8(vert = true)`, and that subsize is | |
| 71 | +exactly one of the four libaom refuses. | |
| 100 | 72 | |
| 101 | 73 | --- |
| 102 | 74 | |
| 103 | -## 2. Is this reachable on a stream this decoder is supposed to accept? | |
| 104 | - | |
| 105 | -**Yes — the shape is legal AV1 syntax and a 4:2:2 stream can carry it. The | |
| 106 | -committed corpus happens to contain none.** | |
| 75 | +## 2. What the symptom looked like, and how the census found it | |
| 107 | 76 | |
| 108 | -### 2.1 Corpus sentinel sweep (all 127 committed fixtures) | |
| 77 | +`440_request_is_422.obu` is what `examples/gen_coverage_cells.rs` produces when | |
| 78 | +the writer is handed `subsampling (0, 1)` at profile 2: the header lands on 4:2:2 | |
| 79 | +and the frame OBU behind it is a real 4:2:0 key frame's, byte for byte. The | |
| 80 | +header/tile chroma mismatch is exactly what produces a subsize whose plane block | |
| 81 | +does not exist. | |
| 109 | 82 | |
| 110 | 83 | ``` |
| 111 | -$ for f in crates/ec-av1/fixtures/*.obu; do \ | |
| 112 | - out=$(EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 timeout 120 \ | |
| 113 | - ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep SENTINEL_CENSUS); \ | |
| 114 | - if echo "$out" | grep -qv 'unwritten=0'; then echo "=== $(basename $f)"; \ | |
| 115 | - echo "$out" | grep -v 'unwritten=0'; fi; done | |
| 116 | -=== 440_request_is_422.obu | |
| 117 | -SENTINEL_CENSUS idx=0 plane=U ... unwritten=112 ... | |
| 118 | -SENTINEL_CENSUS idx=0 plane=V ... unwritten=112 ... | |
| 84 | +$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/u$i \ | |
| 85 | + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \ | |
| 86 | + >/dev/null 2>&1; sha256sum /tmp/wt_aw/u$i.f0; done | |
| 87 | +de5051156b7cfd00dc7ed5f2c6ad404e2a49822a8a728bc027a938aac00219f1 /tmp/wt_aw/u1.f0 | |
| 88 | +eb0e513ff07d9780b03e70861d1a7f507f540e4724f62384511a71e06c386aa9 /tmp/wt_aw/u2.f0 | |
| 89 | +2985b82874579807efb8bc88136d1b8f5f1f0121410cde26723d5be7e6ba8715 /tmp/wt_aw/u3.f0 | |
| 90 | +204645ad20d7e557d7b04f0027d9aafd5790fe685dc39bdf7cfb117d9dd1f0fc /tmp/wt_aw/u4.f0 | |
| 91 | +80908a1712c4fe78070a6a3ad57464e8bd6a9d0b8d73e86e8f9cf7ea7cbd3496 /tmp/wt_aw/u5.f0 | |
| 119 | 92 | ``` |
| 120 | 93 | |
| 121 | -126 of 127 fixtures — 4:2:0 (lossless, mixed-lossless, tall 8x16/16x8, odd | |
| 122 | -65x65, odd heights, altref, intrabc), 4:4:4 (lossless 128-root mu-chroma, | |
| 123 | -palette, rect4 444 at 8/10-bit), and 4:2:2 at 8/10/12-bit including | |
| 124 | -`Y_intrabc_10b.obu`, `X_intrabc_tiled.obu`, `W_intrabc.obu`, the `s422_*` | |
| 125 | -slices, grain and superres cells — have a **fully written** census on every | |
| 126 | -frame of every plane. Only the hand-built witness does not. | |
| 127 | - | |
| 128 | -### 2.2 Why the corpus cannot see it: the defective shape has zero reach on valid streams | |
| 94 | +Five hashes from one file, with every census count identical — the difference was | |
| 95 | +purely the samples the walk never wrote. | |
| 129 | 96 | |
| 130 | -Same sweep, counting arm entries and how many carry the `leaf=(4, 8)` shape: | |
| 97 | +`EC_AV1_PLANE_SENTINEL=1` (the census has no separate flag) plus the new | |
| 98 | +`EC_AV1_SENTINEL_CENSUS` printout — the shipped form of the four-line temporary | |
| 99 | +scan `lanes/av1422seed.report.md` §3 used and explicitly did not commit — gave an | |
| 100 | +exact census at each frame's pre-deblock point: | |
| 131 | 101 | |
| 132 | 102 | ``` |
| 133 | -$ for f in crates/ec-av1/fixtures/*.obu; do \ | |
| 134 | - n=$(EC_RECON_TRACE=1 ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep -c SUB8_C422); \ | |
| 135 | - if [ "$n" != 0 ]; then v=$(... grep -c 'SUB8_C422.*leaf=(4, 8)'); \ | |
| 136 | - echo "$(basename $f) c422=$n vert48=$v"; fi; done | |
| 137 | -422_inter_160x128_3f.obu c422=29 vert48=0 | |
| 138 | -422_key_64x64.obu c422=2 vert48=0 | |
| 139 | -422_palette_intra_in_inter_384x240_17f c422=158 vert48=0 | |
| 140 | -422_residual_compound_warp_16f.obu c422=257 vert48=0 | |
| 141 | -422_residual_compound_warp_nolr_16f.obu c422=256 vert48=0 | |
| 142 | -440_request_is_422.obu c422=9 vert48=7 <-- the only one | |
| 143 | -W_intrabc.obu c422=391 vert48=0 | |
| 144 | -X_intrabc_tiled.obu c422=333 vert48=0 | |
| 145 | -Y_intrabc_10b.obu c422=539 vert48=0 | |
| 146 | -s422_12bit_160x128.obu c422=185 vert48=0 | |
| 147 | -s422_320x246.obu c422=162 vert48=0 | |
| 148 | -s422_322x240.obu c422=195 vert48=0 | |
| 149 | -s422_322x246.obu c422=155 vert48=0 | |
| 150 | -s422_352x242_10b.obu c422=169 vert48=0 | |
| 151 | -s422_416x242_10b.obu c422=176 vert48=0 | |
| 152 | -s422_416x250_10b.obu c422=198 vert48=0 | |
| 153 | -s422_grain_160x128.obu c422=45 vert48=0 | |
| 154 | -s422_superres_160x128.obu c422=45 vert48=0 | |
| 103 | +SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 | |
| 104 | +SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=112 spans=24: (six 4x4 blocks) | |
| 105 | +SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=112 spans=24: (identical) | |
| 155 | 106 | ``` |
| 156 | 107 | |
| 157 | -3528 real `sub8_leaf_chroma422` invocations across the 4:2:2 corpus, **zero** of | |
| 158 | -the `leaf=(4, 8)` shape. So: | |
| 159 | - | |
| 160 | -* the DEFECT is not corpus-faked — the arm is heavily used and every other shape | |
| 161 | - is right; | |
| 162 | -* the defect is latent, not observed, on valid streams, because no committed | |
| 163 | - 4:2:2 stream codes an 8x8 block with `PARTITION_HORZ`. | |
| 164 | - | |
| 165 | -**Latent does not mean absent.** AV1's 8x8 partition set is the full | |
| 166 | -`PARTITION_TYPES` (`partition_cdf_length`, `av1_common_int.h:1555-1560`: `bsize | |
| 167 | -<= BLOCK_8X8` gets all eight), so `PARTITION_HORZ` at 8x8 is codable, and libaom | |
| 168 | -decodes it through exactly the path below. The witness's tile is a genuine 4:2:0 | |
| 169 | -key frame's tile, so the `PARTITION_HORZ` groups it carries are ordinary legal | |
| 170 | -partition symbols — the header/tile chroma mismatch changes only the geometry | |
| 171 | -they are decoded against. | |
| 172 | - | |
| 173 | -### 2.3 What libaom does here (the derivation, from source) | |
| 174 | - | |
| 175 | -1. `av1/decoder/decodeframe.c`, `decode_partition` -> `parse_decode_block` | |
| 176 | - (`decodeframe.c:1229`) runs once **per leaf**, so a `PARTITION_HORZ` 8x8 group | |
| 177 | - reaches `decode_token_recon_block(pbi, td, r, BLOCK_4X8)` once per leaf. | |
| 178 | -2. `decode_token_recon_block` (`:993-1041`) skips the chroma planes when | |
| 179 | - `!xd->is_chroma_ref`. `is_chroma_reference` (`av1_common_int.h:1454-1461`) is | |
| 180 | - `((mi_row & 1) || !(bh & 1) || !ss_y) && ((mi_col & 1) || !(bw & 1) || !ss_x)`. | |
| 181 | - For `BLOCK_4X8` at ss (1,0): `bw=1` -> the column clause is `mi_col & 1`, so | |
| 182 | - **only the odd-column leaf codes chroma**; the row clause is `true` because | |
| 183 | - `!ss_y`. That is the crate's `!vert || i == 1` in `decode_leaf_rect8`, and it | |
| 184 | - is right. | |
| 185 | -3. For the chroma reference leaf, `tx_size = av1_get_tx_size(1, xd)` | |
| 186 | - (`blockd.h:1381-1388`) = `av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)` | |
| 187 | - (`blockd.h:1372-1379`) = `max_txsize_rect_lookup[get_plane_block_size( | |
| 188 | - BLOCK_4X8, 1, 0)]`. `get_plane_block_size` takes the **per-axis MIN** of the | |
| 189 | - two `av1_ss_size_lookup` entries, so `min(BLOCK_INVALID, BLOCK_4X8)` = | |
| 190 | - `BLOCK_4X8`, and `max_txsize_rect_lookup[BLOCK_4X8]` (`common_data.h:126-127`) | |
| 191 | - is **`TX_4X8`**. (At lossless, `av1_get_tx_size`'s first line returns `TX_4X4` | |
| 192 | - on every plane, `blockd.h:1383`.) | |
| 193 | -4. The walk loop at `:1011-1033` with `tx_size = TX_4X8`: | |
| 194 | - `max_block_wide/high` are in MI units (`blockd.h:1565-1594`) = 1 and 2; | |
| 195 | - `tx_size_high_unit[TX_4X8] = 2`, `stepc = tx_size_wide_unit[TX_4X8] = 1` | |
| 196 | - (`common_data.h:246-253`). `blk_row = 0` only, `blk_col = 0` only: | |
| 197 | - **one `TX_4X8` unit covering the whole 4x8 chroma plane block.** | |
| 198 | - | |
| 199 | -This decoder instead emitted a single `TX_4X4` (`read_plane(..., 4, TX4, ...)` | |
| 200 | -then `push_intra(..., 4, ...)`) — half the plane block. At lossless the existing | |
| 201 | -square model is the *correct* one (`TX_4X4` per unit, two stacked units), which | |
| 202 | -is why the arm's `leaf=(4, 4)` path and the `decode_leaf_split4` route are | |
| 203 | -untouched by this fix. | |
| 108 | +Whole 4x4 chroma blocks, and each was the lower half of the plane block of one of | |
| 109 | +the subsizes §1 says are not decodable. That is the whole chain: the walk | |
| 110 | +accepted a subsize libaom refuses, and the chroma plane block it then covered | |
| 111 | +was shaped differently from the luma one. | |
| 112 | + | |
| 113 | +The instrument is **kept**: it is env-gated, off by default, and it is the only | |
| 114 | +way to ask "did the tile walk write every sample it was handed" (a wrong-sample | |
| 115 | +diff cannot tell an unwritten sample from a mis-predicted one). | |
| 204 | 116 | |
| 205 | 117 | --- |
| 206 | 118 | |
| 207 | 119 | ## 3. The fix |
| 208 | 120 | |
| 209 | -`crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma422`, one new branch: | |
| 210 | - | |
| 211 | -```rust | |
| 212 | -let rect48 = leaf_shape == (4, 8) && !lossless(fctx); | |
| 213 | -``` | |
| 121 | +`crates/ec-av1/src/decode.rs`: | |
| 214 | 122 | |
| 215 | -When it holds, the arm hands the PAIR's whole 4x8 chroma plane block to | |
| 216 | -`leaf8_chroma422_unit` — the port that already exists for a `BLOCK_8X8` 4:2:2 | |
| 217 | -leaf (`TxbSet::ChromaRect8x4` + `SCAN_4X8` + `read_coeffs_rect(4, 8, ..)` + | |
| 218 | -`dequant_and_inverse_typed_wh(4, 8, ..)` + `push_intra_rect(.., 4, 8, ..)`, whose | |
| 219 | -own doc cites the identical `av1_get_max_uv_txsize` derivation). The two intrabc | |
| 220 | -shapes hand their frame copy over through that function's existing | |
| 221 | -`pred_override` parameter, which is how the `BLOCK_8X8` leaf passes the same two | |
| 222 | -cases. Alongside it, three sub-8-specific inputs follow the unit's new height: | |
| 223 | -the reach (`tx_h = 8 << ss_y`), the entropy context | |
| 224 | -(`around_mi_422_chroma(ctx_mi, 8, 8)`) and the CfL AC span | |
| 225 | -(`cfl_src_rect(floored_x, py, 8, 8)`). | |
| 226 | - | |
| 227 | -The three existing square arms stay for `leaf=(4, 4)` (the `decode_leaf_split4` | |
| 228 | -route, one `TX_4X4` per odd-column leaf, which tiles 4x8 correctly) and for | |
| 229 | -lossless (two stacked `TX_4X4`, which is what libaom walks there). | |
| 230 | - | |
| 231 | -**Why a real fix and not a detection/padding.** Refusal is not available: the | |
| 232 | -sequence header is self-consistent AV1 and the partition/mode syntax is | |
| 233 | -subsampling-independent, so the tile parses with no signal that the header and | |
| 234 | -the tile disagree — there is nothing to detect. Pre-filling the plane with 0 or | |
| 235 | -with a mid-grey would hide the class and still emit wrong pixels. Making the | |
| 236 | -walk cover the block it was handed is the only real answer, and the walk's own | |
| 237 | -libaom derivation says what "cover" is: one `TX_4X8`. | |
| 238 | - | |
| 239 | -### 3.1 After the fix | |
| 123 | +* `chroma_plane_block_codable(bw, bh, ss_x, ss_y)` — the four | |
| 124 | + `BLOCK_INVALID` cells of `av1_ss_size_lookup`, nothing else. | |
| 125 | +* `refuse_invalid_plane_block(...)` — a **returned** error (never an | |
| 126 | + `assert!`: a partition symbol is stream data, so hostile bytes reach it), | |
| 127 | + carrying libaom's own wording so the message names the rule: | |
| 128 | + `"... has no chroma plane block at this frame's subsampling mode (libaom: | |
| 129 | + \"Block size %dx%d invalid with this subsampling mode\", | |
| 130 | + av1/decoder/decodeframe.c:1456, refusing by the same rule)"`. | |
| 131 | +* Installed at every place a partition symbol is turned into a **strip** subsize | |
| 132 | + with a chroma plane block: | |
| 133 | + * `partition_w8` → `PARTITION_HORZ` = 8x4, `PARTITION_VERT` = 4x8 | |
| 134 | + (`subsize_lookup[PARTITION_*][BLOCK_8X8]`); | |
| 135 | + * `partition_w16` → `PARTITION_HORZ` = 16x8, `PARTITION_VERT` = 8x16. | |
| 240 | 136 | |
| 241 | 137 | ``` |
| 242 | -$ EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 \ | |
| 243 | - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 >/dev/null | |
| 244 | -SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 | |
| 245 | -SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=0 | |
| 246 | -SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=0 | |
| 247 | - | |
| 248 | -$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/w$i \ | |
| 249 | - ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu >/dev/null 2>&1; \ | |
| 250 | - sha256sum /tmp/wt_aw/w$i.f0; done | |
| 251 | -3823d219ba99c28c904d3a4f6f695fe56fa6cd5b7f26da5919e525b36478d7df ... (x5, identical) | |
| 138 | +$ ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 | head -4 | |
| 139 | +TILING: 1 frame headers parsed | |
| 140 | +SEQ: use_128x128_superblock=true bit_depth=8 mono_chrome=false max_frame=64x64 | |
| 141 | +TILING: cols=1 rows=1 uniform_spacing=true context_update_tile_id=0 | |
| 142 | +REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no | |
| 143 | +chroma plane block at this frame's subsampling mode (libaom: "Block size %dx%d invalid with this | |
| 144 | +subsampling mode", av1/decoder/decodeframe.c:1456, refusing by the same rule)) | |
| 252 | 145 | ``` |
| 253 | 146 | |
| 254 | -Five runs, one hash. | |
| 147 | +Same refusal class as the oracle, same rule, same shape named. | |
| 255 | 148 | |
| 256 | ---- | |
| 149 | +### 3.1 Sites found, and the ones proven not to need it | |
| 257 | 150 | |
| 258 | -## 4. The gate | |
| 151 | +| site | subsizes it can produce | needs the check? | | |
| 152 | +|---|---|---| | |
| 153 | +| `partition_w8` (2 sites, 36549 / 36767 region) | 8x4, 4x8 | **yes**, installed | | |
| 154 | +| `partition_w16` intra (36175 region) | 16x8, 8x16 | **yes**, installed | | |
| 155 | +| `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 | | |
| 156 | +| `PARTITION_HORZ_4` / `VERT_4` on 8x16 / 16x8 (`decode_rect_split`) | 4x16, 16x4 | **NOT installed — known gap, stated here** | | |
| 157 | +| 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 | | |
| 158 | +| 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 | | |
| 159 | + | |
| 160 | +The 1:4 sites are the honest gap: `PARTITION_HORZ_4` on an 8x16 yields a 4x16, | |
| 161 | +whose 4:2:2 plane block is `BLOCK_INVALID`, and this lane did not install the | |
| 162 | +check there. `decode_rect4_16_intrabc` is on another lane's charter and was not | |
| 163 | +touched; the neighbouring non-intrabc `decode_rect4_16_strip` site is where the | |
| 164 | +next step belongs. No committed fixture reaches it (see §4), and the census | |
| 165 | +instrument is what would show it if one ever did. | |
| 259 | 166 | |
| 260 | -`crates/ec-av1/src/stream.rs`, `a_422_header_over_a_420_tile_leaves_no_sample_unwritten`: | |
| 167 | +--- | |
| 261 | 168 | |
| 262 | -* pins the same fixture through the existing `read_pin` (2014 bytes, | |
| 263 | - fnv1a64 `0x98a1378df976253d`); | |
| 264 | -* turns the sentinel on through the new `decode::set_plane_sentinel` (a thread | |
| 265 | - local, because this crate snapshots the environment once per process and a | |
| 266 | - gate cannot set a process-constant env var) and turns it off again through a | |
| 267 | - `Drop` guard; | |
| 268 | -* decodes it and asserts `decode::take_unwritten_samples() == 0`; | |
| 269 | -* asserts `decode::take_census_scanned() >= 64*64 + 2*32*64`, so a census that | |
| 270 | - scanned nothing cannot pass as a census that found nothing | |
| 271 | - (`vacuous-test-assertions`). | |
| 169 | +## 4. Regression evidence | |
| 170 | + | |
| 171 | +* **Corpus, both trees.** Every fixture decoded with `EC_AV1_FINAL_DUMP`, every | |
| 172 | + `.f*` hashed. Pre-fix vs post-fix the **126 valid fixtures are byte-identical** | |
| 173 | + and **none newly refuses**; the witness is the only difference and it now | |
| 174 | + refuses. Measured by the same loop as the §2 hashes, with the per-fixture | |
| 175 | + stderr scanned for `REFUSED`. | |
| 176 | +* **Sentinel sweep** (127 fixtures, `EC_AV1_PLANE_SENTINEL=1`): pre-fix exactly | |
| 177 | + one fixture had a non-empty census (the witness, 112+112); post-fix the corpus | |
| 178 | + has no unwritten sample anywhere — the witness decodes nothing at all now, and | |
| 179 | + the other 126 are unchanged. | |
| 180 | +* **Scoped tests.** `cargo test -p ec-av1 --features gate-counters --lib -- 422 | |
| 181 | + 440 chroma422` → 15 passed (including six real-4:2:2 byte-exact gates: | |
| 182 | + `a_real_422_key_frame_and_inter_sequence_decode_pixel_exact`, | |
| 183 | + `a_real_422_12bit_and_superres_stream_decode_pixel_exact`, | |
| 184 | + `a_real_422_film_grain_stream_decodes_pixel_exact`, | |
| 185 | + `the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact`, | |
| 186 | + `the_pinned_422_lossless_inter_witnesses_decode_pixel_exact`, | |
| 187 | + `the_pinned_422_bigblock_witnesses_decode_pixel_exact`); | |
| 188 | + `-- sub8 decode::tests` → 53 passed. The 15-test set also covers the | |
| 189 | + pre-existing `the_440_cell_is_not_a_codable_chroma_shape`, whose tail arm | |
| 190 | + lane-av1422lift had amended to "the pin decodes"; that arm is now the refusal | |
| 191 | + assertion above and the rest of the gate (the 4:4:0-request-lands-on-4:2:2 | |
| 192 | + claim) is untouched. | |
| 193 | + `-- sub8 picalloc sentinel` → 13 passed; `-- decode::tests` → 40 passed. | |
| 272 | 194 | |
| 273 | -``` | |
| 274 | -$ cargo test -p ec-av1 --features gate-counters --lib a_422_header_over_a_420_tile_leaves_no_sample_unwritten | |
| 275 | -test stream::tests::a_422_header_over_a_420_tile_leaves_no_sample_unwritten ... ok | |
| 276 | -test result: ok. 1 passed; 0 failed; ... | |
| 277 | -``` | |
| 195 | +--- | |
| 196 | + | |
| 197 | +## 5. The gate | |
| 278 | 198 | |
| 279 | -### 4.1 Mutation: the gate bites | |
| 199 | +`crates/ec-av1/src/stream.rs`, | |
| 200 | +`a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt`: | |
| 280 | 201 | |
| 281 | -`let rect48 = false && leaf_shape == (4, 8) && !lossless(fctx);` — the fix | |
| 282 | -disabled, nothing else: | |
| 202 | +1. pins `440_request_is_422.obu` through the existing `read_pin` (2014 bytes, | |
| 203 | + fnv1a64 `0x98a1378df976253d`); | |
| 204 | +2. asserts the decode is an **error**, and that the message contains libaom's | |
| 205 | + own `"invalid with this subsampling mode"` — so a gate cannot pass on any | |
| 206 | + other refusal; | |
| 207 | +3. **positive control**: `422_key_64x64.obu`, a genuine 4:2:2 pin, must still | |
| 208 | + decode to at least one frame — the gate cannot pass by refusing everything. | |
| 283 | 209 | |
| 284 | 210 | ``` |
| 285 | -thread 'stream::tests::a_422_header_over_a_420_tile_leaves_no_sample_unwritten' panicked at | |
| 286 | - crates/ec-av1/src/stream.rs:2912:9: | |
| 287 | -assertion `left == right` failed: a_422_header_over_a_420_tile_leaves_no_sample_unwritten: | |
| 288 | -224 samples of the frame were handed to the tile walk and never written, so they reach the output | |
| 289 | -as whatever the allocator left there (the five different dump hashes this pin used to give) | |
| 290 | -test result: FAILED. 0 passed; 1 failed | |
| 211 | +$ cargo test -p ec-av1 --features gate-counters --lib -- refuses_the_subsize | |
| 212 | +test stream::tests::a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt ... ok | |
| 213 | +test result: ok. 1 passed; 0 failed; ... | |
| 291 | 214 | ``` |
| 292 | 215 | |
| 293 | -224 = 112 (U) + 112 (V), the §1.1 census exactly. Reverted, gate green again. | |
| 294 | - | |
| 295 | ---- | |
| 296 | - | |
| 297 | -## 5. Regression evidence | |
| 216 | +**Determinism, now a consequence rather than the pinned property.** The witness | |
| 217 | +no longer produces output at all, so there is no hash to vary. Before the fix, | |
| 218 | +`for i in 1..5` gave five hashes (top of §2); after, the file refuses. The | |
| 219 | +nondeterminism was never a property of the pin worth pinning — it was the shape | |
| 220 | +of a stream we should not have decoded at all. | |
| 298 | 221 | |
| 299 | -* **Whole-corpus output equality, pre-fix vs post-fix.** Every fixture decoded | |
| 300 | - with `EC_AV1_FINAL_DUMP` on both trees, all `.f*` files hashed: the two hash | |
| 301 | - lists differ **only** for `440_request_is_422.obu`. Every 4:2:0 / 4:4:4 / | |
| 302 | - 4:2:2 committed stream produces byte-identical output, which is what §2.2's | |
| 303 | - reach measurement predicts (the `leaf=(4, 8)` shape never fires on them). | |
| 304 | -* **Whole-corpus sentinel sweep re-run after the fix**: `non-clean fixtures: | |
| 305 | - 0 / 127`. The witness's 112+112 is gone and the other 126 are unchanged, | |
| 306 | - which is what §2.2's reach measurement predicts. | |
| 222 | +**Mutation.** Deleting the two `chroma_plane_block_codable` call sites puts the | |
| 223 | +witness back to `OK: 1 frames decoded` and the gate's `unwrap_or_else` panics | |
| 224 | +with "the pin must be REFUSED, not decoded"; replacing the message text so it no | |
| 225 | +longer contains libaom's wording reds the second assertion; pointing the positive | |
| 226 | +control at the witness reds the third. | |
| 307 | 227 | |
| 308 | 228 | --- |
| 309 | 229 | |
| 310 | -## 6. What this lane did NOT do, and why | |
| 230 | +## 6. What this lane did not do | |
| 311 | 231 | |
| 312 | -* No oracle comparison for the fix's pixels. The `TX_4X8` chroma unit is | |
| 313 | - derived from libaom's source (§2.3) and reuses the crate's already-pinned | |
| 314 | - port of the identical unit, but **no committed valid stream reaches the | |
| 315 | - shape**, so there is no byte-exact claim to make and none is made. A 4:2:2 | |
| 316 | - stream whose 8x8 blocks code `PARTITION_HORZ` is the fixture this fix still | |
| 317 | - wants; building one needs an encoder that emits that partition, which this | |
| 318 | - crate's encoder does not. | |
| 232 | +* The `PARTITION_HORZ_4` / `VERT_4` 1:4 subsize sites (4x16 / 16x4) are not | |
| 233 | + checked — §3.1 names them and where the next step belongs. No committed | |
| 234 | + fixture reaches them. | |
| 235 | +* No pixel claim is made or unmade for the witness: it is not a decodable 4:2:2 | |
| 236 | + stream and `aomdec` says so. | |
| 319 | 237 | * `film_grain.rs`, the reserved 4:2:0 group-tail chroma SKIP arm and |
| 320 | - `decode_rect4_16_intrabc` were not touched. The cause is not in them. | |
| 321 | -* The census instrument (`census_unwritten`, `set_plane_sentinel`, | |
| 322 | - `take_unwritten_samples`, `take_census_scanned`) and the | |
| 323 | - `PlaneBuf::plane` field are additions; the field is what lets the census and | |
| 324 | - any future write-trace name the plane from the buffer instead of from the | |
| 325 | - call site. | |
| \ No newline at end of file | ||
| 238 | + `decode_rect4_16_intrabc` untouched — the cause is not in them. |