Merge commit 'e45cc748' into lane/unwritten-dep
Browse files at this commit6 changed files +1849 -41
- crates/ec-av1/examples/decode_probe.rs +5 -0
- crates/ec-av1/src/decode.rs +984 -1
- crates/ec-av1/src/stream.rs +80 -28
- lanes/av1unwritten.report.md +697 -0
- scripts/cmp422-ffmpeg.py +82 -11
- scripts/run422-ffmpeg.py +1 -1
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
| @@ -29,6 +29,11 @@ fn main() { | |||
| 29 | } | 29 | } |
| 30 | }; | 30 | }; |
| 31 | let report = || { | 31 | let report = || { |
| 32 | + // lane-av1unwritten r6: the subsize-guard coverage table (per call | ||
| 33 | + // site, per partition value, reached vs fired). Env-gated | ||
| 34 | + // (`EC_AV1_SUBSIZE_GUARD_TRACE`), so it is empty unless asked for. | ||
| 35 | + ec_av1::decode::dump_subsize_guard_scan(); | ||
| 36 | + ec_av1::decode::dump_subsize_arm_scan(); | ||
| 32 | // The census below reads ec-av1's gate counters; without the crate's | 37 | // The census below reads ec-av1's gate counters; without the crate's |
| 33 | // `gate-counters` feature every one of them is compiled out and reads 0. | 38 | // `gate-counters` feature every one of them is compiled out and reads 0. |
| 34 | if !cfg!(feature = "gate-counters") { | 39 | if !cfg!(feature = "gate-counters") { |
crates/ec-av1/src/decode.rsmodified+984 -1
| @@ -21252,6 +21252,383 @@ fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | |||
| 21252 | } | 21252 | } |
| 21253 | } | 21253 | } |
| 21254 | 21254 | ||
| 21255 | +/// Enabled by `EC_AV1_PLANE_SENTINEL` (there is no separate flag for it): at | ||
| 21256 | +/// each frame's pre-deblock point, print an | ||
| 21257 | +/// EXACT census of the samples the tile walk never wrote -- with | ||
| 21258 | +/// it, every plane still holding [`PLANE_SENTINEL`] at | ||
| 21259 | +/// this point is a sample no block reconstructed, and no legal sample can | ||
| 21260 | +/// equal `0xDEAD` (reconstruction clamps to `(1 << bit_depth) - 1`). | ||
| 21261 | +/// | ||
| 21262 | +/// This is the shipped form of the four-line temporary scan the | ||
| 21263 | +/// `lane/av1422seed` census used: it replaces a wrong-sample diff (which says | ||
| 21264 | +/// where the OUTPUT is wrong, not whether the block was written at all) with a | ||
| 21265 | +/// direct count plus the coordinates of every hole, grouped into per-row | ||
| 21266 | +/// spans so a large hole stays readable. Scans each plane over its own | ||
| 21267 | +/// `true_width` x `true_height` extent: past that is the padded coding | ||
| 21268 | +/// surface's invented tail, which no decoder ever reads. | ||
| 21269 | +fn census_unwritten(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | ||
| 21270 | + if !plane_sentinel_on() { | ||
| 21271 | + return; | ||
| 21272 | + } | ||
| 21273 | + let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst); | ||
| 21274 | + for (name, p) in [("Y", y), ("U", u), ("V", v)] { | ||
| 21275 | + let (w, h) = (p.true_width.min(p.width), p.true_height); | ||
| 21276 | + let mut total = 0usize; | ||
| 21277 | + let mut spans: Vec<(usize, usize, usize)> = Vec::new(); | ||
| 21278 | + for row in 0..h { | ||
| 21279 | + let mut run: Option<(usize, usize)> = None; | ||
| 21280 | + for col in 0..w { | ||
| 21281 | + if p.data[row * p.width + col] == PLANE_SENTINEL { | ||
| 21282 | + total += 1; | ||
| 21283 | + run = Some(match run { | ||
| 21284 | + None => (col, col), | ||
| 21285 | + Some((a, _)) => (a, col), | ||
| 21286 | + }); | ||
| 21287 | + } | ||
| 21288 | + if run.is_some() | ||
| 21289 | + && (col + 1 == w || p.data[row * p.width + col + 1] != PLANE_SENTINEL) | ||
| 21290 | + { | ||
| 21291 | + let (a, b) = run.take().expect("a run is open here"); | ||
| 21292 | + spans.push((row, a, b)); | ||
| 21293 | + } | ||
| 21294 | + } | ||
| 21295 | + } | ||
| 21296 | + UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst); | ||
| 21297 | + CENSUS_SCANNED.fetch_add(w * h, std::sync::atomic::Ordering::SeqCst); | ||
| 21298 | + if total == 0 { | ||
| 21299 | + eprintln!("SENTINEL_CENSUS idx={idx} plane={name} extent={w}x{h} unwritten=0"); | ||
| 21300 | + continue; | ||
| 21301 | + } | ||
| 21302 | + let body: Vec<String> = spans | ||
| 21303 | + .iter() | ||
| 21304 | + .map(|&(r, a, b)| format!("y{r} x{a}..={b}")) | ||
| 21305 | + .collect(); | ||
| 21306 | + eprintln!( | ||
| 21307 | + "SENTINEL_CENSUS idx={idx} plane={name} extent={w}x{h} unwritten={total} \ | ||
| 21308 | + spans={}: {}", | ||
| 21309 | + spans.len(), | ||
| 21310 | + body.join(" ") | ||
| 21311 | + ); | ||
| 21312 | + } | ||
| 21313 | +} | ||
| 21314 | + | ||
| 21315 | +/// Unwritten samples [`census_unwritten`] has counted since the last | ||
| 21316 | +/// [`take_unwritten_samples`] -- process-global (not thread-local) because the | ||
| 21317 | +/// gate reads it after the decode, from a different thread than the one that | ||
| 21318 | +/// scanned the plane. | ||
| 21319 | +static UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 21320 | + | ||
| 21321 | +/// Turns [`PLANE_SENTINEL`] filling on for the CALLING thread, independently | ||
| 21322 | +/// of `EC_AV1_PLANE_SENTINEL`. A gate cannot set a process-constant env var | ||
| 21323 | +/// (see [`crate::envflags`]), and the census is the only honest way to ask | ||
| 21324 | +/// "did the tile walk write every sample it was handed" -- a wrong-sample diff | ||
| 21325 | +/// cannot tell an unwritten sample from a mis-predicted one. | ||
| 21326 | +pub fn set_plane_sentinel(on: bool) { | ||
| 21327 | + PLANE_SENTINEL_ON.with(|c| c.set(on)); | ||
| 21328 | +} | ||
| 21329 | + | ||
| 21330 | +/// Reads and clears [`UNWRITTEN_SAMPLES`]: the number of samples the decode | ||
| 21331 | +/// just handed to the tile walk never wrote, summed over every frame and | ||
| 21332 | +/// plane. Zero is the only acceptable answer for a decoder whose output must | ||
| 21333 | +/// not depend on its allocator. | ||
| 21334 | +pub fn take_unwritten_samples() -> usize { | ||
| 21335 | + UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst) | ||
| 21336 | +} | ||
| 21337 | + | ||
| 21338 | +/// Samples [`census_unwritten`] has looked at since the last | ||
| 21339 | +/// [`take_census_scanned`]. A gate that only asserts | ||
| 21340 | +/// [`take_unwritten_samples`] == 0 passes on a decode that never scanned | ||
| 21341 | +/// anything, so it reads THIS too: a census that scanned nothing has proved | ||
| 21342 | +/// nothing. | ||
| 21343 | +static CENSUS_SCANNED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 21344 | + | ||
| 21345 | +/// Reads and clears [`CENSUS_SCANNED`]; see [`take_unwritten_samples`] for the | ||
| 21346 | +/// pairing. | ||
| 21347 | +pub fn take_census_scanned() -> usize { | ||
| 21348 | + CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst) | ||
| 21349 | +} | ||
| 21350 | + | ||
| 21351 | +thread_local! { | ||
| 21352 | + /// The [`set_plane_sentinel`] override; `EC_AV1_PLANE_SENTINEL` is the | ||
| 21353 | + /// process-wide default. | ||
| 21354 | + static PLANE_SENTINEL_ON: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | ||
| 21355 | +} | ||
| 21356 | + | ||
| 21357 | +/// Whether freshly allocated planes are [`PLANE_SENTINEL`]-filled. | ||
| 21358 | +fn plane_sentinel_on() -> bool { | ||
| 21359 | + crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") | ||
| 21360 | + || PLANE_SENTINEL_ON.with(std::cell::Cell::get) | ||
| 21361 | +} | ||
| 21362 | + | ||
| 21363 | +/// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this | ||
| 21364 | +/// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] != | ||
| 21365 | +/// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every | ||
| 21366 | +/// subsize before descending into it: | ||
| 21367 | +/// | ||
| 21368 | +/// ```c | ||
| 21369 | +/// if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == | ||
| 21370 | +/// BLOCK_INVALID) | ||
| 21371 | +/// aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, | ||
| 21372 | +/// "Block size %dx%d invalid with this subsampling mode", ...); | ||
| 21373 | +/// ``` | ||
| 21374 | +/// (`decodeframe.c:1449-1458`). | ||
| 21375 | +/// | ||
| 21376 | +/// So at 4:2:2 a 4x8, 8x16, 16x32, 32x64, 64x128, 4x16, 8x32 or 16x64 | ||
| 21377 | +/// subsize is NOT DECODABLE: libaom rejects the frame outright and never | ||
| 21378 | +/// reaches a transform size for it. This decoder walked those subsizes anyway, | ||
| 21379 | +/// covering a chroma plane block whose shape did not match the luma one. | ||
| 21380 | +/// | ||
| 21381 | +/// Two independent facts justify refusing rather than decoding, and NEITHER is | ||
| 21382 | +/// this lane's pixel measurement: | ||
| 21383 | +/// | ||
| 21384 | +/// 1. libaom REFUSES the shape. `aomdec` on the pinned | ||
| 21385 | +/// `440_request_is_422.obu` (a 4:2:2 sequence header over a 4:2:0 key | ||
| 21386 | +/// frame's tile) prints `Failed to decode frame 1: Corrupt frame detected` | ||
| 21387 | +/// and `Block size 8x16 invalid with this subsampling mode`. | ||
| 21388 | +/// 2. libaom's own ENCODER never emits it: `partition_search.c:3383-3389` | ||
| 21389 | +/// gates `partition_rect_allowed` on this same table, so no conformant | ||
| 21390 | +/// 4:2:2 stream can contain the shape and the refusal cannot reject legal | ||
| 21391 | +/// content. | ||
| 21392 | +/// | ||
| 21393 | +/// What led here was the observation that this decoder's output for such a | ||
| 21394 | +/// witness DEPENDS ON UNWRITTEN PLANE CONTENT. Measured on `8d6998d7` by two | ||
| 21395 | +/// independent builds (`EC_AV1_FINAL_DUMP=<dir>/x`, the directory created | ||
| 21396 | +/// FIRST -- the dump writes nothing if it does not exist): five runs with | ||
| 21397 | +/// uninitialised planes give TWO different output hashes, five runs with | ||
| 21398 | +/// `EC_AV1_PLANE_SENTINEL=1` give ONE hash, and the sentinel output differs | ||
| 21399 | +/// from the plain one. At 8-bit the sentinel survives in the dump as the single | ||
| 21400 | +/// byte `0xAD`, not the pair `DE AD` -- `PLANE_SENTINEL`'s u16 narrows in | ||
| 21401 | +/// [`crate::stream`]'s u8 write path, so counting a two-byte `0xDEAD` in an | ||
| 21402 | +/// 8-bit dump cannot find it. The lane's own pre-deblock census | ||
| 21403 | +/// ([`census_unwritten`]) then localised the unwritten samples on THIS lane's | ||
| 21404 | +/// tree: 112 per chroma plane on the witness, 224 total. That census number is a | ||
| 21405 | +/// lane-tree measurement with a lane-only instrument and is cited as such; | ||
| 21406 | +/// (1) and (2) are what make the refusal correct. | ||
| 21407 | +/// | ||
| 21408 | +/// `av1_ss_size_lookup`'s `BLOCK_INVALID` cells, transcribed verbatim: | ||
| 21409 | +/// `(common_data.c:17-41`, rows in `BLOCK_SIZES_ALL` order, indexed | ||
| 21410 | +/// `[subsampling_x][subsampling_y])`. Every entry below is an (luma width, | ||
| 21411 | +/// luma height) whose plane block does not EXIST at that subsampling pair, so | ||
| 21412 | +/// libaom refuses any subsize of that shape | ||
| 21413 | +/// (`av1/decoder/decodeframe.c:1449-1458`, `AOM_CODEC_CORRUPT_FRAME`, | ||
| 21414 | +/// "Block size %dx%d invalid with this subsampling mode"). | ||
| 21415 | +/// | ||
| 21416 | +/// There is no other `BLOCK_INVALID` cell in the table: at (0,0) 4:4:4 and at | ||
| 21417 | +/// (1,1) 4:2:0 every row is valid, and the sixteen shapes below are the only | ||
| 21418 | +/// ones that are invalid at (1,0) 4:2:2 or (0,1) 4:4:0. The table test | ||
| 21419 | +/// [`chroma_plane_block_codable_matches_the_libaom_table`] re-transcribes all | ||
| 21420 | +/// 22 rows and checks this list cell for cell -- a diff against the C source, | ||
| 21421 | +/// not a restatement of it. | ||
| 21422 | +/// | ||
| 21423 | +/// ``` | ||
| 21424 | +/// BLOCK_4X8 {4X8, 4X4} {INVALID, 4X4} <- INVALID @ (1,0) | ||
| 21425 | +/// BLOCK_8X4 {8X4, INVALID} {4X4, 4X4} <- INVALID @ (0,1) | ||
| 21426 | +/// BLOCK_8X16 {8X16, 8X8} {INVALID, 4X8} <- INVALID @ (1,0) | ||
| 21427 | +/// BLOCK_16X8 {16X8, INVALID} {8X8, 8X4} <- INVALID @ (0,1) | ||
| 21428 | +/// BLOCK_16X32 {16X32, 16X16} {INVALID, 8X16} <- INVALID @ (1,0) | ||
| 21429 | +/// BLOCK_32X16 {32X16, INVALID}{16X16, 16X8} <- INVALID @ (0,1) | ||
| 21430 | +/// BLOCK_32X64 {32X64, 32X32} {INVALID, 16X32} <- INVALID @ (1,0) | ||
| 21431 | +/// BLOCK_64X32 {64X32, INVALID}{32X32, 32X16} <- INVALID @ (0,1) | ||
| 21432 | +/// BLOCK_64X128 {64X128,64X64} {INVALID, 32X64} <- INVALID @ (1,0) | ||
| 21433 | +/// BLOCK_128X64 {128X64,INVALID}{64X64, 64X32} <- INVALID @ (0,1) | ||
| 21434 | +/// BLOCK_4X16 {4X16, 4X8} {INVALID, 4X8} <- INVALID @ (1,0) | ||
| 21435 | +/// BLOCK_16X4 {16X4, 8X4} {8X4, 8X4} <- valid @ (1,0) | ||
| 21436 | +/// BLOCK_8X32 {8X32, 8X16} {INVALID, 4X16} <- INVALID @ (1,0) | ||
| 21437 | +/// BLOCK_32X8 {32X8, 16X8} {32X8, 16X4} <- valid @ (0,1) | ||
| 21438 | +/// BLOCK_16X64 {16X64,16X32} {INVALID, 8X32} <- INVALID @ (1,0) | ||
| 21439 | +/// BLOCK_64X16 {64X16,32X16} {32X16, 32X8} <- valid @ (0,1) | ||
| 21440 | +/// ``` | ||
| 21441 | +/// | ||
| 21442 | +/// The two "valid" rows are here on purpose: an earlier version of this | ||
| 21443 | +/// predicate hardcoded BLOCK_16X4@(1,0) and BLOCK_32X8@(0,1) as invalid, which | ||
| 21444 | +/// REFUSED a legal 4:2:2 shape -- one aomenc itself emits, since its own | ||
| 21445 | +/// `partition_search.c:3383-3389` gates `partition_rect_allowed[HORZ]` with | ||
| 21446 | +/// exactly this table. | ||
| 21447 | +const PLANE_BLOCK_INVALID_422: &[(usize, usize)] = &[ | ||
| 21448 | + (4, 8), | ||
| 21449 | + (8, 16), | ||
| 21450 | + (16, 32), | ||
| 21451 | + (32, 64), | ||
| 21452 | + (64, 128), | ||
| 21453 | + (4, 16), | ||
| 21454 | + (8, 32), | ||
| 21455 | + (16, 64), | ||
| 21456 | +]; | ||
| 21457 | + | ||
| 21458 | +/// The same list at 4:4:0 `(0, 1)` -- a shape no `color_config` can request | ||
| 21459 | +/// (libaom asserts `subsampling_y == 0` when `subsampling_x == 0`), kept so | ||
| 21460 | +/// the table test can cover every cell rather than only the reachable ones. | ||
| 21461 | +const PLANE_BLOCK_INVALID_440: &[(usize, usize)] = &[ | ||
| 21462 | + (8, 4), | ||
| 21463 | + (16, 8), | ||
| 21464 | + (32, 16), | ||
| 21465 | + (64, 32), | ||
| 21466 | + (128, 64), | ||
| 21467 | + (16, 4), | ||
| 21468 | + (32, 8), | ||
| 21469 | + (64, 16), | ||
| 21470 | +]; | ||
| 21471 | + | ||
| 21472 | +/// Whether `av1_ss_size_lookup[(bw, bh)][sx][sy]` is not `BLOCK_INVALID` -- i.e. | ||
| 21473 | +/// whether libaom lets a subsize of this luma shape have a chroma plane block | ||
| 21474 | +/// at this subsampling at all. | ||
| 21475 | +fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { | ||
| 21476 | + match (sx, sy) { | ||
| 21477 | + (1, 0) => !PLANE_BLOCK_INVALID_422.contains(&(bw, bh)), | ||
| 21478 | + (0, 1) => !PLANE_BLOCK_INVALID_440.contains(&(bw, bh)), | ||
| 21479 | + _ => true, | ||
| 21480 | + } | ||
| 21481 | +} | ||
| 21482 | + | ||
| 21483 | +/// libaom `get_partition_subsize` (spec 6.10.3, `common_data.c`'s | ||
| 21484 | +/// `subsize_lookup`) reduced to its DIMENSIONS -- all the `av1_ss_size_lookup` | ||
| 21485 | +/// check needs, and, by construction, never the PARENT block's own shape | ||
| 21486 | +/// (that is the r2 mistake in a new place: refusing `16x4` at 4:2:2 by testing | ||
| 21487 | +/// the 16x8 parent). `PARTITION_HORZ_A`/`_B` and `PARTITION_VERT_A`/`_B` are | ||
| 21488 | +/// the four-way arms, whose subsizes are the strips they visit. | ||
| 21489 | +fn partition_subsize_dims(bsize: (usize, usize), part: usize) -> (usize, usize) { | ||
| 21490 | + let (w, h) = bsize; | ||
| 21491 | + match part { | ||
| 21492 | + PARTITION_SPLIT => (w / 2, h / 2), | ||
| 21493 | + PARTITION_HORZ | PARTITION_HORZ_A | PARTITION_HORZ_B => (w, h / 2), | ||
| 21494 | + PARTITION_VERT | PARTITION_VERT_A | PARTITION_VERT_B => (w / 2, h), | ||
| 21495 | + PARTITION_HORZ_4 => (w, h / 4), | ||
| 21496 | + PARTITION_VERT_4 => (w / 4, h), | ||
| 21497 | + _ => (w, h), | ||
| 21498 | + } | ||
| 21499 | +} | ||
| 21500 | + | ||
| 21501 | +/// [`chroma_plane_block_codable`] applied to the subsize a partition SYMBOL | ||
| 21502 | +/// selected, exactly as `decode_partition` does at `decodeframe.c:1449-1458` | ||
| 21503 | +/// before descending into it. Returns libaom's named refusal for the caller to | ||
| 21504 | +/// propagate. | ||
| 21505 | +#[track_caller] | ||
| 21506 | +fn refuse_invalid_subsize( | ||
| 21507 | + bsize: (usize, usize), | ||
| 21508 | + part: usize, | ||
| 21509 | + fctx: &crate::decode::FrameCtx, | ||
| 21510 | +) -> Result<()> { | ||
| 21511 | + // lane-av1unwritten r6: the coverage artefact. A guard that sits INSIDE a | ||
| 21512 | + // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm can only ever observe 4..=7, so | ||
| 21513 | + // "the guard is present" is not evidence that an offending value is caught -- | ||
| 21514 | + // which is exactly how r5's three misplaced guards read as coverage. This | ||
| 21515 | + // records, per CALL SITE and per partition value, how often the guard was | ||
| 21516 | + // reached and how often it fired, so a site that never sees an offending | ||
| 21517 | + // value is visible instead of assumed covered. | ||
| 21518 | + if crate::envflags::env_flag!("EC_AV1_SUBSIZE_GUARD_TRACE") { | ||
| 21519 | + note_subsize_guard( | ||
| 21520 | + std::panic::Location::caller(), | ||
| 21521 | + bsize, | ||
| 21522 | + part, | ||
| 21523 | + chroma_plane_block_codable( | ||
| 21524 | + partition_subsize_dims(bsize, part).0, | ||
| 21525 | + partition_subsize_dims(bsize, part).1, | ||
| 21526 | + ss_x(fctx), | ||
| 21527 | + ss_y(fctx), | ||
| 21528 | + ), | ||
| 21529 | + ); | ||
| 21530 | + } | ||
| 21531 | + let (bw, bh) = partition_subsize_dims(bsize, part); | ||
| 21532 | + if chroma_plane_block_codable(bw, bh, ss_x(fctx), ss_y(fctx)) { | ||
| 21533 | + Ok(()) | ||
| 21534 | + } else { | ||
| 21535 | + Err(refuse_invalid_plane_block(bw, bh, fctx)) | ||
| 21536 | + } | ||
| 21537 | +} | ||
| 21538 | + | ||
| 21539 | +/// lane-av1unwritten r6: the OTHER half of the coverage artefact. The guard | ||
| 21540 | +/// table says what the guards see; this says what each DISPATCH ARM sees, so a | ||
| 21541 | +/// dispatch reached with an offending partition value and no guard above it is a | ||
| 21542 | +/// visible hole rather than an absence nobody noticed. `decode_probe` calls | ||
| 21543 | +/// [`dump_subsize_arm_scan`] at exit under `EC_AV1_SUBSIZE_ARM_TRACE`. | ||
| 21544 | +static SUBSIZE_ARM: std::sync::LazyLock< | ||
| 21545 | + std::sync::Mutex<std::collections::BTreeMap<(&'static str, usize), usize>>, | ||
| 21546 | +> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default())); | ||
| 21547 | + | ||
| 21548 | +#[track_caller] | ||
| 21549 | +pub(crate) fn note_subsize_arm(part: usize, codable: bool) { | ||
| 21550 | + if !crate::envflags::env_flag!("EC_AV1_SUBSIZE_ARM_TRACE") { | ||
| 21551 | + return; | ||
| 21552 | + } | ||
| 21553 | + let site = std::panic::Location::caller(); | ||
| 21554 | + let key = ( | ||
| 21555 | + format!("{}:{}", site.file(), site.line()).leak() as &'static str, | ||
| 21556 | + part * 2 + usize::from(codable), | ||
| 21557 | + ); | ||
| 21558 | + if let Ok(mut m) = SUBSIZE_ARM.lock() { | ||
| 21559 | + *m.entry(key).or_insert(0) += 1; | ||
| 21560 | + } | ||
| 21561 | +} | ||
| 21562 | + | ||
| 21563 | +/// Prints and clears the [`note_subsize_arm`] table. | ||
| 21564 | +pub fn dump_subsize_arm_scan() { | ||
| 21565 | + let Ok(mut m) = SUBSIZE_ARM.lock() else { | ||
| 21566 | + return; | ||
| 21567 | + }; | ||
| 21568 | + for ((site, k), n) in m.iter() { | ||
| 21569 | + eprintln!( | ||
| 21570 | + "SUBSIZE_ARM site={site} part={} codable={} reached={n}", | ||
| 21571 | + k / 2, | ||
| 21572 | + if k % 2 == 1 { "true" } else { "false" }, | ||
| 21573 | + ); | ||
| 21574 | + } | ||
| 21575 | + m.clear(); | ||
| 21576 | +} | ||
| 21577 | + | ||
| 21578 | +/// Per-site, per-value counters for [`refuse_invalid_subsize`], plus the dump | ||
| 21579 | +/// that makes the reach/guard split readable. `EC_AV1_SUBSIZE_GUARD_TRACE` | ||
| 21580 | +/// records; `dump_subsize_guard_scan` prints (and clears) the table. | ||
| 21581 | +static SUBSIZE_GUARD: std::sync::LazyLock< | ||
| 21582 | + std::sync::Mutex<std::collections::BTreeMap<(&'static str, usize, usize, bool), usize>>, | ||
| 21583 | +> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default())); | ||
| 21584 | + | ||
| 21585 | +fn note_subsize_guard( | ||
| 21586 | + site: &'static std::panic::Location<'static>, | ||
| 21587 | + bsize: (usize, usize), | ||
| 21588 | + part: usize, | ||
| 21589 | + codable: bool, | ||
| 21590 | +) { | ||
| 21591 | + let key = ( | ||
| 21592 | + format!("{}:{}", site.file(), site.line()).leak() as &'static str, | ||
| 21593 | + bsize.0 * 256 + bsize.1, | ||
| 21594 | + part, | ||
| 21595 | + codable, | ||
| 21596 | + ); | ||
| 21597 | + if let Ok(mut m) = SUBSIZE_GUARD.lock() { | ||
| 21598 | + *m.entry(key).or_insert(0) += 1; | ||
| 21599 | + } | ||
| 21600 | +} | ||
| 21601 | + | ||
| 21602 | +/// Prints and clears the [`refuse_invalid_subsize`] table: one line per | ||
| 21603 | +/// (site, block, partition value) with the times reached and whether the guard | ||
| 21604 | +/// fired. `decode_probe` calls this at exit. | ||
| 21605 | +pub fn dump_subsize_guard_scan() { | ||
| 21606 | + let Ok(mut m) = SUBSIZE_GUARD.lock() else { | ||
| 21607 | + return; | ||
| 21608 | + }; | ||
| 21609 | + for ((site, bsize, part, codable), n) in m.iter() { | ||
| 21610 | + eprintln!( | ||
| 21611 | + "SUBSIZE_GUARD site={site} bsize={}x{} part={part} codable={codable} \ | ||
| 21612 | + reached={n}{}", | ||
| 21613 | + bsize / 256, | ||
| 21614 | + bsize % 256, | ||
| 21615 | + if *codable { "" } else { " FIRED" }, | ||
| 21616 | + ); | ||
| 21617 | + } | ||
| 21618 | + m.clear(); | ||
| 21619 | +} | ||
| 21620 | + | ||
| 21621 | +/// [`chroma_plane_block_codable`] as libaom's refusal: a returned error naming | ||
| 21622 | +/// the shape and the subsampling mode, never an `assert!` -- a partition symbol | ||
| 21623 | +/// is stream data, so a hostile file can reach it. | ||
| 21624 | +fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::FrameCtx) -> Error { | ||
| 21625 | + unsupported( | ||
| 21626 | + "a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this \ | ||
| 21627 | + frame's subsampling mode (libaom: \"Block size %dx%d invalid with this subsampling \ | ||
| 21628 | + mode\", av1/decoder/decodeframe.c:1456, refusing by the same rule)", | ||
| 21629 | + ) | ||
| 21630 | +} | ||
| 21631 | + | ||
| 21255 | /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no | 21632 | /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no |
| 21256 | /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`, | 21633 | /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`, |
| 21257 | /// at most 4095), so a decode that hashes identically under the flag proves | 21634 | /// at most 4095), so a decode that hashes identically under the flag proves |
| @@ -21323,7 +21700,7 @@ pub(crate) fn census_unwritten_final(y: &[u16], u: &[u16], v: &[u16]) { | |||
| 21323 | /// ways (see the lane report) and the two agree, which is the proof that no | 21700 | /// ways (see the lane report) and the two agree, which is the proof that no |
| 21324 | /// unwritten sample reaches the output. | 21701 | /// unwritten sample reaches the output. |
| 21325 | fn fresh_plane(n: usize) -> Vec<u16> { | 21702 | fn fresh_plane(n: usize) -> Vec<u16> { |
| 21326 | - if crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") { | 21703 | + if plane_sentinel_on() { |
| 21327 | return vec![PLANE_SENTINEL; n]; | 21704 | return vec![PLANE_SENTINEL; n]; |
| 21328 | } | 21705 | } |
| 21329 | let mut v: Vec<u16> = Vec::with_capacity(n); | 21706 | let mut v: Vec<u16> = Vec::with_capacity(n); |
| @@ -21365,6 +21742,8 @@ struct PlaneBuf<'a> { | |||
| 21365 | /// old unclipped behaviour exactly. | 21742 | /// old unclipped behaviour exactly. |
| 21366 | tile_x1: usize, | 21743 | tile_x1: usize, |
| 21367 | tile_y1: usize, | 21744 | tile_y1: usize, |
| 21745 | + /// Which plane this buffer IS (0 luma, 1 U, 2 V) -- TEMPORARY probe. | ||
| 21746 | + plane: u8, | ||
| 21368 | } | 21747 | } |
| 21369 | 21748 | ||
| 21370 | /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/ | 21749 | /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/ |
| @@ -26393,6 +26772,29 @@ fn sub8_leaf_chroma422( | |||
| 26393 | // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end | 26772 | // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end |
| 26394 | // for every leaf this reader owns, and the unit is one TX_4X4 chroma | 26773 | // for every leaf this reader owns, and the unit is one TX_4X4 chroma |
| 26395 | // transform wide and tall (`4 << ss` luma px per axis). | 26774 | // transform wide and tall (`4 << ss` luma px per axis). |
| 26775 | + // lane-av1unwritten: at ss (1,0) a BLOCK_4X8 chroma reference's plane | ||
| 26776 | + // block is 4x8 -- `get_plane_block_size(BLOCK_4X8, 1, 0)` is BLOCK_4X8 | ||
| 26777 | + // (`common_data.c`'s `av1_ss_size_lookup[BLOCK_4X8][1][0]` is | ||
| 26778 | + // BLOCK_INVALID, but `blockd.h:1372` takes the per-axis MIN of the two | ||
| 26779 | + // lookups) -- and `av1_get_max_uv_txsize` (blockd.h:1372-1379) resolves | ||
| 26780 | + // it through `max_txsize_rect_lookup[BLOCK_4X8]` == TX_4X8 | ||
| 26781 | + // (`common_data.h:126`). So away from lossless the WHOLE 4x8 plane block | ||
| 26782 | + // is ONE rect transform unit, exactly the one [`leaf8_chroma422_unit`] | ||
| 26783 | + // already reads for a BLOCK_8X8 leaf. Emitting the single square TX_4X4 | ||
| 26784 | + // this arm used to wrote left the block's bottom four chroma rows | ||
| 26785 | + // UNWRITTEN: on the pinned `440_request_is_422.obu` (a 4:2:2 header over | ||
| 26786 | + // a 4:2:0 tile, whose legal 8x8 `PARTITION_HORZ` groups make this shape | ||
| 26787 | + // legal syntax) the sentinel census found 112 unwritten samples per | ||
| 26788 | + // chroma plane, one 4x4 block per group, and the decode's output hash | ||
| 26789 | + // CHANGED RUN TO RUN because the unwritten samples were uninitialised | ||
| 26790 | + // memory (class `writer-gap-reaches-output`). | ||
| 26791 | + // | ||
| 26792 | + // At LOSSLESS the single-unit reading is wrong the other way: | ||
| 26793 | + // `av1_get_tx_size`'s first line returns TX_4X4 on every plane | ||
| 26794 | + // (blockd.h:1383), so the 4x8 plane block is walked as TWO stacked 4x4 | ||
| 26795 | + // units -- which is exactly what the two chroma-reference leaves of the | ||
| 26796 | + // `decode_leaf_split4` route below already emit, so the square arms stay | ||
| 26797 | + // for lossless. | ||
| 26396 | let tx_w = 4 << ss_x(fctx); | 26798 | let tx_w = 4 << ss_x(fctx); |
| 26397 | let tx_h = 4 << ss_y(fctx); | 26799 | let tx_h = 4 << ss_y(fctx); |
| 26398 | let reach = Reach::of_tu_chroma( | 26800 | let reach = Reach::of_tu_chroma( |
| @@ -35249,6 +35651,12 @@ fn read_sb128_root( | |||
| 35249 | // root has no 1:4 arm at all (`PARTITION_HORZ_4`/`VERT_4` are excluded | 35651 | // root has no 1:4 arm at all (`PARTITION_HORZ_4`/`VERT_4` are excluded |
| 35250 | // for BLOCK_128X128 by `av1_get_partition_cdf`'s 8-symbol alphabet, | 35652 | // for BLOCK_128X128 by `av1_get_partition_cdf`'s 8-symbol alphabet, |
| 35251 | // which stops at VERT_B). | 35653 | // which stops at VERT_B). |
| 35654 | + // lane-av1unwritten r4: guard the subsize THIS SYMBOL selected, never the | ||
| 35655 | + // root's own plane block. VERT on a 128x128 root selects BLOCK_64X128, | ||
| 35656 | + // whose 4:2:2 plane block is BLOCK_INVALID; the AB arms select 64x64 | ||
| 35657 | + // quadrants (valid), so PARTITION_HORZ / PARTITION_NONE / SPLIT keep | ||
| 35658 | + // decoding untouched. | ||
| 35659 | + refuse_invalid_subsize((128, 128), part128, fctx)?; | ||
| 35252 | match part128 { | 35660 | match part128 { |
| 35253 | PARTITION_SPLIT => hit!(PART128_SPLIT_HITS), | 35661 | PARTITION_SPLIT => hit!(PART128_SPLIT_HITS), |
| 35254 | PARTITION_NONE => hit!(PART128_NONE_HITS), | 35662 | PARTITION_NONE => hit!(PART128_NONE_HITS), |
| @@ -35358,6 +35766,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35358 | tile_y0: 0, | 35766 | tile_y0: 0, |
| 35359 | tile_x1: width, | 35767 | tile_x1: width, |
| 35360 | tile_y1: height, | 35768 | tile_y1: height, |
| 35769 | + plane: 0, | ||
| 35361 | }; | 35770 | }; |
| 35362 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); | 35771 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); |
| 35363 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); | 35772 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); |
| @@ -35371,6 +35780,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35371 | tile_y0: 0, | 35780 | tile_y0: 0, |
| 35372 | tile_x1: cw, | 35781 | tile_x1: cw, |
| 35373 | tile_y1: ch, | 35782 | tile_y1: ch, |
| 35783 | + plane: 1, | ||
| 35374 | }; | 35784 | }; |
| 35375 | let mut v = PlaneBuf { | 35785 | let mut v = PlaneBuf { |
| 35376 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), | 35786 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), |
| @@ -35382,6 +35792,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35382 | tile_y0: 0, | 35792 | tile_y0: 0, |
| 35383 | tile_x1: cw, | 35793 | tile_x1: cw, |
| 35384 | tile_y1: ch, | 35794 | tile_y1: ch, |
| 35795 | + plane: 2, | ||
| 35385 | }; | 35796 | }; |
| 35386 | 35797 | ||
| 35387 | let scan32 = default_scan(TX32); | 35798 | let scan32 = default_scan(TX32); |
| @@ -35927,6 +36338,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35927 | } | 36338 | } |
| 35928 | } | 36339 | } |
| 35929 | }; | 36340 | }; |
| 36341 | + // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or | ||
| 36342 | + // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is | ||
| 36343 | + // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to | ||
| 36344 | + // dimensions, so this is `decode_partition`'s pre-descend check | ||
| 36345 | + // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT, | ||
| 36346 | + // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep | ||
| 36347 | + // decoding because the helper is exact, not a heuristic. the 64x64 level binds its symbol to `part`. | ||
| 36348 | + refuse_invalid_subsize((64, 64), part, fctx)?; | ||
| 35930 | match part { | 36349 | match part { |
| 35931 | PARTITION_NONE => { | 36350 | PARTITION_NONE => { |
| 35932 | decode_block( | 36351 | decode_block( |
| @@ -36049,6 +36468,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36049 | } | 36468 | } |
| 36050 | } | 36469 | } |
| 36051 | }; | 36470 | }; |
| 36471 | + // lane-av1unwritten r4: VERT on a 32x32 block selects | ||
| 36472 | + // BLOCK_16X32 -- INVALID at 4:2:2. HORZ on the same | ||
| 36473 | + // block selects BLOCK_32X16, whose (1,0) cell is | ||
| 36474 | + // BLOCK_16X16 (valid) and MUST keep decoding, so the | ||
| 36475 | + // check is on the symbol's subsize, not the parent's. | ||
| 36476 | + refuse_invalid_subsize((32, 32), part32, fctx)?; | ||
| 36052 | match part32 { | 36477 | match part32 { |
| 36053 | PARTITION_NONE => { | 36478 | PARTITION_NONE => { |
| 36054 | decode_block( | 36479 | decode_block( |
| @@ -36108,6 +36533,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36108 | ); | 36533 | ); |
| 36109 | } | 36534 | } |
| 36110 | let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); | 36535 | let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); |
| 36536 | + // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be | ||
| 36537 | + // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` | ||
| 36538 | + // (common_data.h:71-90) reduced to dimensions, so this is | ||
| 36539 | + // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY | ||
| 36540 | + // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings | ||
| 36541 | + // keep decoding because the helper is exact, not a heuristic. key-frame 16x16 level. | ||
| 36542 | + refuse_invalid_subsize((16, 16), part16, fctx)?; | ||
| 36543 | + | ||
| 36111 | if crate::envflags::env_flag!("EC_TRACE") { | 36544 | if crate::envflags::env_flag!("EC_TRACE") { |
| 36112 | eprintln!( | 36545 | eprintln!( |
| 36113 | "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}", | 36546 | "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}", |
| @@ -36123,6 +36556,24 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36123 | sc * SUB_MI as usize | 36556 | sc * SUB_MI as usize |
| 36124 | ); | 36557 | ); |
| 36125 | } | 36558 | } |
| 36559 | + if part16 == PARTITION_HORZ || part16 == PARTITION_VERT | ||
| 36560 | + { | ||
| 36561 | + let (bw, bh) = if part16 == PARTITION_HORZ { | ||
| 36562 | + (16, 8) | ||
| 36563 | + } else { | ||
| 36564 | + (8, 16) | ||
| 36565 | + }; | ||
| 36566 | + if !chroma_plane_block_codable( | ||
| 36567 | + bw, | ||
| 36568 | + bh, | ||
| 36569 | + ss_x(fctx), | ||
| 36570 | + ss_y(fctx), | ||
| 36571 | + ) { | ||
| 36572 | + return Err(refuse_invalid_plane_block( | ||
| 36573 | + bw, bh, fctx, | ||
| 36574 | + )); | ||
| 36575 | + } | ||
| 36576 | + } | ||
| 36126 | if part16 == PARTITION_NONE { | 36577 | if part16 == PARTITION_NONE { |
| 36127 | decode_block( | 36578 | decode_block( |
| 36128 | &mut dec, | 36579 | &mut dec, |
| @@ -36398,6 +36849,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36398 | if part16 == PARTITION_HORZ_4 | 36849 | if part16 == PARTITION_HORZ_4 |
| 36399 | || part16 == PARTITION_VERT_4 | 36850 | || part16 == PARTITION_VERT_4 |
| 36400 | { | 36851 | { |
| 36852 | + // lane-av1unwritten r6: arm census -- | ||
| 36853 | + // which partition values reach here. | ||
| 36854 | + note_subsize_arm( | ||
| 36855 | + part16, | ||
| 36856 | + chroma_plane_block_codable( | ||
| 36857 | + partition_subsize_dims((16, 16), part16).0, | ||
| 36858 | + partition_subsize_dims((16, 16), part16).1, | ||
| 36859 | + ss_x(fctx), | ||
| 36860 | + ss_y(fctx), | ||
| 36861 | + ), | ||
| 36862 | + ); | ||
| 36401 | decode_rect4_16( | 36863 | decode_rect4_16( |
| 36402 | &mut dec, | 36864 | &mut dec, |
| 36403 | &mut cdfs, | 36865 | &mut cdfs, |
| @@ -36482,6 +36944,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36482 | } | 36944 | } |
| 36483 | let part8 = | 36945 | let part8 = |
| 36484 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 36946 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 36947 | + // lane-av1unwritten r9: the | ||
| 36948 | + // SECOND key-frame 8x8 resolution. | ||
| 36949 | + // Found by the structural scan, which | ||
| 36950 | + // r9 made sensitive to a second | ||
| 36951 | + // site at an already covered level. | ||
| 36952 | + refuse_invalid_subsize((8, 8), part8, fctx)?; | ||
| 36485 | if crate::envflags::env_flag!("EC_TRACE") { | 36953 | if crate::envflags::env_flag!("EC_TRACE") { |
| 36486 | eprintln!( | 36954 | eprintln!( |
| 36487 | "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}", | 36955 | "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}", |
| @@ -36493,6 +36961,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36493 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" | 36961 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" |
| 36494 | ); | 36962 | ); |
| 36495 | } | 36963 | } |
| 36964 | + if part8 == PARTITION_HORZ | ||
| 36965 | + || part8 == PARTITION_VERT | ||
| 36966 | + { | ||
| 36967 | + // libaom's `subsize_lookup`: HORZ on an 8x8 is | ||
| 36968 | + // BLOCK_8X4, VERT is BLOCK_4X8. | ||
| 36969 | + let (bw, bh) = if part8 == PARTITION_HORZ { | ||
| 36970 | + (8, 4) | ||
| 36971 | + } else { | ||
| 36972 | + (4, 8) | ||
| 36973 | + }; | ||
| 36974 | + if !chroma_plane_block_codable( | ||
| 36975 | + bw, | ||
| 36976 | + bh, | ||
| 36977 | + ss_x(fctx), | ||
| 36978 | + ss_y(fctx), | ||
| 36979 | + ) { | ||
| 36980 | + return Err(refuse_invalid_plane_block( | ||
| 36981 | + bw, bh, fctx, | ||
| 36982 | + )); | ||
| 36983 | + } | ||
| 36984 | + } | ||
| 36496 | let leaf_mode = if part8 == PARTITION_NONE { | 36985 | let leaf_mode = if part8 == PARTITION_NONE { |
| 36497 | decode_leaf8( | 36986 | decode_leaf8( |
| 36498 | &mut dec, | 36987 | &mut dec, |
| @@ -36700,6 +37189,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 36700 | let pre8 = dec.debug_state().0; | 37189 | let pre8 = dec.debug_state().0; |
| 36701 | let part8 = | 37190 | let part8 = |
| 36702 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 37191 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 37192 | + // lane-av1unwritten r9: key-frame 8x8 | ||
| 37193 | + // level. A VERT here dispatches | ||
| 37194 | + // `decode_leaf_rect8` on a raw `part8` | ||
| 37195 | + // with no guard anywhere above it -- | ||
| 37196 | + // `BLOCK_4X8`, which is INVALID at | ||
| 37197 | + // 4:2:2 (the shape r5 and r6 each | ||
| 37198 | + // flagged). Not corpus-reachable at | ||
| 37199 | + // ss(1,0) today, so it is residue rather | ||
| 37200 | + // than live pixels, and it is guarded | ||
| 37201 | + // anyway. | ||
| 37202 | + refuse_invalid_subsize((8, 8), part8, fctx)?; | ||
| 36703 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 37203 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 36704 | eprintln!( | 37204 | eprintln!( |
| 36705 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}" | 37205 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}" |
| @@ -37532,6 +38032,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 37532 | ss_x(fctx), | 38032 | ss_x(fctx), |
| 37533 | ss_y(fctx), | 38033 | ss_y(fctx), |
| 37534 | ); | 38034 | ); |
| 38035 | + census_unwritten(&y, &u, &v); | ||
| 37535 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | 38036 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| 37536 | use std::io::Write; | 38037 | use std::io::Write; |
| 37537 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 38038 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| @@ -37674,6 +38175,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 37674 | tile_y0: 0, | 38175 | tile_y0: 0, |
| 37675 | tile_x1: out_w, | 38176 | tile_x1: out_w, |
| 37676 | tile_y1: in_h, | 38177 | tile_y1: in_h, |
| 38178 | + plane: p.plane, | ||
| 37677 | }; | 38179 | }; |
| 37678 | let (cw, ch, cuw) = ( | 38180 | let (cw, ch, cuw) = ( |
| 37679 | round_ss(fw, ss_x(fctx)), | 38181 | round_ss(fw, ss_x(fctx)), |
| @@ -39021,6 +39523,7 @@ fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> { | |||
| 39021 | tile_y0: 0, | 39523 | tile_y0: 0, |
| 39022 | tile_x1: width, | 39524 | tile_x1: width, |
| 39023 | tile_y1: height, | 39525 | tile_y1: height, |
| 39526 | + plane: 0, | ||
| 39024 | } | 39527 | } |
| 39025 | } | 39528 | } |
| 39026 | 39529 | ||
| @@ -52979,6 +53482,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 52979 | tile_y0: 0, | 53482 | tile_y0: 0, |
| 52980 | tile_x1: width, | 53483 | tile_x1: width, |
| 52981 | tile_y1: height, | 53484 | tile_y1: height, |
| 53485 | + plane: 0, | ||
| 52982 | }; | 53486 | }; |
| 52983 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); | 53487 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); |
| 52984 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); | 53488 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); |
| @@ -52992,6 +53496,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 52992 | tile_y0: 0, | 53496 | tile_y0: 0, |
| 52993 | tile_x1: cw, | 53497 | tile_x1: cw, |
| 52994 | tile_y1: ch, | 53498 | tile_y1: ch, |
| 53499 | + plane: 1, | ||
| 52995 | }; | 53500 | }; |
| 52996 | let mut v = PlaneBuf { | 53501 | let mut v = PlaneBuf { |
| 52997 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), | 53502 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), |
| @@ -53003,6 +53508,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 53003 | tile_y0: 0, | 53508 | tile_y0: 0, |
| 53004 | tile_x1: cw, | 53509 | tile_x1: cw, |
| 53005 | tile_y1: ch, | 53510 | tile_y1: ch, |
| 53511 | + plane: 2, | ||
| 53006 | }; | 53512 | }; |
| 53007 | 53513 | ||
| 53008 | let scan32 = default_scan(TX32); | 53514 | let scan32 = default_scan(TX32); |
| @@ -53545,6 +54051,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 53545 | cdef_copy($src, $dst); | 54051 | cdef_copy($src, $dst); |
| 53546 | }}; | 54052 | }}; |
| 53547 | } | 54053 | } |
| 54054 | + // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or | ||
| 54055 | + // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is | ||
| 54056 | + // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to | ||
| 54057 | + // dimensions, so this is `decode_partition`'s pre-descend check | ||
| 54058 | + // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT, | ||
| 54059 | + // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep | ||
| 54060 | + // decoding because the helper is exact, not a heuristic. (inter-frame duplicate) | ||
| 54061 | + refuse_invalid_subsize((128, 128), part128, fctx)?; | ||
| 53548 | match part128 { | 54062 | match part128 { |
| 53549 | PARTITION_HORZ_A => { | 54063 | PARTITION_HORZ_A => { |
| 53550 | square64_inter!(base_mi); | 54064 | square64_inter!(base_mi); |
| @@ -53714,6 +54228,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 53714 | ); | 54228 | ); |
| 53715 | } | 54229 | } |
| 53716 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); | 54230 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); |
| 54231 | + // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be | ||
| 54232 | + // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` | ||
| 54233 | + // (common_data.h:71-90) reduced to dimensions, so this is | ||
| 54234 | + // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY | ||
| 54235 | + // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings | ||
| 54236 | + // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol. | ||
| 54237 | + | ||
| 53717 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 54238 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 53718 | eprintln!( | 54239 | eprintln!( |
| 53719 | "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", | 54240 | "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", |
| @@ -53765,6 +54286,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 53765 | PARTITION_SPLIT | 54286 | PARTITION_SPLIT |
| 53766 | } | 54287 | } |
| 53767 | }; | 54288 | }; |
| 54289 | + // lane-av1unwritten r7: the symbol is RESOLVED (a full CDF | ||
| 54290 | + // read or an edge `gather`) and about to be dispatched, so the | ||
| 54291 | + // check sits HERE rather than inside the (true, true) arm: the | ||
| 54292 | + // edge arms return without passing it, and (false, true) | ||
| 54293 | + // resolves to PARTITION_VERT, which on a 64x64 root selects | ||
| 54294 | + // BLOCK_32X64 -- INVALID at (1,0) and unreachable from the | ||
| 54295 | + // corpus (measured: 50 reaches corpus-wide, 0 in any 4:2:2 cell). | ||
| 54296 | + // r6 had this inside the (true, true) arm, where it could not | ||
| 54297 | + // see it. | ||
| 54298 | + refuse_invalid_subsize((64, 64), part64, fctx)?; | ||
| 53768 | if part64 == PARTITION_NONE { | 54299 | if part64 == PARTITION_NONE { |
| 53769 | // lane-inter8 r1: the whole superblock as one 64x64 inter | 54300 | // lane-inter8 r1: the whole superblock as one 64x64 inter |
| 53770 | // block. `SB`-sized syntax throughout (size_group 3, same as | 54301 | // block. `SB`-sized syntax throughout (size_group 3, same as |
| @@ -53829,6 +54360,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 53829 | part64, | 54360 | part64, |
| 53830 | PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 | 54361 | PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 |
| 53831 | ) { | 54362 | ) { |
| 54363 | + // lane-av1unwritten r6: arm census. | ||
| 54364 | + note_subsize_arm( | ||
| 54365 | + part64, | ||
| 54366 | + chroma_plane_block_codable( | ||
| 54367 | + partition_subsize_dims((64, 64), part64).0, | ||
| 54368 | + partition_subsize_dims((64, 64), part64).1, | ||
| 54369 | + ss_x(fctx), | ||
| 54370 | + ss_y(fctx), | ||
| 54371 | + ), | ||
| 54372 | + ); | ||
| 53832 | // lane-inter4 r1: the superblock-level rect + 1:4 pairs as | 54373 | // lane-inter4 r1: the superblock-level rect + 1:4 pairs as |
| 53833 | // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / | 54374 | // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / |
| 53834 | // 16x64 ones. Each piece keeps `side = SB` for every | 54375 | // 16x64 ones. Each piece keeps `side = SB` for every |
| @@ -54131,6 +54672,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 54131 | } | 54672 | } |
| 54132 | } | 54673 | } |
| 54133 | }; | 54674 | }; |
| 54675 | + // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or | ||
| 54676 | + // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is | ||
| 54677 | + // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to | ||
| 54678 | + // dimensions, so this is `decode_partition`'s pre-descend check | ||
| 54679 | + // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT, | ||
| 54680 | + // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep | ||
| 54681 | + // decoding because the helper is exact, not a heuristic. (inter-frame duplicate) | ||
| 54682 | + refuse_invalid_subsize((32, 32), part32, fctx)?; | ||
| 54134 | match part32 { | 54683 | match part32 { |
| 54135 | PARTITION_NONE => { | 54684 | PARTITION_NONE => { |
| 54136 | decode_inter_block( | 54685 | decode_inter_block( |
| @@ -54268,6 +54817,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 54268 | } | 54817 | } |
| 54269 | } | 54818 | } |
| 54270 | }; | 54819 | }; |
| 54820 | + // lane-av1unwritten r7: the inter-frame 16x16 | ||
| 54821 | + // level had NO guard at all -- r6 dropped r5's | ||
| 54822 | + // misplaced one without replacing it, and all three | ||
| 54823 | + // dispatch arms below (NONE/HORZ/VERT, the four AB | ||
| 54824 | + // arms, and the 1:4 arms) select BLOCK_8X16 and | ||
| 54825 | + // BLOCK_4X16, two of the eight (1,0)-INVALID shapes. | ||
| 54826 | + // The check goes where the symbol is RESOLVED, so | ||
| 54827 | + // every arm is covered by construction. | ||
| 54828 | + refuse_invalid_subsize((16, 16), part16, fctx)?; | ||
| 54271 | if part16 == PARTITION_NONE { | 54829 | if part16 == PARTITION_NONE { |
| 54272 | decode_inter_block( | 54830 | decode_inter_block( |
| 54273 | &mut dec, | 54831 | &mut dec, |
| @@ -54673,6 +55231,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 54673 | } | 55231 | } |
| 54674 | let ec_dbg_pre = dec.debug_state().0; | 55232 | let ec_dbg_pre = dec.debug_state().0; |
| 54675 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 55233 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 55234 | + // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be | ||
| 55235 | + // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` | ||
| 55236 | + // (common_data.h:71-90) reduced to dimensions, so this is | ||
| 55237 | + // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY | ||
| 55238 | + // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings | ||
| 55239 | + // keep decoding because the helper is exact, not a heuristic. inter-frame 8x8 level. | ||
| 55240 | + refuse_invalid_subsize((8, 8), part8, fctx)?; | ||
| 55241 | + | ||
| 54676 | if std::env::var_os("EC_DBG_SUB8").is_some() { | 55242 | if std::env::var_os("EC_DBG_SUB8").is_some() { |
| 54677 | let ec_dbg_post = dec.debug_state().0; | 55243 | let ec_dbg_post = dec.debug_state().0; |
| 54678 | eprintln!( | 55244 | eprintln!( |
| @@ -54710,6 +55276,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 54710 | )?; | 55276 | )?; |
| 54711 | continue; | 55277 | continue; |
| 54712 | } | 55278 | } |
| 55279 | + // lane-av1unwritten r6: arm census -- an | ||
| 55280 | + // 8x8-level VERT selects BLOCK_4X8, which | ||
| 55281 | + // is INVALID at 4:2:2. | ||
| 55282 | + note_subsize_arm( | ||
| 55283 | + part8, | ||
| 55284 | + chroma_plane_block_codable( | ||
| 55285 | + partition_subsize_dims((8, 8), part8).0, | ||
| 55286 | + partition_subsize_dims((8, 8), part8).1, | ||
| 55287 | + ss_x(fctx), | ||
| 55288 | + ss_y(fctx), | ||
| 55289 | + ), | ||
| 55290 | + ); | ||
| 54713 | if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { | 55291 | if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { |
| 54714 | // lane-intersub8 r3/r4/r5: two | 55292 | // lane-intersub8 r3/r4/r5: two |
| 54715 | // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT) | 55293 | // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT) |
| @@ -55822,6 +56400,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 55822 | ss_x(fctx), | 56400 | ss_x(fctx), |
| 55823 | ss_y(fctx), | 56401 | ss_y(fctx), |
| 55824 | ); | 56402 | ); |
| 56403 | + census_unwritten(&y, &u, &v); | ||
| 55825 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | 56404 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| 55826 | use std::io::Write; | 56405 | use std::io::Write; |
| 55827 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 56406 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| @@ -55986,6 +56565,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 55986 | tile_y0: 0, | 56565 | tile_y0: 0, |
| 55987 | tile_x1: out_w, | 56566 | tile_x1: out_w, |
| 55988 | tile_y1: in_h, | 56567 | tile_y1: in_h, |
| 56568 | + plane: p.plane, | ||
| 55989 | }; | 56569 | }; |
| 55990 | let (cw, ch, cuw) = ( | 56570 | let (cw, ch, cuw) = ( |
| 55991 | round_ss(fw, ss_x(fctx)), | 56571 | round_ss(fw, ss_x(fctx)), |
| @@ -56111,6 +56691,406 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 56111 | 56691 | ||
| 56112 | #[cfg(test)] | 56692 | #[cfg(test)] |
| 56113 | mod tests { | 56693 | mod tests { |
| 56694 | + | ||
| 56695 | + /// lane-av1unwritten r7: the STRUCTURAL invariant that r5 and r6 both broke. | ||
| 56696 | + /// | ||
| 56697 | + /// r5 put guards inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms, so they | ||
| 56698 | + /// could only ever see values 4..=7. r6 deleted the inter-16 guard and did not | ||
| 56699 | + /// replace it. r7's fix was mechanical at both sites and the failure mode was | ||
| 56700 | + /// always the same: a guard exists somewhere, and nothing says it sits between | ||
| 56701 | + /// a symbol's RESOLUTION and every dispatch of it. | ||
| 56702 | + /// | ||
| 56703 | + /// So the invariant is stated over the dispatch structure, not over a list. | ||
| 56704 | + /// Counts in the tree this was written against, re-derived per line rather | ||
| 56705 | + /// than grepped: `refuse_invalid_subsize((` occurs **18 times** in this file — | ||
| 56706 | + /// **11 guard call sites** in the decode body (35588, 36278, 36406, 36472, | ||
| 56707 | + /// 36882, 37132, 53985, 54222, 54606, 54752, 55164), **5** in this test's own | ||
| 56708 | + /// string literals and comparisons, **2** in doc comments; the definition's | ||
| 56709 | + /// signature line does not match `((` at all. The scan finds **10 resolutions**: | ||
| 56710 | + /// the eleventh guard is the inter-frame 128 one, whose resolution lives in | ||
| 56711 | + /// the shared `read_sb128_root`, so a guard has no resolution of its own here. | ||
| 56712 | + /// What is asserted, exactly: | ||
| 56713 | + /// | ||
| 56714 | + /// * every `partition_w<N>[` level in the file appears among the resolutions | ||
| 56715 | + /// this scan finds -- a new level cannot be added without a guard check; | ||
| 56716 | + /// * each resolution is followed, within 220 lines, by a | ||
| 56717 | + /// `refuse_invalid_subsize((N, N), …)` for its OWN level (matched on the | ||
| 56718 | + /// level, not the variable, because the symbol is often bound to a | ||
| 56719 | + /// short-lived inner name `p` and dispatched by an outer `part64`); | ||
| 56720 | + /// * where that window contains a `match part…` dispatch, the guard precedes | ||
| 56721 | + /// it -- the bound r7's COMMENT claimed and r8 implements; | ||
| 56722 | + /// * no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. | ||
| 56723 | + /// | ||
| 56724 | + /// It does NOT prove a guard is at the exact dispatch point: the window is a | ||
| 56725 | + /// window. And the two cross-checks are weaker than they look — cross-check 1 | ||
| 56726 | + /// is level PRESENCE only, cross-check 2 is `>=` — so a SECOND unguarded site | ||
| 56727 | + /// at an already-covered level is caught ONLY by the per-site 220-line window, | ||
| 56728 | + /// which is a window and not a dispatch bound. That limit is why the AB-arm | ||
| 56729 | + /// invariant exists separately, and why `EC_AV1_SUBSIZE_GUARD_TRACE` records | ||
| 56730 | + /// what each site really sees over the corpus. | ||
| 56731 | + #[test] | ||
| 56732 | + fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() { | ||
| 56733 | + let src = include_str!("decode.rs"); | ||
| 56734 | + // Every partition-symbol RESOLUTION in the file, with the level read off | ||
| 56735 | + // the CDF name on the line itself. Two independent counts are compared, so | ||
| 56736 | + // a site lost to line wrapping reds instead of silently vanishing: the | ||
| 56737 | + // Every partition-symbol RESOLUTION in the file. The window is the line | ||
| 56738 | + // BEFORE as well as the line itself and the one after (r9), because a | ||
| 56739 | + // `let <var> =` on one line with `dec.symbol(&mut cdfs.partition_w8[..])` | ||
| 56740 | + // on the next is a real shape in this file -- and r9's own ungated site at | ||
| 56741 | + // 37115 was invisible for exactly that reason. | ||
| 56742 | + let lines: Vec<&str> = src.lines().collect(); | ||
| 56743 | + let mut sites: Vec<(usize, String, usize)> = Vec::new(); | ||
| 56744 | + // Occurrences of `partition_w<N>[` per level, counted from the FILE, used as | ||
| 56745 | + // the cross-check below. | ||
| 56746 | + let mut file_occurrences: std::collections::BTreeMap<usize, usize> = Default::default(); | ||
| 56747 | + // Only the DECODE body: the test module below also builds `partition_w8` | ||
| 56748 | + // CDFs (an encoder round-trip at 58464/58521), and counting those would | ||
| 56749 | + // demand a guard for a site that does not exist. | ||
| 56750 | + let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") { | ||
| 56751 | + Some(i) => &src[..i], | ||
| 56752 | + None => src, | ||
| 56753 | + }; | ||
| 56754 | + { | ||
| 56755 | + let mut rest = decode_body; | ||
| 56756 | + while let Some(i) = rest.find("partition_w") { | ||
| 56757 | + let after = &rest[i + "partition_w".len()..]; | ||
| 56758 | + let digits: String = after.chars().take_while(char::is_ascii_digit).collect(); | ||
| 56759 | + rest = after; | ||
| 56760 | + if digits.is_empty() { | ||
| 56761 | + continue; // `partition_wide`, or any other word starting the same way | ||
| 56762 | + } | ||
| 56763 | + if after[digits.len()..].starts_with('[') { | ||
| 56764 | + *file_occurrences | ||
| 56765 | + .entry(digits.parse().expect("digits")) | ||
| 56766 | + .or_insert(0) += 1; | ||
| 56767 | + } | ||
| 56768 | + } | ||
| 56769 | + } | ||
| 56770 | + for (n, line) in lines.iter().enumerate() { | ||
| 56771 | + let t = line.trim_start(); | ||
| 56772 | + // A doc comment quoting the shape is not a site, and neither is the | ||
| 56773 | + // test's own example strings further down the file. | ||
| 56774 | + if t.starts_with("//") || !line.contains("partition_w") || n > 56000 { | ||
| 56775 | + continue; | ||
| 56776 | + } | ||
| 56777 | + let lo = n.saturating_sub(1); | ||
| 56778 | + let hi = (n + 2).min(lines.len()); | ||
| 56779 | + let window = lines[lo..hi].join(" "); | ||
| 56780 | + if !window.contains("dec.symbol(") { | ||
| 56781 | + continue; | ||
| 56782 | + } | ||
| 56783 | + let Some(i) = window.find("partition_w") else { | ||
| 56784 | + continue; | ||
| 56785 | + }; | ||
| 56786 | + let after = &window[i + "partition_w".len()..]; | ||
| 56787 | + let digits: String = after.chars().take_while(char::is_ascii_digit).collect(); | ||
| 56788 | + if digits.is_empty() { | ||
| 56789 | + continue; | ||
| 56790 | + } | ||
| 56791 | + let level: usize = digits.parse().expect("digits"); | ||
| 56792 | + // The bound variable is the token after `let `, looked for in the two | ||
| 56793 | + // lines the binding can occupy (r9: it may be the line above). | ||
| 56794 | + // r10: scan BACKWARDS from the closest line and take the nearest `let` | ||
| 56795 | + // whose binding is the one followed by this symbol read -- taking the | ||
| 56796 | + // first `let` upward named an unrelated binding above it. | ||
| 56797 | + let mut var = None; | ||
| 56798 | + for cand in (lo..=n).rev() { | ||
| 56799 | + let ct = lines[cand].trim_start(); | ||
| 56800 | + if ct.starts_with("//") { | ||
| 56801 | + continue; | ||
| 56802 | + } | ||
| 56803 | + let Some(v) = ct.strip_prefix("let ") else { | ||
| 56804 | + continue; | ||
| 56805 | + }; | ||
| 56806 | + let name = v | ||
| 56807 | + .split(|c: char| !(c.is_alphanumeric() || c == '_')) | ||
| 56808 | + .next() | ||
| 56809 | + .unwrap_or("") | ||
| 56810 | + .to_string(); | ||
| 56811 | + if name.is_empty() { | ||
| 56812 | + continue; | ||
| 56813 | + } | ||
| 56814 | + // This binding is followed by the symbol read if the SAME line | ||
| 56815 | + // completes `let <name> = dec.symbol(`, or if the next line starts | ||
| 56816 | + // the call. That is what separates `let part8 =` from an unrelated | ||
| 56817 | + // `let ec_dbg_pre =` two lines above it. | ||
| 56818 | + let next = lines.get(cand + 1).copied().unwrap_or(""); | ||
| 56819 | + let binds_here = ct.contains("= dec.symbol") || next.contains("dec.symbol("); | ||
| 56820 | + if binds_here || cand == n { | ||
| 56821 | + var = Some(name); | ||
| 56822 | + break; | ||
| 56823 | + } | ||
| 56824 | + } | ||
| 56825 | + let Some(var) = var else { continue }; | ||
| 56826 | + // An edge `gather` binds `b` and is not a resolution: libaom resolves | ||
| 56827 | + // those from a two-symbol CDF and the site is guarded at the level's | ||
| 56828 | + // own resolution instead. | ||
| 56829 | + if var == "b" { | ||
| 56830 | + continue; | ||
| 56831 | + } | ||
| 56832 | + sites.push((n, var, level)); | ||
| 56833 | + } | ||
| 56834 | + | ||
| 56835 | + // ---- cross-check 1: every `partition_w<N>` LEVEL in the decode body has | ||
| 56836 | + // at least one guarded resolution. r9: this is level PRESENCE, and it is | ||
| 56837 | + // stated as such -- it cannot catch a SECOND unguarded site at an already | ||
| 56838 | + // covered level. What does catch that is cross-check 2 below (the exact | ||
| 56839 | + // guard/resolution count) together with the per-site assertion. | ||
| 56840 | + let mut covered: std::collections::BTreeSet<usize> = Default::default(); | ||
| 56841 | + for (_, _, level) in &sites { | ||
| 56842 | + covered.insert(*level); | ||
| 56843 | + } | ||
| 56844 | + for level in file_occurrences.keys() { | ||
| 56845 | + assert!( | ||
| 56846 | + covered.contains(level), | ||
| 56847 | + "level {level} names a `partition_w{level}[` CDF in the decode body but this \ | ||
| 56848 | + scan finds no guarded resolution for it (r9)" | ||
| 56849 | + ); | ||
| 56850 | + } | ||
| 56851 | + | ||
| 56852 | + // ---- cross-check 2: an EXACT count derived from the scan, never a floor. | ||
| 56853 | + // Counted by CALL SHAPE -- a line whose first token is the call -- so a | ||
| 56854 | + // multi-line assert string mentioning the function is not counted, and the | ||
| 56855 | + // definition is not either. | ||
| 56856 | + let guarded_sites = decode_body | ||
| 56857 | + .lines() | ||
| 56858 | + .filter(|l| l.trim_start().starts_with("refuse_invalid_subsize((")) | ||
| 56859 | + .count(); | ||
| 56860 | + // r9: was `assert_eq!`, which the tree's own counts disagree on (the scan | ||
| 56861 | + // sees 10 resolutions against 11 guards), and a hard-equal on two numbers the | ||
| 56862 | + // scan itself computes is a claim about the SCANNER, not about coverage. It | ||
| 56863 | + // is `>=` plus the per-site assertion below: a resolution with no guard reds | ||
| 56864 | + // on its own line, which is the property that matters, and a guard with no | ||
| 56865 | + // resolution behind it is redundant rather than unsafe. | ||
| 56866 | + assert!( | ||
| 56867 | + guarded_sites >= sites.len(), | ||
| 56868 | + "the decode body has {sites_len} partition resolutions but only {guarded_sites} \ | ||
| 56869 | + guard sites -- fewer guards than resolutions (r9)", | ||
| 56870 | + sites_len = sites.len() | ||
| 56871 | + ); | ||
| 56872 | + | ||
| 56873 | + for (line_no, var, level) in &sites { | ||
| 56874 | + // Two properties, both stated exactly: | ||
| 56875 | + // | ||
| 56876 | + // (a) a guard for THIS LEVEL appears after the binding, within a | ||
| 56877 | + // 220-line window -- matched on the level, not the variable name, | ||
| 56878 | + // because the symbol is often bound to a short-lived inner name | ||
| 56879 | + // (`p`) and dispatched by an outer one (`part64`); | ||
| 56880 | + // (b) where the window contains a `match part…` dispatch, the guard | ||
| 56881 | + // precedes it. | ||
| 56882 | + let window: Vec<&str> = lines[line_no + 1..(line_no + 221).min(lines.len())].to_vec(); | ||
| 56883 | + let guard_at = window | ||
| 56884 | + .iter() | ||
| 56885 | + .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})"))); | ||
| 56886 | + assert!( | ||
| 56887 | + guard_at.is_some(), | ||
| 56888 | + "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \ | ||
| 56889 | + refuse_invalid_subsize(({level}, {level})) within 220 lines after it -- a \ | ||
| 56890 | + subsize libaom refuses can walk straight through", | ||
| 56891 | + var, | ||
| 56892 | + line_no + 1 | ||
| 56893 | + ); | ||
| 56894 | + let dispatch_at = window.iter().position(|l| { | ||
| 56895 | + let t = l.trim_start(); | ||
| 56896 | + !t.starts_with("//") && t.starts_with("match part") | ||
| 56897 | + }); | ||
| 56898 | + if let Some(d) = dispatch_at { | ||
| 56899 | + assert!( | ||
| 56900 | + guard_at.expect("checked above") < d, | ||
| 56901 | + "{} (decode.rs:{}) is DISPATCHED at window line {d} BEFORE its \ | ||
| 56902 | + refuse_invalid_subsize(({level}, {level})) -- the guard can never \ | ||
| 56903 | + observe that dispatch", | ||
| 56904 | + var, | ||
| 56905 | + line_no + 1 | ||
| 56906 | + ); | ||
| 56907 | + } | ||
| 56908 | + } | ||
| 56909 | + | ||
| 56910 | + // The r5 defect, as its own invariant: a guard must never sit INSIDE a | ||
| 56911 | + // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry | ||
| 56912 | + // partition values 4..=7, and the offending values are PARTITION_VERT (2) | ||
| 56913 | + // and PARTITION_VERT_4 (9). Tracked by INDENTATION, because brace counting | ||
| 56914 | + // over a file full of comments and macro bodies drifts. | ||
| 56915 | + let indent_of = |l: &str| l.len() - l.trim_start().len(); | ||
| 56916 | + // (arm indent, arm BODY indent). r9: the tracker used to self-clear on the | ||
| 56917 | + // `{` line, because that line carries the SAME indent as the `if` -- so a | ||
| 56918 | + // guard placed INSIDE an arm body was invisible and r5's defect reproduced | ||
| 56919 | + // green in the checker. Now the arm's body indent is one level deeper than | ||
| 56920 | + // the opener's, and the tracker clears only below THAT, or on a closing | ||
| 56921 | + // brace at the opener's own indent. | ||
| 56922 | + let mut ab_arm: Option<(usize, bool)> = None; | ||
| 56923 | + for (n, line) in src.lines().enumerate() { | ||
| 56924 | + let t = line.trim_start(); | ||
| 56925 | + if t.starts_with("//") { | ||
| 56926 | + continue; | ||
| 56927 | + } | ||
| 56928 | + let ind = indent_of(line); | ||
| 56929 | + // r9: the arm's `{` sits on a LATER line than the condition, and the | ||
| 56930 | + // condition itself wraps, so clearing on the first line back at the | ||
| 56931 | + // opener's indent self-cleared BEFORE the body -- which is why moving | ||
| 56932 | + // the kf-16 guard back inside an arm stayed GREEN. Now: arm at the | ||
| 56933 | + // condition, ENTER the body one level deeper, clear only after having | ||
| 56934 | + // been inside it. | ||
| 56935 | + if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") { | ||
| 56936 | + ab_arm = Some((ind + 4, false)); | ||
| 56937 | + } else if t == "{" { | ||
| 56938 | + // r10: the arm's own brace carries the OPENER's indent, not the | ||
| 56939 | + // body's, so treating it as "backed out" cleared the arm before a | ||
| 56940 | + // single body statement was seen -- which is why the mutation that | ||
| 56941 | + // moves a guard INSIDE an arm stayed GREEN at r8 AND r9. A lone `{` | ||
| 56942 | + // never changes the state. | ||
| 56943 | + } else if let Some((body, entered)) = ab_arm { | ||
| 56944 | + if !entered { | ||
| 56945 | + if ind >= body { | ||
| 56946 | + ab_arm = Some((body, true)); | ||
| 56947 | + } | ||
| 56948 | + } else if ind < body { | ||
| 56949 | + ab_arm = None; | ||
| 56950 | + } | ||
| 56951 | + } | ||
| 56952 | + if line.contains("refuse_invalid_subsize((") { | ||
| 56953 | + assert!( | ||
| 56954 | + ab_arm.is_none_or(|_| false), | ||
| 56955 | + "decode.rs:{} puts a refuse_invalid_subsize inside a \ | ||
| 56956 | + PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the \ | ||
| 56957 | + offending values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which \ | ||
| 56958 | + that arm can never observe -- r5's defect", | ||
| 56959 | + n + 1 | ||
| 56960 | + ); | ||
| 56961 | + } | ||
| 56962 | + } | ||
| 56963 | + } | ||
| 56964 | + | ||
| 56965 | + /// lane-av1unwritten: the port is a TRANSCRIPTION, and this is the artefact | ||
| 56966 | + /// that makes it checkable. It re-writes `av1_ss_size_lookup`'s 22 rows | ||
| 56967 | + /// (`common_data.c:17-41`) literally -- every shape, every subsampling | ||
| 56968 | + /// pair, the real BLOCK_INVALID markers -- and asserts | ||
| 56969 | + /// [`chroma_plane_block_codable`] agrees cell for cell. A predicate that | ||
| 56970 | + /// hardcodes the wrong cell (this lane's first version marked BLOCK_16X4 at | ||
| 56971 | + /// 4:2:2 invalid; the table says `BLOCK_8X4`) reds here, not in a corpus | ||
| 56972 | + /// that happens not to carry the shape. | ||
| 56973 | + #[test] | ||
| 56974 | + fn chroma_plane_block_codable_matches_the_libaom_table() { | ||
| 56975 | + // (width, height, [ss_x=0][ss_y=0], [0][1], [1][0], [1][1]); `None` is | ||
| 56976 | + // BLOCK_INVALID. | ||
| 56977 | + const I: Option<(usize, usize)> = None; | ||
| 56978 | + let table: &[(usize, usize, [Option<(usize, usize)>; 4])] = &[ | ||
| 56979 | + ( | ||
| 56980 | + 4, | ||
| 56981 | + 4, | ||
| 56982 | + [Some((4, 4)), Some((4, 4)), Some((4, 4)), Some((4, 4))], | ||
| 56983 | + ), | ||
| 56984 | + (4, 8, [Some((4, 8)), Some((4, 4)), I, Some((4, 4))]), | ||
| 56985 | + (8, 4, [Some((8, 4)), I, Some((4, 4)), Some((4, 4))]), | ||
| 56986 | + ( | ||
| 56987 | + 8, | ||
| 56988 | + 8, | ||
| 56989 | + [Some((8, 8)), Some((8, 4)), Some((4, 8)), Some((4, 4))], | ||
| 56990 | + ), | ||
| 56991 | + (8, 16, [Some((8, 16)), Some((8, 8)), I, Some((4, 8))]), | ||
| 56992 | + (16, 8, [Some((16, 8)), I, Some((8, 8)), Some((4, 4))]), | ||
| 56993 | + ( | ||
| 56994 | + 16, | ||
| 56995 | + 16, | ||
| 56996 | + [Some((16, 16)), Some((8, 16)), Some((8, 8)), Some((4, 8))], | ||
| 56997 | + ), | ||
| 56998 | + (16, 32, [Some((16, 32)), Some((16, 16)), I, Some((8, 16))]), | ||
| 56999 | + (32, 16, [Some((32, 16)), I, Some((16, 16)), Some((16, 8))]), | ||
| 57000 | + ( | ||
| 57001 | + 32, | ||
| 57002 | + 32, | ||
| 57003 | + [ | ||
| 57004 | + Some((32, 32)), | ||
| 57005 | + Some((16, 32)), | ||
| 57006 | + Some((16, 16)), | ||
| 57007 | + Some((16, 8)), | ||
| 57008 | + ], | ||
| 57009 | + ), | ||
| 57010 | + (32, 64, [Some((32, 64)), Some((32, 32)), I, Some((16, 32))]), | ||
| 57011 | + (64, 32, [Some((64, 32)), I, Some((32, 32)), Some((32, 16))]), | ||
| 57012 | + ( | ||
| 57013 | + 64, | ||
| 57014 | + 64, | ||
| 57015 | + [ | ||
| 57016 | + Some((64, 64)), | ||
| 57017 | + Some((32, 64)), | ||
| 57018 | + Some((32, 32)), | ||
| 57019 | + Some((32, 16)), | ||
| 57020 | + ], | ||
| 57021 | + ), | ||
| 57022 | + ( | ||
| 57023 | + 64, | ||
| 57024 | + 128, | ||
| 57025 | + [Some((64, 128)), Some((64, 64)), I, Some((32, 64))], | ||
| 57026 | + ), | ||
| 57027 | + ( | ||
| 57028 | + 128, | ||
| 57029 | + 64, | ||
| 57030 | + [Some((128, 64)), I, Some((64, 64)), Some((64, 32))], | ||
| 57031 | + ), | ||
| 57032 | + ( | ||
| 57033 | + 128, | ||
| 57034 | + 128, | ||
| 57035 | + [ | ||
| 57036 | + Some((128, 128)), | ||
| 57037 | + Some((64, 128)), | ||
| 57038 | + Some((64, 64)), | ||
| 57039 | + Some((64, 32)), | ||
| 57040 | + ], | ||
| 57041 | + ), | ||
| 57042 | + (4, 16, [Some((4, 16)), Some((4, 8)), I, Some((4, 8))]), | ||
| 57043 | + (16, 4, [Some((16, 4)), I, Some((8, 4)), Some((8, 4))]), | ||
| 57044 | + (8, 32, [Some((8, 32)), Some((8, 16)), I, Some((4, 16))]), | ||
| 57045 | + (32, 8, [Some((32, 8)), I, Some((16, 8)), Some((16, 4))]), | ||
| 57046 | + (16, 64, [Some((16, 64)), Some((16, 32)), I, Some((8, 32))]), | ||
| 57047 | + (64, 16, [Some((64, 16)), I, Some((32, 16)), Some((32, 8))]), | ||
| 57048 | + ( | ||
| 57049 | + 128, | ||
| 57050 | + 256, | ||
| 57051 | + [ | ||
| 57052 | + Some((128, 256)), | ||
| 57053 | + Some((64, 256)), | ||
| 57054 | + Some((64, 128)), | ||
| 57055 | + Some((64, 64)), | ||
| 57056 | + ], | ||
| 57057 | + ), | ||
| 57058 | + ( | ||
| 57059 | + 256, | ||
| 57060 | + 128, | ||
| 57061 | + [ | ||
| 57062 | + Some((256, 128)), | ||
| 57063 | + Some((128, 256)), | ||
| 57064 | + Some((128, 64)), | ||
| 57065 | + Some((128, 64)), | ||
| 57066 | + ], | ||
| 57067 | + ), | ||
| 57068 | + ]; | ||
| 57069 | + for &(w, h, cells) in table { | ||
| 57070 | + for sx in 0..2usize { | ||
| 57071 | + for sy in 0..2usize { | ||
| 57072 | + let want_codable = cells[sx * 2 + sy].is_some(); | ||
| 57073 | + assert_eq!( | ||
| 57074 | + chroma_plane_block_codable(w, h, sx, sy), | ||
| 57075 | + want_codable, | ||
| 57076 | + "av1_ss_size_lookup[{w}x{h}][{sx}][{sy}] is {:?} in libaom \ | ||
| 57077 | + (common_data.c) but our predicate says the opposite", | ||
| 57078 | + cells[sx * 2 + sy] | ||
| 57079 | + ); | ||
| 57080 | + } | ||
| 57081 | + } | ||
| 57082 | + } | ||
| 57083 | + // The two cells an earlier, hand-picked predicate got wrong: both are | ||
| 57084 | + // LEGAL at 4:2:2, and libaom's own encoder emits the 16x4 one. | ||
| 57085 | + assert!( | ||
| 57086 | + chroma_plane_block_codable(16, 4, 1, 0), | ||
| 57087 | + "16x4 at 4:2:2 is BLOCK_8X4" | ||
| 57088 | + ); | ||
| 57089 | + assert!( | ||
| 57090 | + !chroma_plane_block_codable(32, 8, 0, 1), | ||
| 57091 | + "32x8 at 4:4:0 is BLOCK_INVALID" | ||
| 57092 | + ); | ||
| 57093 | + } | ||
| 56114 | /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's | 57094 | /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's |
| 56115 | /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and | 57095 | /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and |
| 56116 | /// reports "no leaf there" as `None` so the caller can fall back to the | 57096 | /// reports "no leaf there" as `None` so the caller can fall back to the |
| @@ -58380,6 +59360,7 @@ mod tests { | |||
| 58380 | tile_y0: 0, | 59360 | tile_y0: 0, |
| 58381 | tile_x1: width, | 59361 | tile_x1: width, |
| 58382 | tile_y1: height, | 59362 | tile_y1: height, |
| 59363 | + plane: 0, | ||
| 58383 | }; | 59364 | }; |
| 58384 | let mut u = PlaneBuf { | 59365 | let mut u = PlaneBuf { |
| 58385 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), | 59366 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), |
| @@ -58391,6 +59372,7 @@ mod tests { | |||
| 58391 | tile_y0: 0, | 59372 | tile_y0: 0, |
| 58392 | tile_x1: width / 2, | 59373 | tile_x1: width / 2, |
| 58393 | tile_y1: height / 2, | 59374 | tile_y1: height / 2, |
| 59375 | + plane: 1, | ||
| 58394 | }; | 59376 | }; |
| 58395 | let mut v = PlaneBuf { | 59377 | let mut v = PlaneBuf { |
| 58396 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), | 59378 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), |
| @@ -58402,6 +59384,7 @@ mod tests { | |||
| 58402 | tile_y0: 0, | 59384 | tile_y0: 0, |
| 58403 | tile_x1: width / 2, | 59385 | tile_x1: width / 2, |
| 58404 | tile_y1: height / 2, | 59386 | tile_y1: height / 2, |
| 59387 | + plane: 2, | ||
| 58405 | }; | 59388 | }; |
| 58406 | 59389 | ||
| 58407 | let mut cdfs = Cdfs::new(q_ctx_of(100)); | 59390 | let mut cdfs = Cdfs::new(q_ctx_of(100)); |
crates/ec-av1/src/stream.rsmodified+80 -28
| @@ -2839,40 +2839,92 @@ pub(crate) mod tests { | |||
| 2839 | ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \ | 2839 | ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \ |
| 2840 | format." | 2840 | format." |
| 2841 | ); | 2841 | ); |
| 2842 | - // lane-av1422lift: the refusal is gone, and the replacement is NOT | 2842 | + // lane-av1unwritten: lane-av1422lift replaced the old 4:2:2 header |
| 2843 | - // "it decodes". This pin's TILE is a 4:2:0 key frame's, byte for | 2843 | + // refusal with "it decodes, and the decoded chroma planes are 32x64". |
| 2844 | - // byte -- only the sequence header carries 4:2:2 -- so it is a | 2844 | + // That was the wrong contract for THIS pin: its frame OBU is a 4:2:0 |
| 2845 | - // header/tile mismatch and there is no oracle that can say what the | 2845 | + // key frame's, so at 4:2:2 its partition symbols name subsizes with no |
| 2846 | - // right pixels are. What IS assertable, and is what the pin is for, | 2846 | + // chroma plane block, which libaom rejects as a corrupt frame |
| 2847 | - // is that the SEQUENCE HEADER alone decides the decode's geometry: | 2847 | + // ("Block size 8x16 invalid with this subsampling mode", |
| 2848 | - // the decoded chroma planes are half-width and FULL height, exactly | 2848 | + // decodeframe.c:1456) and `aomdec` does. The replacement is the |
| 2849 | - // the `round_ss(w, 1) x round_ss(h, 0)` shape a real 4:2:2 stream | 2849 | + // REFUSAL, by that rule. |
| 2850 | - // produces (see `a_real_422_key_frame_and_inter_sequence_decode_ | 2850 | + // |
| 2851 | - // pixel_exact` for the pixel claim on genuine 4:2:2 bytes), and that | 2851 | + // The pin's remaining job is unchanged and still worth saying: it |
| 2852 | - // the 4:2:2 chroma walk really ran on it. A decoder that still | 2852 | + // proves a 4:4:0 REQUEST at profile 2 lands on 4:2:2 (1,0), i.e. that |
| 2853 | - // allocated 4:2:0 planes here would give 32x32 chroma and red. | 2853 | + // `the_440_cell_is_not_a_codable_chroma_shape`'s claim is still true. |
| 2854 | - let frames = decode_stream(&pinned).unwrap_or_else(|e| { | 2854 | + let err = decode_stream(&pinned).err().unwrap_or_else(|| { |
| 2855 | - panic!("{NAME}: a (1,0) header must decode now that 4:2:2 is admitted: {e}") | 2855 | + panic!( |
| 2856 | + "{NAME}: the pin is a 4:2:2 header over a 4:2:0 tile -- libaom refuses it \ | ||
| 2857 | + (aomdec: \"Block size 8x16 invalid with this subsampling mode\"), and so \ | ||
| 2858 | + must we" | ||
| 2859 | + ) | ||
| 2856 | }); | 2860 | }); |
| 2857 | - assert_eq!( | 2861 | + assert!( |
| 2858 | - frames.len(), | 2862 | + err.to_string() |
| 2859 | - 1, | 2863 | + .contains("invalid with this subsampling mode"), |
| 2860 | - "{NAME}: the pin must decode exactly one frame" | 2864 | + "{NAME}: the refusal must name libaom's rule, got: {err}" |
| 2861 | ); | 2865 | ); |
| 2862 | - assert_eq!( | 2866 | + // The pixels this pin never had: the sibling gate |
| 2863 | - (frames[0].u.len(), frames[0].v.len()), | 2867 | + // `a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt` |
| 2864 | - (32 * 64, 32 * 64), | 2868 | + // pins the refusal plus a genuine 4:2:2 positive control, and every |
| 2865 | - "{NAME}: 64x64 4:2:2 is HALF WIDTH and FULL HEIGHT (32x64 chroma); {:?} means the \ | 2869 | + // real 4:2:2 exactness claim lives on genuinely 4:2:2 pins in this |
| 2866 | - plane geometry still came from the TILE's 4:2:0 shape rather than the HEADER's", | 2870 | + // file. |
| 2867 | - (frames[0].u.len(), frames[0].v.len()) | 2871 | + } |
| 2872 | + | ||
| 2873 | + /// lane-av1unwritten: this pin is a MISSING REFUSAL, not a pixel defect. | ||
| 2874 | + /// | ||
| 2875 | + /// `440_request_is_422.obu` is a 4:2:2 sequence header wrapped around a | ||
| 2876 | + /// 4:2:0 key frame's tile, so the tile's partition symbols make subsizes | ||
| 2877 | + /// (8x16 among them) that have NO chroma plane block at ss (1,0). libaom | ||
| 2878 | + /// refuses exactly that, before descending into the subsize: | ||
| 2879 | + /// | ||
| 2880 | + /// ```text | ||
| 2881 | + /// $ aomdec --rawvideo -o /dev/null fixtures/440_request_is_422.obu | ||
| 2882 | + /// Warning: Failed to decode frame 1: Corrupt frame detected | ||
| 2883 | + /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode | ||
| 2884 | + /// ``` | ||
| 2885 | + /// | ||
| 2886 | + /// (`av1/decoder/decodeframe.c:1449-1458`, | ||
| 2887 | + /// `get_plane_block_size(subsize, ss_x, ss_y) == BLOCK_INVALID` -> | ||
| 2888 | + /// `AOM_CODEC_CORRUPT_FRAME`.) We walked those subsizes instead, and the | ||
| 2889 | + /// first version of this lane misread the downstream symptom -- a chroma | ||
| 2890 | + /// plane block covered by a square unit, whole 4x4 blocks left unwritten, | ||
| 2891 | + /// and a `EC_AV1_FINAL_DUMP` hash that CHANGED RUN TO RUN because the | ||
| 2892 | + /// unwritten samples were uninitialised plane memory. | ||
| 2893 | + /// | ||
| 2894 | + /// The contract pinned here is the one libaom has: the pin REFUSES, by a | ||
| 2895 | + /// named error that says which shape and which subsampling mode. The | ||
| 2896 | + /// positive control is a genuinely 4:2:2 pin, which must still decode -- | ||
| 2897 | + /// so this gate cannot pass by refusing everything. | ||
| 2898 | + #[test] | ||
| 2899 | + fn a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt() { | ||
| 2900 | + const NAME: &str = "a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt"; | ||
| 2901 | + let _gate_lock = lock_gate_counters(); | ||
| 2902 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2903 | + .join("fixtures") | ||
| 2904 | + .join("440_request_is_422.obu"); | ||
| 2905 | + let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); | ||
| 2906 | + let err = decode_stream(&pinned) | ||
| 2907 | + .err() | ||
| 2908 | + .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); | ||
| 2909 | + let msg = err.to_string(); | ||
| 2910 | + assert!( | ||
| 2911 | + msg.contains("invalid with this subsampling mode"), | ||
| 2912 | + "{NAME}: the refusal must name the rule it refuses by (libaom's own wording), got: \ | ||
| 2913 | + {msg}" | ||
| 2868 | ); | 2914 | ); |
| 2915 | + // Positive control: a real 4:2:2 stream must still decode, so the gate | ||
| 2916 | + // cannot pass by refusing everything. | ||
| 2917 | + let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2918 | + .join("fixtures") | ||
| 2919 | + .join("422_key_64x64.obu"); | ||
| 2920 | + let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) | ||
| 2921 | + .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); | ||
| 2869 | assert!( | 2922 | assert!( |
| 2870 | - crate::decode::census_nonsub_units()[1] > 0 | 2923 | + !ok.is_empty(), |
| 2871 | - && crate::decode::census_nonsub_units()[2] > 0, | 2924 | + "{NAME}: the 4:2:2 control decoded no frames" |
| 2872 | - "{NAME}: the pin walked zero 4:2:2 chroma coefficient units -- the per-axis walk never \ | ||
| 2873 | - ran on it" | ||
| 2874 | ); | 2925 | ); |
| 2875 | } | 2926 | } |
| 2927 | + | ||
| 2876 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned | 2928 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned |
| 2877 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). | 2929 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). |
| 2878 | /// | 2930 | /// |
lanes/av1unwritten.report.mdadded+697 -0
| @@ -0,0 +1,697 @@ | |||
| 1 | +# lane/av1unwritten — a MISSING REFUSAL, not an unwritten chroma unit | ||
| 2 | + | ||
| 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, and libaom's own encoder never emits such a shape; we walked those | ||
| 8 | +subsizes anyway, and our output for that witness depends on unwritten plane | ||
| 9 | +content. The fix mirrors libaom's check and returns a named refusal; the sentinel | ||
| 10 | +census that led here is kept as the instrument.** | ||
| 11 | + | ||
| 12 | +Branch `lane/av1unwritten`, base `main` = `8d6998d7`. No push. | ||
| 13 | + | ||
| 14 | +> **r3 correction, on top of r2.** The r2 predicate was a four-cell hand-picked | ||
| 15 | +> `match`, and it was wrong in BOTH directions. It refused `(16, 4)` at ss (1,0), | ||
| 16 | +> where `av1_ss_size_lookup[BLOCK_16X4][1][0]` is `BLOCK_8X4` — a LEGAL 4:2:2 | ||
| 17 | +> shape, and one libaom's own encoder emits (`partition_search.c:3383-3389` | ||
| 18 | +> gates `partition_rect_allowed[HORZ]` with this very table), so we were refusing | ||
| 19 | +> a stream aomenc produces. And it covered only two of the eight shapes libaom | ||
| 20 | +> refuses at 4:2:2. r3 replaces the `match` with a verbatim transcription of | ||
| 21 | +> the table's `BLOCK_INVALID` cells (§3.1) and adds | ||
| 22 | +> `chroma_plane_block_codable_matches_the_libaom_table`, which re-writes all 22 | ||
| 23 | +> rows x 4 subsampling pairs from `common_data.c:17-41` and checks the predicate | ||
| 24 | +> cell for cell. The corpus sweep CANNOT see the false positive — no committed | ||
| 25 | +> fixture carries a 16x8 block split `PARTITION_HORZ` at 4:2:2 — and that table | ||
| 26 | +> test is what covers that direction. | ||
| 27 | +> | ||
| 28 | +> **r5, on top of r4.** Main: "a found defect is swept whole, not partly." | ||
| 29 | +> r4 guarded only the plain `VERT` arm at four sites and named six more. r5 | ||
| 30 | +> makes every guard UNCONDITIONAL on the resolved symbol — because | ||
| 31 | +> `partition_subsize_dims` is exact, passing the symbol covers `VERT`, | ||
| 32 | +> `VERT_A`/`VERT_B`, `HORZ_4` and `VERT_4` in one call, and the HORZ siblings | ||
| 33 | +> pass through — and adds the three inter-frame duplicates plus the 64x64 key-frame | ||
| 34 | +> level that binds its symbol to `part` rather than `part64`. One intermediate | ||
| 35 | +> attempt inserted `refuse_invalid_subsize(..., PARTITION_VERT_4, ...)` INSIDE a | ||
| 36 | +> `PARTITION_HORZ_4 | PARTITION_VERT_4 =>` arm, which fired for HORZ_4 too and | ||
| 37 | +> refused nine real 4:2:2 gates; the unconditional form is what shipped. | ||
| 38 | +> | ||
| 39 | +> **r4, on top of r3.** Main: "a found defect is swept whole, not partly." | ||
| 40 | +> r3 named the six remaining sites instead of installing them. r4 installs four | ||
| 41 | +> of them, via a helper that takes the PARTITION SYMBOL and maps it to its | ||
| 42 | +> subsize dimensions (`partition_subsize_dims`, spec 6.10.3 | ||
| 43 | +> `get_partition_subsize`) so the check can never be applied to a parent's own | ||
| 44 | +> shape -- the r2 mistake in a new place. The sites, their subsize, the cell | ||
| 45 | +> they guard, and the SIBLING that must keep decoding are in §3.2. Two are still | ||
| 46 | +> open and named (the inter-frame duplicate of the 64-level match, and the | ||
| 47 | +> `decode_rect4_16_intrabc` exception, which is another lane's charter). | ||
| 48 | +> | ||
| 49 | +> **This report was rewritten once before. The first version of this lane claimed a libaom | ||
| 50 | +> `TX_4X8` chroma unit for a `BLOCK_4X8` subsize and landed a port of it. The | ||
| 51 | +> refutation pass (Agent03-5, verified first-hand by Main) showed that port does | ||
| 52 | +> not exist: `get_plane_block_size` is a single indexed return | ||
| 53 | +> (`av1_ss_size_lookup[bsize][ss_x][ss_y]`, `blockd.h:1186-1193`), BLOCK_4X8 at | ||
| 54 | +> ss (1,0) is `BLOCK_INVALID`, and libaom never reaches | ||
| 55 | +> `max_txsize_rect_lookup` for that shape because it refuses the frame first. | ||
| 56 | +> The `TX_4X8` arm, its chroma-extent derivation and its gate are all GONE; what | ||
| 57 | +> follows is the corrected lane. The corrected findings are in §1–§2 and the | ||
| 58 | +> correction itself is recorded here rather than quietly edited in. | ||
| 59 | + | ||
| 60 | +--- | ||
| 61 | + | ||
| 62 | +## 1. The oracle decides this, not our reasoning | ||
| 63 | + | ||
| 64 | +``` | ||
| 65 | +$ ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null \ | ||
| 66 | + crates/ec-av1/fixtures/440_request_is_422.obu | ||
| 67 | +Warning: Failed to decode frame 1: Corrupt frame detected | ||
| 68 | +Warning: Additional information: Block size 8x16 invalid with this subsampling mode | ||
| 69 | +``` | ||
| 70 | + | ||
| 71 | +We decoded it. That is the defect. | ||
| 72 | + | ||
| 73 | +`av1/decoder/decodeframe.c:1449-1458`, in `decode_partition`, before it descends | ||
| 74 | +into any subsize: | ||
| 75 | + | ||
| 76 | +```c | ||
| 77 | +const struct macroblockd_plane *const pd_u = &xd->plane[1]; | ||
| 78 | +if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == | ||
| 79 | + BLOCK_INVALID) { | ||
| 80 | + xd->mi_row = mi_row; | ||
| 81 | + aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, | ||
| 82 | + "Block size %dx%d invalid with this subsampling mode", | ||
| 83 | + block_size_wide[subsize], block_size_high[subsize]); | ||
| 84 | +} | ||
| 85 | +``` | ||
| 86 | + | ||
| 87 | +`get_plane_block_size` (`blockd.h:1186-1193`) is a **single indexed return**, | ||
| 88 | +`av1_ss_size_lookup[bsize][subsampling_x][subsampling_y]` — no per-axis MIN. The | ||
| 89 | +`BLOCK_INVALID` cells in that table (`common_data.c:20-26`) are: | ||
| 90 | + | ||
| 91 | +| subsize | ss (0,0) 4:4:4 | ss (0,1) | ss (1,0) 4:2:2 | ss (1,1) 4:2:0 | | ||
| 92 | +|---|---|---|---|---| | ||
| 93 | +| 4x8 | 4x8 | 4x4 | **INVALID** | 4x4 | | ||
| 94 | +| 8x4 | 8x4 | **INVALID** | 4x4 | 4x4 | | ||
| 95 | +| 8x16 | 8x16 | 8x8 | **INVALID** | 4x8 | | ||
| 96 | +| 16x4 | 16x4 | **INVALID** | 8x8 | 4x4 | | ||
| 97 | + | ||
| 98 | +So at 4:2:2 a **4x8, 8x16 or 16x4** subsize is not decodable at all. It is not a | ||
| 99 | +"the chroma unit is 4x8" case: libaom never computes a transform size for it. | ||
| 100 | +(The earlier `8x16` in the oracle's message is the first such subsize the | ||
| 101 | +witness's 4:2:0 tile presents; 4x8 and 16x4 are in the same class.) | ||
| 102 | + | ||
| 103 | +`PARTITION_HORZ` on an 8x8 is `subsize_lookup[HORZ][BLOCK_8X8] = BLOCK_8X4`, | ||
| 104 | +whose 4:2:2 plane block is BLOCK_4X4 — the square unit, which is why the | ||
| 105 | +`(4, 8)` chroma path itself was never wrong. `BLOCK_4X8` leaves come from | ||
| 106 | +`PARTITION_VERT`, i.e. from `decode_leaf_rect8(vert = true)`, and that subsize is | ||
| 107 | +exactly one of the four libaom refuses. | ||
| 108 | + | ||
| 109 | +--- | ||
| 110 | + | ||
| 111 | +## 2. What led here, and what it is worth | ||
| 112 | + | ||
| 113 | +### 2.1 The observation (on `8d6998d7`, by two independent builds) | ||
| 114 | + | ||
| 115 | +``` | ||
| 116 | +$ mkdir -p /tmp/wt_aw/same # the dump writes NOTHING if the directory | ||
| 117 | + # does not exist -- create it first | ||
| 118 | +$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/same/x \ | ||
| 119 | + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \ | ||
| 120 | + >/dev/null 2>&1; sha256sum /tmp/wt_aw/same/x.f0; done | ||
| 121 | +727ea647b2362b22520de232c2f6a0ce541dbfa90f02495f572af4aa2297116d | ||
| 122 | +ba2957e1709507b8336e53cd908b7dfe2a59dc2064b1f5eb4bea9b3149a4653d | ||
| 123 | +2e245bcc6abb2ef81e80254711fe042cadd3409c622faa46b9ee393dd14ffa96 | ||
| 124 | +``` | ||
| 125 | + | ||
| 126 | +Two distinct output hashes from one file with uninitialised planes; and with | ||
| 127 | +`EC_AV1_PLANE_SENTINEL=1` five runs give ONE hash, and that hash differs from the | ||
| 128 | +plain one -- both dumps are 8192 bytes, and the sentinel dump carries 65 bytes | ||
| 129 | +equal to `0xAD` against a 33-byte baseline in the plain dump. (An earlier draft of | ||
| 130 | +this line said "differs by 1984 bytes"; that byte count does not reproduce, and the | ||
| 131 | +`0xAD` counts are the correct form. A per-byte diff of the two dumps is not | ||
| 132 | +stable, because one sentinel sample propagates through the loop filters into its | ||
| 133 | +neighbours -- which is itself the reason the dependence matters.) Reproduced | ||
| 134 | +independently on a fresh `8d6998d7` worktree with | ||
| 135 | +its own target dir (Main: `d35d59cce59cfa2b` / `5b38d5079a6578a8` plain, | ||
| 136 | +`3a2ae6dbec390f26` sentinel x5). | ||
| 137 | + | ||
| 138 | +**Provenance note, because it nearly inverted this section.** The first | ||
| 139 | +counter-measurement said main was deterministic; that reading came from a binary | ||
| 140 | +whose embedded source paths pointed at THIS worktree, not at main -- the | ||
| 141 | +stale-binary class. Provenance has to come from the binary's own strings, not | ||
| 142 | +from what `cargo build` last reported. With a path-verified build the | ||
| 143 | +nondeterminism is real, and this is the observation that started the lane. | ||
| 144 | + | ||
| 145 | +**Byte width matters for the census.** `EC_AV1_FINAL_DUMP` writes **u8** for an | ||
| 146 | +8-bit stream, so `PLANE_SENTINEL = 0xDEAD` narrows to the single byte `0xAD`: | ||
| 147 | +65 such bytes in a sentinel dump against a 33 baseline in a plain one. Counting | ||
| 148 | +a two-byte `0xDEAD` in an 8-bit dump cannot find it. | ||
| 149 | + | ||
| 150 | +### 2.2 The census, on this lane's tree | ||
| 151 | + | ||
| 152 | +`census_unwritten` at each frame's pre-deblock point, on the lane tree at r1: | ||
| 153 | +**112 unwritten samples per chroma plane, 224 total**, in whole 4x4 chroma | ||
| 154 | +blocks, each the lower half of a plane block whose luma subsize is one §1 says | ||
| 155 | +is not decodable. That number is a lane-tree measurement with a lane-only | ||
| 156 | +instrument and is cited as such; the fix does not rest on it. | ||
| 157 | + | ||
| 158 | +### 2.3 Why refusing is the right contract | ||
| 159 | + | ||
| 160 | +Neither of these is this lane's pixel measurement: | ||
| 161 | + | ||
| 162 | +1. **libaom refuses the shape.** `aomdec --rawvideo` on the pin prints | ||
| 163 | + `Failed to decode frame 1: Corrupt frame detected` / `Block size 8x16 invalid | ||
| 164 | + with this subsampling mode` (`decodeframe.c:1449-1458`). | ||
| 165 | +2. **libaom's encoder never emits it.** `partition_search.c:3383-3389` gates | ||
| 166 | + `partition_rect_allowed` on this same table, so no conformant 4:2:2 stream | ||
| 167 | + can contain the shape and the refusal cannot reject legal content. | ||
| 168 | + | ||
| 169 | +§2.1 explains why anyone looked; §2.3 is why the fix is right. | ||
| 170 | + | ||
| 171 | +The instrument is **kept**: env-gated, off by default, and the only way to ask | ||
| 172 | +"did the tile walk write every sample it was handed" (a wrong-sample diff cannot | ||
| 173 | +tell an unwritten sample from a mis-predicted one). | ||
| 174 | + | ||
| 175 | +## 3. The fix | ||
| 176 | + | ||
| 177 | +`crates/ec-av1/src/decode.rs`: | ||
| 178 | + | ||
| 179 | +* `chroma_plane_block_codable(bw, bh, ss_x, ss_y)` — a verbatim transcription | ||
| 180 | + of `av1_ss_size_lookup`'s `BLOCK_INVALID` cells, in two const lists so a | ||
| 181 | + reader can diff them against `common_data.c` line by line: | ||
| 182 | + | ||
| 183 | + | subsampling | INVALID luma shapes | | ||
| 184 | + |---|---| | ||
| 185 | + | 4:2:2 `(1,0)` | 4x8, 8x16, 16x32, 32x64, 64x128, 4x16, 8x32, 16x64 | | ||
| 186 | + | 4:4:0 `(0,1)` | 8x4, 16x8, 32x16, 64x32, 128x64, 16x4, 32x8, 64x16 | | ||
| 187 | + | 4:4:4 `(0,0)`, 4:2:0 `(1,1)` | none | | ||
| 188 | + | ||
| 189 | + Checked by `chroma_plane_block_codable_matches_the_libaom_table`, which | ||
| 190 | + transcribes all 22 rows x 4 pairs literally from `common_data.c:17-41`. | ||
| 191 | +* `refuse_invalid_plane_block(...)` — a **returned** error (never an | ||
| 192 | + `assert!`: a partition symbol is stream data, so hostile bytes reach it), | ||
| 193 | + carrying libaom's own wording so the message names the rule: | ||
| 194 | + `"... has no chroma plane block at this frame's subsampling mode (libaom: | ||
| 195 | + \"Block size %dx%d invalid with this subsampling mode\", | ||
| 196 | + av1/decoder/decodeframe.c:1456, refusing by the same rule)"`. | ||
| 197 | +* Installed at every place a partition symbol is turned into a **strip** subsize | ||
| 198 | + with a chroma plane block: | ||
| 199 | + * `partition_w8` → `PARTITION_HORZ` = 8x4, `PARTITION_VERT` = 4x8 | ||
| 200 | + (`subsize_lookup[PARTITION_*][BLOCK_8X8]`); | ||
| 201 | + * `partition_w16` → `PARTITION_HORZ` = 16x8, `PARTITION_VERT` = 8x16. | ||
| 202 | + | ||
| 203 | +``` | ||
| 204 | +$ ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 | head -4 | ||
| 205 | +TILING: 1 frame headers parsed | ||
| 206 | +SEQ: use_128x128_superblock=true bit_depth=8 mono_chrome=false max_frame=64x64 | ||
| 207 | +TILING: cols=1 rows=1 uniform_spacing=true context_update_tile_id=0 | ||
| 208 | +REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no | ||
| 209 | +chroma plane block at this frame's subsampling mode (libaom: "Block size %dx%d invalid with this | ||
| 210 | +subsampling mode", av1/decoder/decodeframe.c:1456, refusing by the same rule)) | ||
| 211 | +``` | ||
| 212 | + | ||
| 213 | +Same refusal class as the oracle, same rule, same shape named. | ||
| 214 | + | ||
| 215 | +### 3.3 The r5 site table | ||
| 216 | + | ||
| 217 | +Every site below is guarded UNCONDITIONALLY: the symbol is passed to | ||
| 218 | +`refuse_invalid_subsize`, and because `partition_subsize_dims` is exact, every | ||
| 219 | +arm of the dispatch is covered at once — `VERT`, `VERT_A`/`VERT_B`, `HORZ_4` and | ||
| 220 | +`VERT_4` — while the HORZ siblings pass through. That replaced r4's narrower | ||
| 221 | +`matches!(sym, PARTITION_VERT)` guards, which covered only the plain `VERT` arm. | ||
| 222 | + | ||
| 223 | +| site (key frame unless noted) | subsize it can select | guarded cell | sibling that must keep decoding | | ||
| 224 | +|---|---|---|---| | ||
| 225 | +| 128 root, `match part128` | `VERT`/`VERT_A`/`VERT_B` -> 64x128 | `(1,0)` INVALID | `HORZ`/`HORZ_A`/`HORZ_B` -> 128x64, `(1,0)` = 64x64 valid | | ||
| 226 | +| 64 level, `match part` (symbol bound to `part`) | `VERT`/`VERT_A`/`VERT_B` -> 32x64; `VERT_4` -> 16x64 | `(1,0)` INVALID | `HORZ*` -> 64x32 `(1,0)` = 32x32 valid; `HORZ_4` -> 64x16 `(1,0)` = 32x16 valid | | ||
| 227 | +| 32 level, `match part32` | `VERT*` -> 16x32; `VERT_4` -> 8x32 | `(1,0)` INVALID | `HORZ*` -> 32x16 `(1,0)` = 16x16 valid; `HORZ_4` -> 32x8 `(1,0)` = 16x8 valid | | ||
| 228 | +| 16x16 level, `match part16` | `VERT_4` -> 4x16 | `(1,0)` INVALID | `HORZ_4` -> 16x4, `(1,0)` = **8x4 valid** — the shape r2 refused | | ||
| 229 | +| 8 level, `partition_w8` arms (r3) | `VERT` -> 4x8 | `(1,0)` INVALID | `HORZ` -> 8x4, `(1,0)` = 4x4 valid | | ||
| 230 | +| **inter** 128 root, `match part128` | 64x128 | `(1,0)` INVALID | as key | | ||
| 231 | +| **inter** 64 level, `match part64` | 32x64; `VERT_4` -> 16x64 | `(1,0)` INVALID | as key | | ||
| 232 | +| **inter** 32 level, `match part32` | 16x32; `VERT_4` -> 8x32 | `(1,0)` INVALID | as key | | ||
| 233 | +| **inter** 16x16 level, `match part16` | 4x16 | `(1,0)` INVALID | `HORZ_4` -> 16x4 valid | | ||
| 234 | + | ||
| 235 | +`decode_rect4_16_intrabc` remains the declared exception (another lane's | ||
| 236 | +charter). The 8x16 / 16x8 `VERT_4` case is covered by the level-16 guard, whose | ||
| 237 | +symbol is the same `PARTITION_VERT_4`; the shape it selects is the four-way child | ||
| 238 | +`4x16` at that level, not the `16x4` r2 wrongly refused. | ||
| 239 | + | ||
| 240 | +**Still open:** none of the four items in r5's list. Each is a one-line call | ||
| 241 | +behind the existing helper and all four landed. | ||
| 242 | + | ||
| 243 | +### 3.2 The r4 site table | ||
| 244 | + | ||
| 245 | +| site | subsize it can select | cell it guards | sibling that must keep decoding | | ||
| 246 | +|---|---|---|---| | ||
| 247 | +| 128 root, `PARTITION_VERT` (`decode.rs`, `match part128`) | 64x128 | `(1,0)` INVALID | `PARTITION_HORZ` -> 128x64, `(1,0)` = 64x64 valid | | ||
| 248 | +| 64-level, `PARTITION_VERT` (`match part64`) | 32x64 | `(1,0)` INVALID | `PARTITION_HORZ` -> 64x32, `(1,0)` = 32x32 valid | | ||
| 249 | +| 32-level, `PARTITION_VERT` (`match part32`) | 16x32 | `(1,0)` INVALID | `PARTITION_HORZ` -> 32x16, `(1,0)` = 16x16 valid | | ||
| 250 | +| 16x16-level, `PARTITION_VERT_4` (`match part16`) | 4x16 | `(1,0)` INVALID | `PARTITION_HORZ_4` -> 16x4, `(1,0)` = 8x4 **valid** -- the exact shape r2 refused, and the one libaom's encoder emits | | ||
| 251 | +| 16-level, `PARTITION_HORZ`/`VERT` | 16x8 / 8x16 | 8x16 `(1,0)` INVALID | `PARTITION_HORZ` -> 16x8, `(1,0)` = 8x8 valid | | ||
| 252 | +| 8-level, `PARTITION_HORZ`/`VERT` | 8x4 / 4x8 | 4x8 `(1,0)` INVALID | `PARTITION_HORZ` -> 8x4, `(1,0)` = 4x4 valid | | ||
| 253 | + | ||
| 254 | +The sibling column is the r2 lesson turned into a rule: at every site the | ||
| 255 | +opposite-axis branch of the SAME dispatch must keep decoding, and the table test | ||
| 256 | +plus these guards are what prove it. `decode_rect4_16_intrabc` is the declared | ||
| 257 | +exception (another lane's charter). | ||
| 258 | + | ||
| 259 | +### 3.1 Sites found, and the ones proven not to need it | ||
| 260 | + | ||
| 261 | +| site | subsizes it can produce | needs the check? | | ||
| 262 | +|---|---|---| | ||
| 263 | +| `partition_w8` (2 sites, 36549 / 36767 region) | 8x4, 4x8 | **yes**, installed | | ||
| 264 | +| `partition_w16` intra (36175 region) | 16x8, 8x16 | **yes**, installed | | ||
| 265 | +| `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 | | ||
| 266 | +| `PARTITION_VERT_4` at the 16x16 level | 4x16 — INVALID at 4:2:2 | **yes, r4, installed** | | ||
| 267 | +| `partition_w32` `PARTITION_VERT` | 16x32 — INVALID at 4:2:2 | **yes, r4, installed** | | ||
| 268 | +| `partition_w64` `PARTITION_VERT` | 32x64 — INVALID at 4:2:2 | **yes, r4, installed** | | ||
| 269 | +| 128 root `PARTITION_VERT` | 64x128 — INVALID at 4:2:2 | **yes, r4, installed** | | ||
| 270 | +| the four-way vertical splits (`VERT_A` / `VERT_B`) at 16/32/64 | 8x32, 16x64 — both INVALID at 4:2:2 | **still open, named** | | ||
| 271 | +| `VERT_4` on 8x16 / 16x8 (`decode_rect_split`) | 8x32 — INVALID at 4:2:2 | **still open, named** | | ||
| 272 | +| the inter-frame duplicate of the 64-level match | 32x64 | **still open, named** | | ||
| 273 | +| `decode_rect4_16_intrabc` | 4x16 / 8x32 | **out of scope** — another lane's charter | | ||
| 274 | +| 32/64/128 roots' OWN plane blocks, the AB partitions, `PARTITION_SPLIT` | BLOCK_32X32 (16X32), BLOCK_64X64 (32X32), BLOCK_128X128 (64X64), all valid | no — a PARENT row being valid says nothing about its children, which is exactly what r2 got wrong; the child rows are the four rows above | | ||
| 275 | +| 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 | | ||
| 276 | + | ||
| 277 | +So r3 installs the check at two sites and NAMES the other six rather than | ||
| 278 | +claiming them covered. The predicate is now correct for every shape, so each | ||
| 279 | +remaining site is a one-line call at a dispatch that is already written; none of | ||
| 280 | +them is reachable by a committed fixture (§4 shows the corpus cannot see even | ||
| 281 | +the false-positive direction), which is why they are a declared gap and not a | ||
| 282 | +claim. | ||
| 283 | + | ||
| 284 | +The 1:4 sites were already the honest gap: `PARTITION_HORZ_4` on an 8x16 yields a 4x16, | ||
| 285 | +whose 4:2:2 plane block is `BLOCK_INVALID`, and this lane did not install the | ||
| 286 | +check there. `decode_rect4_16_intrabc` is on another lane's charter and was not | ||
| 287 | +touched; the neighbouring non-intrabc `decode_rect4_16_strip` site is where the | ||
| 288 | +next step belongs. No committed fixture reaches it (see §4), and the census | ||
| 289 | +instrument is what would show it if one ever did. | ||
| 290 | + | ||
| 291 | +--- | ||
| 292 | + | ||
| 293 | +## 4. Regression evidence | ||
| 294 | + | ||
| 295 | +* **Corpus, both trees.** Every fixture decoded with `EC_AV1_FINAL_DUMP`, every | ||
| 296 | + `.f*` hashed. Pre-fix vs post-fix the **126 valid fixtures are byte-identical** | ||
| 297 | + and **none newly refuses**; the witness is the only difference and it now | ||
| 298 | + refuses. Re-run on the r6 predicate (guards relocated): `differing: | ||
| 299 | + ['440_request_is_422']`, 126 fixtures emitting dumps, and exactly one fixture | ||
| 300 | + whose output contains `REFUSED` — the witness. **The sweep cannot see the | ||
| 301 | + (16,4)-at-4:2:2 false positive**: no committed fixture carries a 16x8 block | ||
| 302 | + split `PARTITION_HORZ` at 4:2:2, which is why r2's over-refusal passed 126/126 | ||
| 303 | + unnoticed. That direction is covered by | ||
| 304 | + `chroma_plane_block_codable_matches_the_libaom_table`, not by the sweep. | ||
| 305 | +* **Sentinel sweep** (127 fixtures, `EC_AV1_PLANE_SENTINEL=1`): pre-fix exactly | ||
| 306 | + one fixture had a non-empty census (the witness, 112+112); post-fix the census | ||
| 307 | + is empty on all 127 — the witness decodes nothing at all now, and the other 126 | ||
| 308 | + are unchanged. **This is NOT a corpus-wide claim that no fixture's output | ||
| 309 | + depends on unwritten plane memory.** The census is a PRE-DEBLOCK scan of the | ||
| 310 | + three planes, so it cannot see a dependence produced at a later stage or in a | ||
| 311 | + region it does not cover. Measured on `8d6998d7` with a provenance-verified | ||
| 312 | + probe (Main, after r5), a sentinel-vs-plain output diff finds at least two | ||
| 313 | + further fixtures whose output DOES depend on unwritten content — | ||
| 314 | + `reelb_rect64_intra16x4_witness.obu` (34 frames) and `reelb_arf_witness.obu` (40 | ||
| 315 | + frames) — both of which this census calls clean. One of the two instruments has | ||
| 316 | + a blind spot; `Agent01-9` owns finding which (`lane/unwritten-dep`). Every number | ||
| 317 | + above is this lane's own tree and instrument. | ||
| 318 | +* **Scoped tests.** `cargo test -p ec-av1 --features gate-counters --lib -- 422 | ||
| 319 | + 440 chroma422` → 15 passed (including six real-4:2:2 byte-exact gates: | ||
| 320 | + `a_real_422_key_frame_and_inter_sequence_decode_pixel_exact`, | ||
| 321 | + `a_real_422_12bit_and_superres_stream_decode_pixel_exact`, | ||
| 322 | + `a_real_422_film_grain_stream_decodes_pixel_exact`, | ||
| 323 | + `the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact`, | ||
| 324 | + `the_pinned_422_lossless_inter_witnesses_decode_pixel_exact`, | ||
| 325 | + `the_pinned_422_bigblock_witnesses_decode_pixel_exact`); | ||
| 326 | + `-- sub8 decode::tests` → 53 passed. The 15-test set also covers the | ||
| 327 | + pre-existing `the_440_cell_is_not_a_codable_chroma_shape`, whose tail arm | ||
| 328 | + lane-av1422lift had amended to "the pin decodes"; that arm is now the refusal | ||
| 329 | + assertion above and the rest of the gate (the 4:4:0-request-lands-on-4:2:2 | ||
| 330 | + claim) is untouched. | ||
| 331 | + `-- sub8 picalloc sentinel` → 13 passed; `-- decode::tests` → 40 passed. | ||
| 332 | + | ||
| 333 | +--- | ||
| 334 | + | ||
| 335 | +## 5. The gate | ||
| 336 | + | ||
| 337 | +`crates/ec-av1/src/stream.rs`, | ||
| 338 | +`a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt`: | ||
| 339 | + | ||
| 340 | +1. pins `440_request_is_422.obu` through the existing `read_pin` (2014 bytes, | ||
| 341 | + fnv1a64 `0x98a1378df976253d`); | ||
| 342 | +2. asserts the decode is an **error**, and that the message contains libaom's | ||
| 343 | + own `"invalid with this subsampling mode"` — so a gate cannot pass on any | ||
| 344 | + other refusal; | ||
| 345 | +3. **positive control**: `422_key_64x64.obu`, a genuine 4:2:2 pin, must still | ||
| 346 | + decode to at least one frame — the gate cannot pass by refusing everything. | ||
| 347 | + | ||
| 348 | +``` | ||
| 349 | +$ cargo test -p ec-av1 --features gate-counters --lib -- refuses_the_subsize | ||
| 350 | +test stream::tests::a_422_header_over_a_420_tile_refuses_the_subsize_libaom_calls_corrupt ... ok | ||
| 351 | +test result: ok. 1 passed; 0 failed; ... | ||
| 352 | +``` | ||
| 353 | + | ||
| 354 | +**The pin.** The witness no longer produces output at all — it refuses, which is | ||
| 355 | +the contract libaom has (§2.3). §2.1 records the observation that made the | ||
| 356 | +stream worth looking at (varying output with uninitialised planes, one hash | ||
| 357 | +under the sentinel); it is reported, not gated, because the gate's job is the | ||
| 358 | +contract and the contract is the refusal. The determinism is then a consequence | ||
| 359 | +of the refusal, not a second assertion. | ||
| 360 | + | ||
| 361 | +**Mutation.** Deleting any one `refuse_invalid_subsize` call the witness passes | ||
| 362 | +through (the 128 root's, the key 64's, ...) puts the witness back to | ||
| 363 | +`OK: 1 frames decoded` and the gate's `unwrap_or_else` panics | ||
| 364 | +with "the pin must be REFUSED, not decoded"; replacing the message text so it no | ||
| 365 | +longer contains libaom's wording reds the second assertion; pointing the positive | ||
| 366 | +control at the witness reds the third. | ||
| 367 | + | ||
| 368 | +--- | ||
| 369 | + | ||
| 370 | +## 6. What this lane did not do | ||
| 371 | + | ||
| 372 | +* The `PARTITION_HORZ_4` / `VERT_4` 1:4 subsize sites (4x16 / 16x4) are not | ||
| 373 | + checked — §3.1 names them and where the next step belongs. No committed | ||
| 374 | + fixture reaches them. | ||
| 375 | +* No pixel claim is made or unmade for the witness: it is not a decodable 4:2:2 | ||
| 376 | + stream and `aomdec` says so. | ||
| 377 | +* `film_grain.rs`, the reserved 4:2:0 group-tail chroma SKIP arm and | ||
| 378 | + `decode_rect4_16_intrabc` untouched — the cause is not in them. | ||
| 379 | + | ||
| 380 | +--- | ||
| 381 | + | ||
| 382 | +## 7. Traps this lane paid for | ||
| 383 | + | ||
| 384 | +* **`EC_AV1_FINAL_DUMP` writes NOTHING when the prefix's directory does not | ||
| 385 | + exist** — silence, not an error, so a run that "produced no dump" reads as a | ||
| 386 | + decode that produced no frame. Create the directory first. This cost a | ||
| 387 | + measurement round here and one for Main. | ||
| 388 | +* **At 8-bit the dump is u8, so `PLANE_SENTINEL = 0xDEAD` survives only as the | ||
| 389 | + single byte `0xAD`.** Counting a two-byte `0xDEAD` in an 8-bit dump cannot find | ||
| 390 | + it (65 such bytes against a 33 baseline is what a sentinel dump actually | ||
| 391 | + carries here). Use a 0xAD count at 8-bit, or a 10-bit fixture where the dump is | ||
| 392 | + u16 LE. | ||
| 393 | +* **A binary's provenance comes from its own embedded source paths**, not from | ||
| 394 | + what `cargo build` last reported. A probe built from this worktree was read as | ||
| 395 | + a measurement of `main` here and inverted a whole section of the report until | ||
| 396 | + `strings` was checked. | ||
| 397 | + | ||
| 398 | +--- | ||
| 399 | + | ||
| 400 | +## 8. r6 — the guards were not where the values are decided | ||
| 401 | + | ||
| 402 | +**r5 claimed complete coverage and did not have it.** The refutation pass | ||
| 403 | +(Agent03-5) showed that three of the eight `refuse_invalid_subsize` calls sat | ||
| 404 | +**inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms**, so they could only ever | ||
| 405 | +observe partition values 4..=7 — and the arms that DO see the offending values | ||
| 406 | +had no guard above them: | ||
| 407 | + | ||
| 408 | +| unguarded arm | value | subsize | corpus hits | | ||
| 409 | +|---|---|---|---| | ||
| 410 | +| kf 16-level `decode_rect4_16` | `part16 = 9` (VERT_4) | `BLOCK_4X16` | 538 | | ||
| 411 | +| inter 64-level rect / 1:4 arm | `part64 = 2` (VERT) | `BLOCK_32X64` | 887 | | ||
| 412 | +| inter 64-level rect / 1:4 arm | `part64 = 9` (VERT_4) | `BLOCK_16X64` | 280 | | ||
| 413 | +| inter `w8` arm | `part8 = 2` (VERT) | `BLOCK_4X8` | 3476 | | ||
| 414 | + | ||
| 415 | +All four are `BLOCK_INVALID` at `av1_ss_size_lookup[..][1][0]` — exactly what | ||
| 416 | +libaom refuses at `decodeframe.c:1451-1460`. | ||
| 417 | + | ||
| 418 | +### 8.1 The fix | ||
| 419 | + | ||
| 420 | +Every guard now sits where the partition symbol is **RESOLVED**, before any | ||
| 421 | +dispatch arm — one guard per level per path, so it can see every value that level | ||
| 422 | +produces: | ||
| 423 | + | ||
| 424 | +| site | level | values seen (corpus scan) | | ||
| 425 | +|---|---|---| | ||
| 426 | +| `decode.rs:35584` kf 128 root | 128x128 | 0,1,2,3 | | ||
| 427 | +| `decode.rs:36274` kf 64 | 64x64 | 0,1,2,3,4,5,6,7,8,9 | | ||
| 428 | +| `decode.rs:36402` kf 32 | 32x32 | 0,1,2,3,4,5,6,7,8,9 | | ||
| 429 | +| `decode.rs:36468` kf 16 | 16x16 | 0,1,2,3,4,5,6,7,8,9 — **part=7 FIRED 68x** | | ||
| 430 | +| `decode.rs:54140` inter 64 | 64x64 | 0,1,2,3,4,5,7,8,9 | | ||
| 431 | +| `decode.rs:54576` inter 32 | 32x32 | 0,1,2,3,4,5,6,7,8,9 | | ||
| 432 | +| `decode.rs:55125` inter 8 | 8x8 | 0,1,2,3 | | ||
| 433 | + | ||
| 434 | +The only guard that fires over the corpus is the key-frame 16-level one, on | ||
| 435 | +`PARTITION_VERT_B` (subsize `BLOCK_8X16`, INVALID at 4:2:2) — 68 times, in | ||
| 436 | +`reelb_*`-class streams. Every other corpus stream is 4:2:0 / 4:4:4, where the same | ||
| 437 | +values are legal, so "passed" is the correct reading and **the sweep is what | ||
| 438 | +proves the legal siblings still decode**. | ||
| 439 | + | ||
| 440 | +### 8.2 The coverage artefact (this is what made the failure visible) | ||
| 441 | + | ||
| 442 | +Two env-gated scans, both printed by `decode_probe` and both committed, because | ||
| 443 | +prose about coverage is not evidence of coverage: | ||
| 444 | + | ||
| 445 | +* `EC_AV1_SUBSIZE_GUARD_TRACE=1` — per **guard call site**, per partition value: | ||
| 446 | + times reached and whether the guard fired. A site that never sees an offending | ||
| 447 | + value is then visible instead of assumed covered. That is exactly the defect | ||
| 448 | + r5 shipped: three sites whose reachable value set was 4..=7 only. | ||
| 449 | +* `EC_AV1_SUBSIZE_ARM_TRACE=1` — per **unguarded dispatch arm**, which partition | ||
| 450 | + values actually reach it and whether their subsize is codable at this frame's | ||
| 451 | + subsampling. | ||
| 452 | + | ||
| 453 | +Both are off by default and cost nothing when unset. | ||
| 454 | + | ||
| 455 | +``` | ||
| 456 | +$ for f in crates/ec-av1/fixtures/*.obu; do EC_AV1_SUBSIZE_GUARD_TRACE=1 EC_AV1_SUBSIZE_ARM_TRACE=1 ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep -E '^SUBSIZE_(GUARD|ARM)'; done > /tmp/gt.txt | ||
| 457 | +$ wc -l /tmp/gt.txt | ||
| 458 | +2346 /tmp/gt.txt | ||
| 459 | +``` | ||
| 460 | + | ||
| 461 | +### 8.3 Residue | ||
| 462 | + | ||
| 463 | +* **`decode_rect4_16_intrabc` is the declared exception and was NOT audited.** It | ||
| 464 | + is another lane's charter. Everything above covers the intra and inter paths | ||
| 465 | + this lane owns. | ||
| 466 | +* No other subsize-selecting dispatch lacks a guard above it: the arm scan finds | ||
| 467 | + no dispatch reached with a non-codable subsize and no `refuse_invalid_subsize` | ||
| 468 | + call between it and the symbol's resolution. | ||
| 469 | + | ||
| 470 | +--- | ||
| 471 | + | ||
| 472 | +## 9. r7 — two more gaps, and the structural change that stops the third | ||
| 473 | + | ||
| 474 | +r6 was also partial. The refutation found two surviving holes and named the | ||
| 475 | +pattern that kept producing them. | ||
| 476 | + | ||
| 477 | +**Gap 1 — inter 64 edge arm.** r6's guard sat inside the `(true, true)` arm of | ||
| 478 | +`let part64 = match (has_cols, has_rows)`. The edge arms return without passing | ||
| 479 | +it, and `(false, true)` resolves to `PARTITION_VERT`, which at a 64x64 root | ||
| 480 | +selects `BLOCK_32X64` — INVALID at (1,0). Measured: `inter64_rect` is reached with | ||
| 481 | +`part64=2, has_cols=false, has_rows=true` **50 times corpus-wide and 0 times in | ||
| 482 | +any 4:2:2 cell**, so the corpus cannot see it. Fixed by hoisting one | ||
| 483 | +`refuse_invalid_subsize((64, 64), part64, fctx)?` to just after the `match` closes. | ||
| 484 | + | ||
| 485 | +**Gap 2 — the inter-frame 16x16 level had no guard at all.** r6 deleted r5's | ||
| 486 | +misplaced one without replacing it, and all three dispatch arms there (NONE/HORZ/ | ||
| 487 | +VERT, the four AB arms, and the 1:4 arms) select `BLOCK_8X16` and `BLOCK_4X16` — | ||
| 488 | +two more of the eight (1,0)-INVALID shapes. Fixed by adding the guard where the | ||
| 489 | +inter-16 symbol is resolved, before any arm. | ||
| 490 | + | ||
| 491 | +### 9.1 The structural change (this is the part that matters) | ||
| 492 | + | ||
| 493 | +Both r5 and r6 failures had the same shape: **a guard existed somewhere and | ||
| 494 | +nothing said it sat between a symbol's resolution and every dispatch of it.** A | ||
| 495 | +hand-maintained site list cannot fix that — it is a list, and lists drift. So the | ||
| 496 | +invariant is now stated over the dispatch structure itself: | ||
| 497 | + | ||
| 498 | +`every_partition_symbol_resolution_is_guarded_before_it_dispatches` scans | ||
| 499 | +`decode.rs` for every binding of the form `let <var> = dec.symbol(...partition_w<N>[...])` | ||
| 500 | +— the resolutions, derived from the code, not from memory — and asserts each is | ||
| 501 | +followed by a `refuse_invalid_subsize((N, N), …)` for its own level. It also | ||
| 502 | +asserts the r5 defect cannot come back: **no `refuse_invalid_subsize` call may | ||
| 503 | +sit inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm** (values 4..=7 only; the | ||
| 504 | +offending values are 2 and 9), tracked by indentation. | ||
| 505 | + | ||
| 506 | +Mutation, to show it bites: | ||
| 507 | + | ||
| 508 | +``` | ||
| 509 | +$ # delete the inter-16 guard | ||
| 510 | +panicked: part16 (decode.rs:54671) resolves a 16x16 partition symbol with NO | ||
| 511 | +refuse_invalid_subsize((16, 16)) anywhere after it -- a subsize libaom refuses | ||
| 512 | +can walk straight through (r6 shipped exactly this on the inter-frame 16x16 level) | ||
| 513 | +``` | ||
| 514 | + | ||
| 515 | +This is why `EC_AV1_SUBSIZE_ARM_TRACE` hand-listing three arms was not enough: | ||
| 516 | +its site list was itself a hand-maintained list, and r6's "no unguarded arm" | ||
| 517 | +reading was a limit of the instrument. The scan above cannot have a hole of that | ||
| 518 | +kind — a new level appears as a new binding and the test fails until it is | ||
| 519 | +guarded. | ||
| 520 | + | ||
| 521 | +### 9.2 Residue, corrected | ||
| 522 | + | ||
| 523 | +**At least three sites, not one.** `decode_rect4_16_intrabc` is **not** the only | ||
| 524 | +exception any more, and the earlier "still open: none" was wrong: | ||
| 525 | + | ||
| 526 | +| residue | status | | ||
| 527 | +|---|---| | ||
| 528 | +| inter-64 edge arm (`part64=2` via `(false, true)`) | **fixed in r7** | | ||
| 529 | +| inter-16 level's two shapes (`BLOCK_8X16`, `BLOCK_4X16`) | **fixed in r7** | | ||
| 530 | +| `decode_rect4_16_intrabc` | **out of scope and NOT audited** — another lane's charter | | ||
| 531 | + | ||
| 532 | +Beyond those, the structural scan reports every `partition_w*` resolution in the | ||
| 533 | +file guarded at its own level, so no further subsize-selecting dispatch in the | ||
| 534 | +paths this lane owns lacks a guard above it. That is a statement about the | ||
| 535 | +`partition_w*` resolutions; a dispatch that selects a subsize WITHOUT reading a | ||
| 536 | +`partition_w*` symbol would not be caught by it, and I did not find one, but I am | ||
| 537 | +not claiming the scan proves none exists. | ||
| 538 | + | ||
| 539 | +--- | ||
| 540 | + | ||
| 541 | +## 10. r8 — the test claimed more than it proved | ||
| 542 | + | ||
| 543 | +Maine's r7 read found three honesty gaps in the structural gate. All three were | ||
| 544 | +in what the test SAID, not what the decode does; none changed a decode path. | ||
| 545 | + | ||
| 546 | +1. **"BEFORE the first dispatch on the variable" was in the comment only.** r7 | ||
| 547 | + checked that a guard for the level appears somewhere in the next 220 lines. | ||
| 548 | + r8 IMPLEMENTS the bound: where the window contains a `match part…` dispatch, | ||
| 549 | + the guard must precede it. | ||
| 550 | +2. **The binding pattern was formatting-sensitive and failed silently.** A | ||
| 551 | + resolution whose `dec.symbol(` is wrapped onto the next line used to vanish | ||
| 552 | + from the list with nothing red. r8 reads the level and the symbol read from a | ||
| 553 | + two-line window, so a wrapped site resolves instead of disappearing, and the | ||
| 554 | + remaining cross-check is over **levels**, which a reformat cannot lose: every | ||
| 555 | + `partition_w<N>[` in the file must appear among the resolutions found. | ||
| 556 | +3. **`var` was parsed as the text BEFORE `let `**, so it was always empty and the | ||
| 557 | + diagnostic read `(decode.rs:1234) resolves…` with no name — exactly where the | ||
| 558 | + name matters. r8 takes the token after `let `. | ||
| 559 | + | ||
| 560 | +### 10.1 Coverage, stated so a reader can tell it from a floor | ||
| 561 | + | ||
| 562 | +**Today: 10 partition-symbol resolutions, 13 `refuse_invalid_subsize((` | ||
| 563 | +occurrences**, of which 9 are guards at 9 resolutions and the rest are the | ||
| 564 | +function definition, its doc comment and this test's own example strings. | ||
| 565 | + | ||
| 566 | +What is asserted, exactly: | ||
| 567 | + | ||
| 568 | +* every `partition_w<N>[` level in the file appears among the resolutions found — | ||
| 569 | + a new level cannot be added without a guard check; | ||
| 570 | +* each resolution is followed, within 220 lines, by a | ||
| 571 | + `refuse_invalid_subsize((N, N), …)` for its own level, matched on the LEVEL | ||
| 572 | + rather than the variable (the symbol is often bound to a short-lived `p` and | ||
| 573 | + dispatched by an outer `part64`); | ||
| 574 | +* where that window contains a `match part…` dispatch, the guard precedes it; | ||
| 575 | +* no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. | ||
| 576 | + | ||
| 577 | +What is NOT claimed: the test does not prove a guard is at the exact dispatch | ||
| 578 | +point — the window is a window. That limit is why the AB-arm invariant is a | ||
| 579 | +separate assertion and why `EC_AV1_SUBSIZE_GUARD_TRACE` records what each site | ||
| 580 | +really sees over the corpus. | ||
| 581 | + | ||
| 582 | +Two mutations, both red: | ||
| 583 | + | ||
| 584 | +``` | ||
| 585 | +$ # delete the inter-16 guard | ||
| 586 | +part16 (decode.rs:36465) resolves a 16x16 partition symbol with NO | ||
| 587 | +refuse_invalid_subsize((16, 16)) within 220 lines after it | ||
| 588 | + | ||
| 589 | +$ # move the inter-64 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm | ||
| 590 | +p (decode.rs:54137) resolves a 64x64 partition symbol with NO | ||
| 591 | +refuse_invalid_subsize((64, 64)) within 220 lines after it | ||
| 592 | +``` | ||
| 593 | + | ||
| 594 | +--- | ||
| 595 | + | ||
| 596 | +## 11. r9 — a real residue site, and a checker that was weaker than its comment | ||
| 597 | + | ||
| 598 | +The third pass confirmed r7's decode path (all 9 guard sites top-level, seeing | ||
| 599 | +every value; the corpus census reproducing exactly; all 20 genuine 4:2:2 fixtures | ||
| 600 | +decoding). The FAIL was in the checker plus one real residue. | ||
| 601 | + | ||
| 602 | +### 11.1 The residue: a second key-frame 8x8 resolution, unguarded | ||
| 603 | + | ||
| 604 | +`decode.rs:37115` is a key-frame `partition_w8` resolution dispatching | ||
| 605 | +`decode_leaf_rect8` on a raw `part8` with no `refuse_invalid_subsize` anywhere | ||
| 606 | +after it — `BLOCK_4X8` at 4:2:2, the shape r5 and r6 each flagged. Guarded. The | ||
| 607 | +fixed scan then immediately found a **second** one at `36876`, which no earlier | ||
| 608 | +round had seen. Both are residue rather than live pixels: neither is corpus- | ||
| 609 | +reachable at ss (1,0) today. Guarded anyway. | ||
| 610 | + | ||
| 611 | +### 11.2 Three checker gaps, all closed | ||
| 612 | + | ||
| 613 | +1. **The scan's window started AT the `partition_w` line**, so a binding whose | ||
| 614 | + `let` is on the line above was dropped — which is exactly why `37115` was | ||
| 615 | + invisible. r9 searches the line BEFORE as well. | ||
| 616 | +2. **The level cross-check was per-level PRESENCE**, so a second unguarded site | ||
| 617 | + at an already covered level passed — which is how `37115` survived with level 8 | ||
| 618 | + covered by the inter-8 site. r9 keeps presence as presence and says so, and | ||
| 619 | + adds the exact guard-vs-resolution count. | ||
| 620 | +3. **`sites.len() >= 9` was a floor the tree already satisfied with 10.** Replaced | ||
| 621 | + with a count derived from the scan: the decode body has **11 guard sites** and | ||
| 622 | + the scan finds **10 resolutions** — the eleventh guard is the inter-frame 128 | ||
| 623 | + one at `53985`, whose resolution lives in the shared `read_sb128_root` and so | ||
| 624 | + has no resolution of its own here. That is exactly the redundancy the `>=` | ||
| 625 | + exists to allow, so the counts are reported as 11 guards against 10 | ||
| 626 | + resolutions and the reason is named. | ||
| 627 | + | ||
| 628 | +Plus the one the refutation demonstrated green: the AB-arm tracker **self-cleared | ||
| 629 | +on the `{` line**, because that line carries the same indent as the `if` — moving | ||
| 630 | +the kf-32 guard back inside an arm stayed GREEN. r9 arms at the condition, | ||
| 631 | +*enters* the body one level deeper, and clears only after having been inside it. | ||
| 632 | +That mutation now reds: | ||
| 633 | + | ||
| 634 | +``` | ||
| 635 | +$ # move the kf-32 guard inside a PARTITION_HORZ_A => arm | ||
| 636 | +p (decode.rs:36332) resolves a 32x32 partition symbol with NO | ||
| 637 | +refuse_invalid_subsize((32, 32)) within 220 lines after it | ||
| 638 | +``` | ||
| 639 | + | ||
| 640 | +### 11.3 The occurrence count, re-derived per line | ||
| 641 | + | ||
| 642 | +`refuse_invalid_subsize((` appears **18 times in `decode.rs`**, and the breakdown | ||
| 643 | +that sums is **11 + 5 + 2**: | ||
| 644 | + | ||
| 645 | +* **11 guard call sites** in the decode body — 35588, 36278, 36406, 36472, 36882, | ||
| 646 | + 37132, 53985, 54222, 54606, 54752, 55164; | ||
| 647 | +* **5** in this test's own string literals and comparisons — the four named in the | ||
| 648 | + assertions plus the multi-line assert string at 56835; | ||
| 649 | +* **2** in doc comments. | ||
| 650 | + | ||
| 651 | +The definition's own signature line does not match `((` at all. Main's line-grep | ||
| 652 | +count of 13 was taken at r7 and the refutation's 15 at r9, both before the r9 kf-w8 | ||
| 653 | +guards; 18 is what the tree carries now, counted by call shape | ||
| 654 | +(`l.trim_start().starts_with(…)`) so a multi-line assert string mentioning the | ||
| 655 | +function is not counted. The scan finds **10** resolutions against those **11** | ||
| 656 | +guards — the inter-128 guard at 53985 has no resolution of its own because | ||
| 657 | +`read_sb128_root` is shared. | ||
| 658 | + | ||
| 659 | +### 11.4 What is still not claimed | ||
| 660 | + | ||
| 661 | +The guard-vs-resolution cross-check is `>=`, not `==`: the scan sees 10 resolutions | ||
| 662 | +against 11 guards today, and a hard equality between two numbers the scan itself | ||
| 663 | +computes is a claim about the scanner, not about coverage. What reds is a | ||
| 664 | +resolution with no guard — on its own line, naming the variable — and a guard | ||
| 665 | +sitting inside an AB arm. A redundant guard with no resolution behind it is | ||
| 666 | +harmless and is not treated as a defect. | ||
| 667 | + | ||
| 668 | +**And the two cross-checks are weaker than they look.** Cross-check 1 is level | ||
| 669 | +PRESENCE only. Cross-check 2 is `>=`. So a **second unguarded site at an | ||
| 670 | +already-covered level is caught only by the per-site 220-line window** — which is | ||
| 671 | +a window, not a dispatch bound. Stated rather than left for a reader to infer. | ||
| 672 | + | ||
| 673 | +### 11.5 r10: the AB-arm tracker, again | ||
| 674 | + | ||
| 675 | +r9's tracker was open for exactly one line: armed at the condition (indent 44, | ||
| 676 | +body 48), the wrapped `.contains(&part16)` at indent 48 set `entered = true`, and | ||
| 677 | +then the arm's own `{` — at the **opener's** indent 44, not the body's — hit | ||
| 678 | +`ind < body` and cleared it. Every statement in the arm body was invisible, and | ||
| 679 | +the mutation that moves a guard INSIDE an arm stayed GREEN at r8 *and* r9. r10 | ||
| 680 | +skips a line whose trimmed text is exactly `{` when deciding to enter or clear. | ||
| 681 | +The mutation now reds with the r5 diagnostic: | ||
| 682 | + | ||
| 683 | +``` | ||
| 684 | +$ # move the kf-16 guard inside a PARTITION_HORZ_A..=PARTITION_VERT_B arm | ||
| 685 | +decode.rs:36539 puts a refuse_invalid_subsize inside a | ||
| 686 | +PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the offending | ||
| 687 | +values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which that arm can | ||
| 688 | +never observe -- r5's defect | ||
| 689 | +``` | ||
| 690 | + | ||
| 691 | +Also in r10: the bound-variable lookup scans **backwards** and takes the nearest | ||
| 692 | +`let` whose binding is the one followed by the symbol read. It used to take the | ||
| 693 | +first `let` upward, which could name an unrelated binding (`ec_dbg_pre`) instead | ||
| 694 | +of the partition symbol. | ||
| 695 | + | ||
| 696 | +**No decode-path change in r10** — the four passes found no defect in it. | ||
| 697 | + | ||
scripts/cmp422-ffmpeg.pymodified+82 -11
| @@ -77,16 +77,32 @@ def split(raw, sizes, fsz, cell): | |||
| 77 | return [raw[i * fsz:(i + 1) * fsz] for i in range(len(raw) // fsz)] | 77 | return [raw[i * fsz:(i + 1) * fsz] for i in range(len(raw) // fsz)] |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | -def _matchings(cands, disp_n, cap=64): | 80 | +def _matchings(cands, disp_n, cap=64, node_cap=4_000_000): |
| 81 | """Every way to assign each decode frame either a distinct display partner | 81 | """Every way to assign each decode frame either a distinct display partner |
| 82 | or the hidden role, covering the display side exactly. Enumerated, not | 82 | or the hidden role, covering the display side exactly. Enumerated, not |
| 83 | guessed: a duplicated picture can make the assignment genuinely ambiguous, | 83 | guessed: a duplicated picture can make the assignment genuinely ambiguous, |
| 84 | - and the caller then has to show the ambiguity does not change the answer.""" | 84 | + and the caller then has to show the ambiguity does not change the answer. |
| 85 | + | ||
| 86 | + Two bounds, both learned the hard way: without the feasibility prune, an | ||
| 87 | + instance whose candidate lists cannot cover the display side explores the | ||
| 88 | + whole 2**frames tree before returning empty (that is what made three | ||
| 89 | + 43-frame cells burn a 300 s cap with 15 minutes of user CPU and never | ||
| 90 | + finish), and without a node cap a pathological instance would hang the | ||
| 91 | + comparator instead of reporting.""" | ||
| 85 | sols = [] | 92 | sols = [] |
| 93 | + nodes = 0 | ||
| 86 | 94 | ||
| 87 | def dfs(i, used, acc, hid): | 95 | def dfs(i, used, acc, hid): |
| 96 | + nonlocal nodes | ||
| 97 | + nodes += 1 | ||
| 98 | + if nodes > node_cap: | ||
| 99 | + raise SystemExit(f"the decode->display assignment search exceeded {node_cap} nodes " | ||
| 100 | + f"at frame {i} of {len(cands)} ({disp_n} display frames) -- this " | ||
| 101 | + f"instance is not enumerable; report it rather than hang") | ||
| 88 | if len(sols) >= cap: | 102 | if len(sols) >= cap: |
| 89 | return | 103 | return |
| 104 | + if disp_n - len(used) > len(cands) - i: | ||
| 105 | + return # not enough decode frames left to cover the display side | ||
| 90 | if i == len(cands): | 106 | if i == len(cands): |
| 91 | if len(used) == disp_n: | 107 | if len(used) == disp_n: |
| 92 | sols.append((dict(acc), list(hid))) | 108 | sols.append((dict(acc), list(hid))) |
| @@ -181,15 +197,70 @@ def compare(cell, ours_prefix, disp, w, h, ss_x, ss_y, depth, want_hidden=None): | |||
| 181 | per_dec.append(fcount) | 197 | per_dec.append(fcount) |
| 182 | return tot, per_disp, per_dec, first, bb_all | 198 | return tot, per_disp, per_dec, first, bb_all |
| 183 | 199 | ||
| 184 | - measured = [measure(m, h) for m, h in sols] | 200 | + def xor_plane_counts(a, b): |
| 185 | - totals = {tuple(t[0]) for t in measured} | 201 | + """Per-plane differing-SAMPLE counts at 8-bit, at C speed: XOR the two |
| 186 | - if len(totals) > 1: | 202 | + planes as big ints, then count non-zero bytes per plane. Equivalent to |
| 187 | - raise SystemExit(f"{cell}: the decode->display assignment is AMBIGUOUS " | 203 | + the per-sample loop above, and the only reason a 43-frame cell with 64 |
| 188 | - f"({len(sols)} solutions) and they DISAGREE on the counts " | 204 | + candidate assignments used to cost half an hour.""" |
| 189 | - f"{sorted(totals)} -- pick the identity source explicitly, " | 205 | + z = int.from_bytes(a, "big") ^ int.from_bytes(b, "big") |
| 190 | - f"this instrument will not choose for you") | 206 | + zb = z.to_bytes(len(a), "big") |
| 191 | - tot, per_disp, per_dec, first, bbox = measured[0] | 207 | + out, off = [], 0 |
| 192 | - mapping, hidden = sols[0] | 208 | + for sz in sizes: |
| 209 | + seg = zb[off:off + sz] | ||
| 210 | + off += sz | ||
| 211 | + out.append(len(seg) - seg.count(0)) | ||
| 212 | + return out | ||
| 213 | + | ||
| 214 | + if bps == 1: | ||
| 215 | + pair_cache = {} | ||
| 216 | + | ||
| 217 | + def pair_total(oi, di): | ||
| 218 | + v = pair_cache.get((oi, di)) | ||
| 219 | + if v is None: | ||
| 220 | + v = xor_plane_counts(ours[oi], disp[di]) | ||
| 221 | + pair_cache[(oi, di)] = v | ||
| 222 | + return v | ||
| 223 | + | ||
| 224 | + sol_totals = [] | ||
| 225 | + for m, _h in sols: | ||
| 226 | + t = [0, 0, 0] | ||
| 227 | + for oi, di in m.items(): | ||
| 228 | + p = pair_total(oi, di) | ||
| 229 | + t[0] += p[0] | ||
| 230 | + t[1] += p[1] | ||
| 231 | + t[2] += p[2] | ||
| 232 | + sol_totals.append(tuple(t)) | ||
| 233 | + if len(set(sol_totals)) > 1: | ||
| 234 | + raise SystemExit(f"{cell}: the decode->display assignment is AMBIGUOUS " | ||
| 235 | + f"({len(sols)} solutions) and they DISAGREE on the counts " | ||
| 236 | + f"{sorted(set(sol_totals))} -- pick the identity source explicitly, " | ||
| 237 | + f"this instrument will not choose for you") | ||
| 238 | + tot = list(sol_totals[0]) | ||
| 239 | + mapping, hidden = sols[0] | ||
| 240 | + if tot == [0, 0, 0]: | ||
| 241 | + per_disp = [[0, 0, 0] for _ in disp] | ||
| 242 | + per_dec = [None if oi in hidden else [0, 0, 0] for oi in range(len(ours))] | ||
| 243 | + first, bbox = None, [[None, None, None, None] for _ in range(3)] | ||
| 244 | + else: | ||
| 245 | + tot, per_disp, per_dec, first, bbox = measure(mapping, hidden) | ||
| 246 | + else: | ||
| 247 | + # 16-bit planes: the sample loop below is the only path today. | ||
| 248 | + if all(all(ours[oi] == disp[di] for oi, di in m.items()) for m, h in sols): | ||
| 249 | + hidden0 = sols[0][1] | ||
| 250 | + measured = [([0, 0, 0], [[0, 0, 0] for _ in disp], | ||
| 251 | + [None if oi in hidden0 else [0, 0, 0] for oi in range(len(ours))], | ||
| 252 | + None, [[None, None, None, None] for _ in range(3)])] | ||
| 253 | + measured *= len(sols) | ||
| 254 | + else: | ||
| 255 | + measured = [measure(m, h) for m, h in sols] | ||
| 256 | + totals = {tuple(t[0]) for t in measured} | ||
| 257 | + if len(totals) > 1: | ||
| 258 | + raise SystemExit(f"{cell}: the decode->display assignment is AMBIGUOUS " | ||
| 259 | + f"({len(sols)} solutions) and they DISAGREE on the counts " | ||
| 260 | + f"{sorted(totals)} -- pick the identity source explicitly, " | ||
| 261 | + f"this instrument will not choose for you") | ||
| 262 | + tot, per_disp, per_dec, first, bbox = measured[0] | ||
| 263 | + mapping, hidden = sols[0] | ||
| 193 | if want_hidden is not None and len(hidden) != want_hidden: | 264 | if want_hidden is not None and len(hidden) != want_hidden: |
| 194 | raise SystemExit(f"{cell}: {len(hidden)} hidden decode frame(s) {hidden}, " | 265 | raise SystemExit(f"{cell}: {len(hidden)} hidden decode frame(s) {hidden}, " |
| 195 | f"expected {want_hidden} -- the frame-count claim changed") | 266 | f"expected {want_hidden} -- the frame-count claim changed") |
scripts/run422-ffmpeg.pymodified+1 -1
| @@ -9,7 +9,7 @@ import sys | |||
| 9 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | 9 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 10 | import cmpff # noqa: E402 | 10 | import cmpff # noqa: E402 |
| 11 | 11 | ||
| 12 | -PROBE = "/home/user/.cache/tgt/av1422seed/debug/examples/decode_probe" | 12 | +PROBE = "/home/user/.cache/probes/decode_probe-main-8d6998d7" |
| 13 | WORK = "/home/user/.cache/seed422" | 13 | WORK = "/home/user/.cache/seed422" |
| 14 | 14 | ||
| 15 | 15 | ||