forge
Explore
Log in

Don't you dare go Hollow

Prove four refusals by enumeration and delete the dead palette (Y) guard

Browse files at this commit

2937d256e60c38b54126c37736ca9049c499c131Ahmet Kaan GümüşParent: 7407710
  • test
    • prove four refusals by enumeration and delete the dead palette (Y) guard
Show full message
test(av1): prove four refusals by enumeration and delete the dead palette (Y) guard

The two `decode_rect_split` shape refusals (rect chroma tables, split intra
strip transform unit) are enumerated over their five callers' footprint domain
at every tx depth, against both `match` tables read out of decode.rs itself.
The 128-root CfL/filter-intra/palette guard is enumerated over its four
symbols' own size gates. The palette (Y) guard was dead -- all eight
`read_intra_mode`/`read_intra_mode_rect` call sites hand the reader a real
ctx/cache pair -- so both arms are deleted and an audit keeps the invariant.
The superblock-strip palette refusal is registered as a witnessed capability
gap: its gate already hard-asserts a real screen stream reaches it by name.

refusal inventory: 36 refusals / 28 proven -> 35 refusals / 32 proven.
crates/ec-av1/src/decode.rsmodified+0 -10
@@ -7088,11 +7088,6 @@ fn read_intra_mode_rect(
7088 let use_palette_y =7088 let use_palette_y =
7089 mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;7089 mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;
7090 if use_palette_y {7090 if use_palette_y {
7091- if palette.is_none() {
7092- return Err(unsupported(
7093- "a block that actually uses a palette (Y) -- reconstruction is out of scope",
7094- ));
7095- }
7096 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);7091 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
7097 let colors = read_palette_colors_y(dec, n, cache, fctx);7092 let colors = read_palette_colors_y(dec, n, cache, fctx);
7098 palette_y_pending = Some((n, colors));7093 palette_y_pending = Some((n, colors));
@@ -11166,11 +11161,6 @@ fn read_intra_mode(
11166 eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32);11161 eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32);
11167 }11162 }
11168 if use_palette_y {11163 if use_palette_y {
11169- if palette.is_none() {
11170- return Err(unsupported(
11171- "a block that actually uses a palette (Y) -- reconstruction is out of scope",
11172- ));
11173- }
11174 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);11164 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
11175 if trace {11165 if trace {
11176 let (rng, _) = dec.debug_state();11166 let (rng, _) = dec.debug_state();
crates/ec-av1/src/refusal_inventory.rsmodified+312 -4
@@ -50,10 +50,12 @@ const REFUSALS: &[&str] = &[
50 // 8x8 LEAF inside an inter frame (this round, gate50 // 8x8 LEAF inside an inter frame (this round, gate
51 // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`),51 // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`),
52 // which is why the (UV) string is gone from the decoder entirely -- the52 // which is why the (UV) string is gone from the decoder entirely -- the
53- // leaf was its only site. The (Y) one survives ONLY as the defensive53+ // leaf was its only site. The (Y) one survived as the defensive
54- // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`;54+ // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`
55- // every caller now passes a real ctx/cache pair, so no stream reaches it.55+ // until lane-t900 r33 DELETED both arms: all eight call sites hand the
56- "a block that actually uses a palette (Y) -- reconstruction is out of scope",56+ // reader a real ctx/cache pair, so no stream could reach either (audit
57+ // `every_read_intra_mode_call_site_hands_the_reader_a_palette_cache`,
58+ // which keeps that invariant now the refusal is gone).
57 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",59 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
58 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",60 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
59 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",61 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
@@ -349,6 +351,37 @@ const PROVEN: &[(&str, &str)] = &[
349 // `real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact`351 // `real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact`
350 // decodes both lifted shapes byte-exact vs ffmpeg, and the census now352 // decodes both lifted shapes byte-exact vs ffmpeg, and the census now
351 // asserts none of the three strings comes back.353 // asserts none of the three strings comes back.
354+ // lane-t900 r33, enumeration: the five callers of `decode_rect_split` pass
355+ // the ten rect footprints with `8 <= min` and `max <= 64`, and every one of
356+ // them has a chroma table and -- at every tx depth -- a luma arm. The two
357+ // shape classes that would miss one (a 128-sided half, a sub-8 strip) have
358+ // readers that are not among those callers.
359+ (
360+ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
361+ "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table",
362+ ),
363+ (
364+ "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
365+ "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table",
366+ ),
367+ // lane-t900 r33, enumeration: each of the four symbols this guard tests is
368+ // read under a size gate that no 128-pixel side passes (the call site's
369+ // literal `cfl=false`, `filter_intra_size_class_rect`'s table, and
370+ // `palette_bsize_ctx_wh`'s bound).
371+ (
372+ "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)",
373+ "no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol",
374+ ),
375+ // lane-t900 r33, WITNESS of a capability gap: the refusal is REACHED by
376+ // real `--tune-content=screen --enable-palette=1` streams, counted
377+ // (`palette_sb_strip_hits`) and hard-asserted non-zero by its gate, which
378+ // also decodes the arms that do not reach it pixel-exact. lane-pal8 r1
379+ // measured the lift and it mismatches whole-frame, so the string names a
380+ // real shape a real encoder writes -- an open capability, not a claim.
381+ (
382+ "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
383+ "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact",
384+ ),
352 (385 (
353 "a reference picture whose height does not match this frame's own true size",386 "a reference picture whose height does not match this frame's own true size",
354 "an_inter_frame_shorter_than_its_reference_is_refused_by_name",387 "an_inter_frame_shorter_than_its_reference_is_refused_by_name",
@@ -1045,6 +1078,281 @@ mod tests {
1045 }1078 }
1046 }1079 }
1047 1080
1081+ /// lane-t900 r33, ENUMERATION for the two [`decode_rect_split`] refusals
1082+ /// ("a coded HORZ/VERT strip whose chroma transform has no rect
1083+ /// coefficient tables here" and "a split intra strip whose transform unit
1084+ /// is {tx_w}x{tx_h}").
1085+ ///
1086+ /// Both guard shape lookups inside one function, so the proof is one
1087+ /// enumeration: the footprints that function is CALLED with, walked
1088+ /// through `depth_to_tx_wh` at every depth, against the two `match`
1089+ /// tables read out of `decode.rs` itself (class
1090+ /// `table-and-reader-move-together` -- a table edit invalidates this test
1091+ /// rather than sneaking past it).
1092+ ///
1093+ /// The footprint domain is the five callers' own: `decode_block_rect`
1094+ /// (32-level 2:1), `decode_block_rect4` (32-level 1:4), `decode_leaf_rect`
1095+ /// (16-level 2:1), `decode_block_rect64` (64-level 2:1 and 1:4) and
1096+ /// `decode_intra_rect_in_inter`, whose reachable shapes are the ten
1097+ /// rectangular census shapes with `8 <= min` and `max <= 64` (already
1098+ /// pinned by `every_intra_in_inter_shape_the_census_lists_has_a_size_group_row`).
1099+ /// The two shape classes that would MISS a table -- a 128-sided half
1100+ /// (chroma 64x32) and a sub-8 strip (16x4 -> chroma 8x2) -- are excluded
1101+ /// structurally: their readers, `decode_block_128rect` and
1102+ /// `decode_rect4_16_strip`, are not among the callers, which this test
1103+ /// asserts by locating every `decode_rect_split(` call in its enclosing
1104+ /// function.
1105+ #[test]
1106+ fn every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table() {
1107+ let src = include_str!("decode.rs");
1108+
1109+ // (1) The caller set. Each call's enclosing function is the last
1110+ // top-level `fn` before it.
1111+ let fn_starts: Vec<(usize, String)> = src
1112+ .match_indices("\nfn ")
1113+ .map(|(i, _)| {
1114+ let rest = &src[i + 4..];
1115+ let name = rest[..rest.find('(').unwrap_or(0)].to_string();
1116+ (i, name)
1117+ })
1118+ .collect();
1119+ let mut callers: BTreeSet<String> = BTreeSet::new();
1120+ for (at, _) in src.match_indices("decode_rect_split(") {
1121+ let enclosing = fn_starts
1122+ .iter()
1123+ .filter(|(i, _)| *i < at)
1124+ .next_back()
1125+ .expect("a decode_rect_split call outside any function");
1126+ if enclosing.1 != "decode_rect_split" {
1127+ callers.insert(enclosing.1.clone());
1128+ }
1129+ }
1130+ let expected: BTreeSet<String> = [
1131+ "decode_block_rect",
1132+ "decode_block_rect4",
1133+ "decode_block_rect64",
1134+ "decode_intra_rect_in_inter",
1135+ "decode_leaf_rect",
1136+ ]
1137+ .iter()
1138+ .map(|s| s.to_string())
1139+ .collect();
1140+ assert_eq!(
1141+ callers, expected,
1142+ "the set of functions that call decode_rect_split changed -- re-derive the \
1143+ footprint domain below from the new caller (a 128-sided or sub-8 caller makes \
1144+ both refusals live)"
1145+ );
1146+
1147+ // (2) The walk, asserted against its own source before it is applied.
1148+ const WALK: &str = " let (mut w, mut h) = (bw.min(64), bh.min(64));\n \
1149+ for _ in 0..depth {\n match w.cmp(&h) {\n \
1150+ std::cmp::Ordering::Greater => w /= 2,\n \
1151+ std::cmp::Ordering::Less => h /= 2,\n \
1152+ std::cmp::Ordering::Equal => {\n w /= 2;\n \
1153+ h /= 2;\n }\n }\n }";
1154+ assert_eq!(
1155+ src.matches(WALK).count(),
1156+ 1,
1157+ "depth_to_tx_wh's walk is no longer spelled the way this enumeration mirrors it"
1158+ );
1159+ let depth_to_tx_wh = |bw: usize, bh: usize, depth: usize| {
1160+ let (mut w, mut h) = (bw.min(64), bh.min(64));
1161+ for _ in 0..depth {
1162+ match w.cmp(&h) {
1163+ std::cmp::Ordering::Greater => w /= 2,
1164+ std::cmp::Ordering::Less => h /= 2,
1165+ std::cmp::Ordering::Equal => {
1166+ w /= 2;
1167+ h /= 2;
1168+ }
1169+ }
1170+ }
1171+ (w, h)
1172+ };
1173+
1174+ // (3) The two tables, read out of decode_rect_split's own text: every
1175+ // `(w, h) =>` / `(w, h) |` match arm head between the table's `let`
1176+ // and the guard that follows it.
1177+ let body_at = src.find("fn decode_rect_split(").expect("decode_rect_split is gone");
1178+ let body = &src[body_at..];
1179+ let slice = |from: &str, to: &str| -> &str {
1180+ let a = body.find(from).unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split"));
1181+ let b = body[a..].find(to).unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split"));
1182+ &body[a..a + b]
1183+ };
1184+ let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> {
1185+ let mut out = BTreeSet::new();
1186+ let bytes = text.as_bytes();
1187+ for (i, _) in text.match_indices('(') {
1188+ let mut j = i + 1;
1189+ let mut w = 0usize;
1190+ while j < bytes.len() && bytes[j].is_ascii_digit() {
1191+ w = w * 10 + usize::from(bytes[j] - b'0');
1192+ j += 1;
1193+ }
1194+ if j == i + 1 || !text[j..].starts_with(", ") {
1195+ continue;
1196+ }
1197+ j += 2;
1198+ let mut h = 0usize;
1199+ let start_h = j;
1200+ while j < bytes.len() && bytes[j].is_ascii_digit() {
1201+ h = h * 10 + usize::from(bytes[j] - b'0');
1202+ j += 1;
1203+ }
1204+ if j == start_h || !text[j..].starts_with(')') {
1205+ continue;
1206+ }
1207+ // Only an arm HEAD counts, never a `(32, 8)` inside prose.
1208+ let after = text[j + 1..].trim_start();
1209+ if after.starts_with("=>") || after.starts_with('|') {
1210+ out.insert((w, h));
1211+ }
1212+ }
1213+ out
1214+ };
1215+ let chroma = arm_shapes(slice("let chroma: Option<(TxbSet", "if !m.skip {"));
1216+ let luma = arm_shapes(slice("let luma_rect: Option<(TxbSet", "no luma \\"));
1217+ assert!(
1218+ chroma.len() >= 6 && luma.len() >= 6,
1219+ "the tables parsed to {} chroma / {} luma shapes -- the parse, not the decoder, \
1220+ is what this would be measuring",
1221+ chroma.len(),
1222+ luma.len()
1223+ );
1224+
1225+ // (4) The enumeration itself.
1226+ let mut checked = 0u32;
1227+ for wl in 3..=6u32 {
1228+ for hl in 3..=6u32 {
1229+ let (bw, bh) = (1usize << wl, 1usize << hl);
1230+ let ratio = bw.max(bh) / bw.min(bh);
1231+ if ratio != 2 && ratio != 4 {
1232+ continue;
1233+ }
1234+ assert!(
1235+ chroma.contains(&(bw / 2, bh / 2)),
1236+ "a {bw}x{bh} strip's {}x{} chroma transform has no rect table -- the \
1237+ chroma refusal is LIVE for a shape a caller codes",
1238+ bw / 2,
1239+ bh / 2
1240+ );
1241+ // Every depth: once the walk reaches a square it stays square,
1242+ // so this covers any tx_depth a header can code.
1243+ for depth in 1..=4 {
1244+ let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
1245+ assert!(
1246+ tx_w == tx_h || luma.contains(&(tx_w, tx_h)),
1247+ "a {bw}x{bh} strip at depth {depth} resolves to a {tx_w}x{tx_h} \
1248+ transform unit, which has no luma arm -- that refusal is LIVE"
1249+ );
1250+ checked += 1;
1251+ }
1252+ }
1253+ }
1254+ assert_eq!(checked, 40, "the strip domain is not the ten rect shapes x four depths");
1255+ }
1256+
1257+ /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a
1258+ /// 128-root HORZ/VERT intra block".
1259+ ///
1260+ /// The guard fires when any of four symbols came back `Some` from
1261+ /// `read_intra_mode_rect` on a 128x64/64x128 half. Each of the four is
1262+ /// read under a size gate, and none of those gates admits a 128-pixel
1263+ /// side:
1264+ ///
1265+ /// * `cfl_alpha` -- read only under the `cfl` PARAMETER, and the 128-root
1266+ /// call site passes the literal `false`;
1267+ /// * `use_filter_intra` -- read only when `filter_intra_size_class_rect`
1268+ /// is `Some`, whose table has no arm with a 128 side and whose square
1269+ /// fallback (`filter_intra_size_class`) caps at 32
1270+ /// (`av1_filter_intra_allowed_bsize`);
1271+ /// * `palette_y_mode` / `palette_uv_mode` -- both inside the
1272+ /// `palette_bsize_ctx_wh` block already enumerated by
1273+ /// [`no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax`].
1274+ #[test]
1275+ fn no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol() {
1276+ let src = include_str!("decode.rs");
1277+ // The 128-root call site's own `cfl` argument, with the comment that
1278+ // explains it -- the two lines are matched together so that reordering
1279+ // the arguments cannot leave this test pointing at another `false`.
1280+ const CFL_OFF_AT_128: &str = " // `is_cfl_allowed` caps CFL at 32x32: `uv_mode` comes off the\n \
1281+ // 13-symbol no-CFL CDF here, never the 14-symbol one.\n false,";
1282+ assert_eq!(
1283+ src.matches(CFL_OFF_AT_128).count(),
1284+ 1,
1285+ "the 128-root call site no longer passes cfl=false -- a CfL alpha can reach the \
1286+ guard, so this enumeration proves nothing"
1287+ );
1288+ // The filter-intra table: every arm head, plus the square fallback.
1289+ let fi_at = src
1290+ .find("fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> {")
1291+ .expect("filter_intra_size_class_rect is gone");
1292+ let fi_body = &src[fi_at..fi_at + src[fi_at..].find("\n}\n").expect("unterminated fn")];
1293+ assert!(
1294+ !fi_body.contains("128"),
1295+ "filter_intra_size_class_rect grew an arm naming a 128 side"
1296+ );
1297+ assert!(
1298+ fi_body.contains("_ if bw == bh => filter_intra_size_class(bw),")
1299+ && fi_body.contains("_ => None,"),
1300+ "filter_intra_size_class_rect's fallbacks changed shape"
1301+ );
1302+ let sq_at = src
1303+ .find("fn filter_intra_size_class(side: usize) -> Option<usize> {")
1304+ .expect("filter_intra_size_class is gone");
1305+ let sq_body = &src[sq_at..sq_at + src[sq_at..].find("\n}\n").expect("unterminated fn")];
1306+ assert!(
1307+ !sq_body.contains("128") && !sq_body.contains("64"),
1308+ "filter_intra_size_class admits a side above 32 -- av1_filter_intra_allowed_bsize \
1309+ does not, so re-derive this proof"
1310+ );
1311+ // And palette, at the two shapes the refusal names.
1312+ assert!(
1313+ src.contains("if bw > 64 || bh > 64 || bw * bh < 64 {"),
1314+ "palette_bsize_ctx_wh's bound moved -- see \
1315+ no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax"
1316+ );
1317+ for (bw, bh) in [(128usize, 64usize), (64, 128)] {
1318+ assert!(bw > 64 || bh > 64, "{bw}x{bh} is not a 128-root half");
1319+ }
1320+ }
1321+
1322+ /// lane-t900 r33, STRUCTURAL AUDIT behind the DELETION of "a block that
1323+ /// actually uses a palette (Y) -- reconstruction is out of scope".
1324+ ///
1325+ /// That refusal was the `palette.is_none()` arm of `read_intra_mode` and
1326+ /// `read_intra_mode_rect`: a stream reached it only if a CALLER read the
1327+ /// palette syntax without handing the reader a neighbour ctx/cache pair.
1328+ /// Every one of the eight call sites passes `Some((palette_ctx,
1329+ /// &palette_cache))`, so no stream could reach either arm and both are
1330+ /// gone from `decode.rs`. This test keeps the invariant the deletion rests
1331+ /// on: a future caller that passes `None` fails here rather than decoding
1332+ /// a palette off an empty colour cache.
1333+ #[test]
1334+ fn every_read_intra_mode_call_site_hands_the_reader_a_palette_cache() {
1335+ let src = include_str!("decode.rs");
1336+ let mut sites = 0u32;
1337+ for name in ["read_intra_mode(", "read_intra_mode_rect("] {
1338+ for (at, _) in src.match_indices(name) {
1339+ // The definition itself, not a call.
1340+ if src[..at].ends_with("fn ") {
1341+ continue;
1342+ }
1343+ sites += 1;
1344+ let window = &src[at..(at + 4096).min(src.len())];
1345+ let end = window.find("fctx,\n").unwrap_or(window.len());
1346+ assert!(
1347+ window[..end].contains("Some((palette_ctx, &palette_cache)),"),
1348+ "a {name} call site does not hand the reader a palette ctx/cache pair -- \
1349+ the deleted `palette.is_none()` refusal was its guard"
1350+ );
1351+ }
1352+ }
1353+ assert_eq!(sites, 8, "the call-site audit found {sites} sites, not the 8 it enumerated");
1354+ }
1355+
1048 /// Every entry of [`PROVEN`] must still name a live refusal and a test1356 /// Every entry of [`PROVEN`] must still name a live refusal and a test
1049 /// that exists, and the count it prints is the inventory's numerator.1357 /// that exists, and the count it prints is the inventory's numerator.
1050 #[test]1358 #[test]