forge
Explore
Log in

Don't you dare go Hollow

lane-av1422lpf: pin the three panic witnesses and gate all seven sites

Browse files at this commit

d840e80af88ea70a2ad36308da83aebf5cbaafbfAhmet Kaan GümüşParent: 4058fb3
Committed code refuses 4:2:2 at the sequence header, so the decode-level
half of this gate cannot run here. What is committed is the byte pin
(size + fnv1a64) plus refusal-by-name for the three cells that used to
panic, and a source-scan arm with one assertion per site.

Every scan assertion has a forbidden twin and a required twin, so neither
an unreverted site nor a matcher that stopped matching can pass. Two of
the matchers (sites 5 and 6) were DEAD on first write -- the revert
mutation still passed because the literal being searched for never
matched even with the fix in place, since the line-anchored form cannot
span the fix's own comment. Measured and corrected: the gate now also
builds a whitespace-flattened form of each body for the matchers that
span an argument list, and every site's revert mutation reds it.
crates/ec-av1/fixtures/W_intrabc.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/X_intrabc_tiled.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/Y_intrabc_10b.obuadded+0 -0

Binary file changed

crates/ec-av1/src/stream.rsmodified+269 -2
@@ -3020,6 +3020,270 @@ pub(crate) mod tests {
3020 /// the refusal-by-name contract: with the header refusal standing,3020 /// the refusal-by-name contract: with the header refusal standing,
3021 /// NO committed test can decode a 4:2:2 stream, because the bypass that3021 /// NO committed test can decode a 4:2:2 stream, because the bypass that
3022 /// would allow it must never be committed.3022 /// would allow it must never be committed.
3023+ /// lane-av1422lpf: the 4:2:2 lossless INTER chroma panic family -- SEVEN
3024+ /// sites, each indexing a block's chroma PLANE BLOCK with the ENCLOSING
3025+ /// SQUARE `max(side >> ss_x, side >> ss_y)`.
3026+ ///
3027+ /// libaom's chroma plane block is PER-AXIS, `(bw >> ss_x) x
3028+ /// (bh >> ss_y)` (`av1_common_int.h`'s `av1_get_plane_block_size`, the
3029+ /// `dec->uv_buffer` extent in decodeframe.c), and it is square only when
3030+ /// `ss_x == ss_y`. The enclosing square is the same number at 4:2:0
3031+ /// (`side >> 1`) and 4:4:4 (`side`) on a square block, so every site
3032+ /// below is byte-identical there; at 4:2:2 the square is the LUMA side
3033+ /// and each site walked off its own buffer.
3034+ ///
3035+ /// Committed code refuses 4:2:2 at the sequence header, so -- exactly
3036+ /// like the witnesses above -- what this gate can assert in committed
3037+ /// code is the byte pin, the refusal-by-name contract, and the arm below:
3038+ /// that each site's PER-AXIS expression is still spelled per-axis and
3039+ /// the square-cut expression it replaced is gone. The decode-level
3040+ /// evidence is measured on the local `EC_AV1_ALLOW_422_PROBE`
3041+ /// patch-run-restore build and is in `lanes/av1422lpf.report.md`.
3042+ #[test]
3043+ fn the_pinned_422_lossless_inter_chroma_panics_refuse_by_name() {
3044+ const NAME: &str = "the_pinned_422_lossless_inter_chroma_panics_refuse_by_name";
3045+ const REFUSAL: &str = "a chroma format of 4:2:2";
3046+ for (file, bytes, fp) in [
3047+ ("W_intrabc.obu", 130_320usize, 0xb6d5c4653a32567a_u64),
3048+ ("X_intrabc_tiled.obu", 131_696, 0xb6e04621d2116ef7),
3049+ ("Y_intrabc_10b.obu", 202_281, 0x2ecf03435a14dbf),
3050+ ] {
3051+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
3052+ .join("fixtures")
3053+ .join(file);
3054+ let data = std::fs::read(&path).unwrap_or_else(|e| {
3055+ panic!("{NAME}: pinned witness {file} is missing ({e}) -- the gate cannot run")
3056+ });
3057+ assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
3058+ assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
3059+ let err = decode_stream(&data).unwrap_err().to_string();
3060+ assert!(
3061+ err.contains(REFUSAL),
3062+ "{NAME}: {file} must refuse by name, got: {err}"
3063+ );
3064+ }
3065+ }
3066+
3067+ /// lane-av1422lpf: the SOURCE-SCAN arm of the witness gate above -- one
3068+ /// assertion per site, so a mutation at any single site reds exactly that
3069+ /// site and leaves the other six alone.
3070+ ///
3071+ /// Every assertion has a NEGATIVE twin (`forbidden`) and a POSITIVE twin
3072+ /// (`required`), so neither an unreverted site nor a matcher that has
3073+ /// stopped matching can pass: the forbidden string is absent AND the
3074+ /// required string is present in the same function body. The `required`
3075+ /// half is what makes this gate non-vacuous in the
3076+ /// `dead-matcher-positive-control` sense -- a scan that matched nothing
3077+ /// would fail it rather than pass silently.
3078+ ///
3079+ /// `strip_code` is the same comment-stripping the arms above use: the
3080+ /// fixes quote their own old expression to say what it was, and a prose
3081+ /// mention must neither read as a reintroduction nor mask one.
3082+ #[test]
3083+ fn the_422_lossless_inter_chroma_walk_sites_stay_per_axis() {
3084+ const NAME: &str = "the_422_lossless_inter_chroma_walk_sites_stay_per_axis";
3085+ let src = include_str!("decode.rs");
3086+ let strip_code = |body: &str| -> String {
3087+ body.lines()
3088+ .map(|l| l.split_once("//").map_or(l, |(c, _)| c))
3089+ .collect::<Vec<_>>()
3090+ .join("\n")
3091+ };
3092+ // A SECOND form with the same comment stripping but every run of
3093+ // whitespace collapsed to one space, so a matcher can span an argument
3094+ // list that a line-anchored fix's own comment sits inside. Without it
3095+ // the site-5 and site-6 matchers are DEAD: the mutation that reverts
3096+ // them still passes, because the literal being searched for never
3097+ // matched even when the fix was in place. Measured, not assumed --
3098+ // `verifier-dead-matcher-positive-control`.
3099+ let flatten = |body: &str| -> String {
3100+ strip_code(body)
3101+ .split_whitespace()
3102+ .collect::<Vec<_>>()
3103+ .join(" ")
3104+ };
3105+ let body_of = |fn_name: &str| -> String {
3106+ let after = src
3107+ .split_once(&format!("\nfn {fn_name}("))
3108+ .unwrap_or_else(|| panic!("{NAME}: `{fn_name}` must exist in decode.rs"));
3109+ let end = after.1.find("\nfn ").unwrap_or(after.1.len());
3110+ strip_code(&after.1[..end])
3111+ };
3112+ let flat_of = |fn_name: &str| -> String {
3113+ let after = src
3114+ .split_once(&format!("\nfn {fn_name}("))
3115+ .unwrap_or_else(|| panic!("{NAME}: `{fn_name}` must exist in decode.rs"));
3116+ let end = after.1.find("\nfn ").unwrap_or(after.1.len());
3117+ flatten(&after.1[..end])
3118+ };
3119+ // (label, enclosing fn, forbidden square-cut spelling, required
3120+ // per-axis spelling, required count in that fn)
3121+ let sites: [(&str, &str, &str, &str, usize); 4] = [
3122+ (
3123+ "site 1 -- read_inter_chroma_lossless's composed-grid extent",
3124+ "read_inter_chroma_lossless",
3125+ "stride * stride,\n );",
3126+ "stride * blk_h,",
3127+ 1,
3128+ ),
3129+ (
3130+ "site 7 -- read_intra_chroma_lossless's composed-grid extent",
3131+ "read_intra_chroma_lossless",
3132+ "stride * stride,\n );",
3133+ "stride * blk_h,",
3134+ 1,
3135+ ),
3136+ (
3137+ "site 4 -- the strip chroma rect's VERT arm at ss (1,0)",
3138+ "decode_inter_block",
3139+ "} else if s.horz {\n (8, 4)\n } else {\n (4, 8)\n }",
3140+ "} else if ss_y(fctx) == 0 {\n (4, 16)\n } else {\n (4, 8)\n }",
3141+ 1,
3142+ ),
3143+ (
3144+ "site 5 -- the mu-chunk lossless walk's prediction stride",
3145+ "decode_inter_block",
3146+ "(write_chroma_w, write_chroma_h), chroma_side, mode_for_tx,",
3147+ "(write_chroma_w, write_chroma_h), chroma_stride, mode_for_tx,",
3148+ 2,
3149+ ),
3150+ ];
3151+ for (label, fn_name, forbidden, required, count) in sites {
3152+ // The last table row is written in the flattened form (it spans a
3153+ // comment the fix itself wrote); the others are line-anchored.
3154+ let flattened = required.contains(" mode_for_tx,");
3155+ let body = if flattened {
3156+ flat_of(fn_name)
3157+ } else {
3158+ body_of(fn_name)
3159+ };
3160+ assert_eq!(
3161+ body.matches(forbidden).count(),
3162+ 0,
3163+ "{NAME}: {label} is BACK -- the square-cut expression \
3164+ `{forbidden}` is what this gate exists for"
3165+ );
3166+ assert!(
3167+ body.matches(required).count() >= count,
3168+ "{NAME}: {label}: the per-axis expression `{required}` must appear \
3169+ at least {count} time(s) in `{fn_name}` -- found {}",
3170+ body.matches(required).count()
3171+ );
3172+ }
3173+ // Sites 2, 5 and 6 are the `chroma_side`-vs-`chroma_stride` and
3174+ // `chroma_side`-vs-`chroma_buf_h` argument choices, which are
3175+ // single-token differences on otherwise identical lines. Counting the
3176+ // remaining `chroma_side` uses per arm is the only way to see them, so
3177+ // they get their own exact-count assertions instead of a substring.
3178+ let dib = body_of("decode_inter_block");
3179+ // Site 2: the lossless TX_4x4 unit replay indexes the composed grid.
3180+ assert_eq!(
3181+ dib.matches("let start = (cr * cu + rr) * chroma_stride + cc * cu;")
3182+ .count(),
3183+ 1,
3184+ "{NAME}: site 2 -- the lossless TX_4x4 replay must index the \
3185+ composed plane grid at `chroma_stride` (the plane block's own \
3186+ width), not `chroma_side`"
3187+ );
3188+ assert_eq!(
3189+ dib.matches("let start = (cr * cu + rr) * chroma_side + cc * cu;")
3190+ .count(),
3191+ 0,
3192+ "{NAME}: site 2 is BACK -- the lossless TX_4x4 replay indexes the \
3193+ composed grid at the enclosing square again"
3194+ );
3195+ // Sites 5 and 6. The two mu-chunk walks (the single-reference and the
3196+ // compound twin) take the block's `(write_chroma_w, write_chroma_h)`
3197+ // and the stride SEPARATELY; the two intra-in-inter walks take both
3198+ // the block shape and the region as `(chroma_stride, chroma_buf_h)`.
3199+ // Every one of the four must be per-axis; the pre-fix spelling was
3200+ // the enclosing square `chroma_side` for the stride, and
3201+ // `(chroma_side, chroma_side)` for the intra block shape.
3202+ let dibf = flat_of("decode_inter_block");
3203+ assert_eq!(
3204+ dibf.matches("(chroma_stride, chroma_buf_h),").count(),
3205+ 3,
3206+ "{NAME}: site 6 -- the two intra-in-inter walks pass the plane block \
3207+ as `(chroma_stride, chroma_buf_h)` at all THREE argument positions \
3208+ it occupies -- the mu-chunk walk's blk shape, and the whole-block walk's blk shape and region -- found {}",
3209+ dibf.matches("(chroma_stride, chroma_buf_h),").count()
3210+ );
3211+ assert_eq!(
3212+ dibf.matches("(chroma_side, chroma_side),").count(),
3213+ 0,
3214+ "{NAME}: site 6 is BACK -- an intra-in-inter walk still hands the \
3215+ plane block the enclosing square `chroma_side`"
3216+ );
3217+ // The geometry the scan cannot see, derived from the same `>> ss`
3218+ // forms the fixes use, so the scan and the fix cannot disagree about
3219+ // what per-axis means at each chroma format. A 16x16 luma block:
3220+ // (side >> ss_x, side >> ss_y) is the plane block and
3221+ // max(side >> ss_x, side >> ss_y) is the enclosing square.
3222+ let plane_block = |side: usize, ss_x: u32, ss_y: u32| (side >> ss_x, side >> ss_y);
3223+ let enclosing = |side: usize, ss_x: u32, ss_y: u32| {
3224+ (
3225+ (side >> ss_x).max(side >> ss_y),
3226+ (side >> ss_x).max(side >> ss_y),
3227+ )
3228+ };
3229+ for (label, side, ss_x, ss_y, block, square) in [
3230+ ("4:2:0", 16usize, 1u32, 1u32, (8, 8), (8, 8)),
3231+ ("4:2:2", 16, 1, 0, (8, 16), (16, 16)),
3232+ ("4:4:4", 16, 0, 0, (16, 16), (16, 16)),
3233+ ] {
3234+ assert_eq!(
3235+ plane_block(side, ss_x, ss_y),
3236+ block,
3237+ "{NAME}: the {label} chroma plane block of a {side}x{side} luma block"
3238+ );
3239+ assert_eq!(
3240+ enclosing(side, ss_x, ss_y),
3241+ square,
3242+ "{NAME}: the {label} enclosing chroma square of a {side}x{side} \
3243+ luma block"
3244+ );
3245+ }
3246+ // The load-bearing claim of "unchanged at 4:2:0 and 4:4:4": the two
3247+ // are the same number exactly when `ss_x == ss_y`, and DIFFERENT at
3248+ // 4:2:2 -- which is what makes every site above inert there and
3249+ // active at 4:2:2. If this ever held at 4:2:2 the fixes would be
3250+ // untested rather than inert.
3251+ assert_eq!(plane_block(16, 1, 1), enclosing(16, 1, 1));
3252+ assert_eq!(plane_block(16, 0, 0), enclosing(16, 0, 0));
3253+ assert_ne!(
3254+ plane_block(16, 1, 0),
3255+ enclosing(16, 1, 0),
3256+ "{NAME}: 4:2:2 must NOT be square -- if the plane block equalled \
3257+ the enclosing square at ss (1,0), none of these sites could ever \
3258+ be wrong and the gates above would be measuring nothing"
3259+ );
3260+ // Site 4's own geometry: a PARTITION_VERT_4 strip is 4x16 luma and
3261+ // pairs on COLUMNS while `ss_x == 1`, so the pair is 8x16 and its
3262+ // plane block is (8 >> ss_x, 16 >> ss_y).
3263+ for (label, ss_x, _ss_y, want) in [
3264+ ("4:2:0", 1u32, 1u32, (4usize, 8usize)),
3265+ ("4:2:2", 1, 0, (4, 16)),
3266+ ("4:4:4", 0, 0, (8, 16)),
3267+ ] {
3268+ assert_eq!(
3269+ plane_block(8, ss_x, 0).0,
3270+ want.0,
3271+ "{NAME}: site 4 -- the {label} VERT strip pair's chroma width"
3272+ );
3273+ }
3274+ // ...and the HORZ arm of the same match needs NO third shape at
3275+ // 4:2:2: a HORZ_4 strip pairs on ROWS only while `ss_y == 1`, and
3276+ // 4:2:2 has `ss_y == 0`, so each 16x4 strip is its own chroma
3277+ // reference and its own (8 >> ss_x, 4 >> 0) plane block -- which is
3278+ // the (8, 4) the existing arm already returns.
3279+ assert_eq!(
3280+ (plane_block(16, 1, 0).0, plane_block(4, 1, 0).1),
3281+ (8usize, 4usize),
3282+ "{NAME}: site 4 -- the 4:2:2 HORZ strip's own plane block is already \
3283+ the (8, 4) the unsplit arm returns, which is why only the VERT arm \
3284+ gained a shape"
3285+ );
3286+ }
3023 #[test]3287 #[test]
3024 fn the_pinned_422_residual_compound_warp_witness_is_present_and_refuses_by_name() {3288 fn the_pinned_422_residual_compound_warp_witness_is_present_and_refuses_by_name() {
3025 const NAME: &str =3289 const NAME: &str =
@@ -10603,7 +10867,11 @@ pub(crate) mod tests {
10603 let _ = std::fs::remove_dir_all(&dir);10867 let _ = std::fs::remove_dir_all(&dir);
10604 let decoded = decode_stream(&data).expect("the pinned stream decodes");10868 let decoded = decode_stream(&data).expect("the pinned stream decodes");
10605 let ours = pack_rawvideo(&decoded, bit_depth, NAME);10869 let ours = pack_rawvideo(&decoded, bit_depth, NAME);
10606- assert_eq!(ours.len(), want.len(), "{NAME}: the two sides differ in size");10870+ assert_eq!(
10871+ ours.len(),
10872+ want.len(),
10873+ "{NAME}: the two sides differ in size"
10874+ );
10607 10875
10608 // The per-frame plane table, built from each decoded picture's OWN10876 // The per-frame plane table, built from each decoded picture's OWN
10609 // plane lengths -- the same source `pack_rawvideo` lays the bytes out10877 // plane lengths -- the same source `pack_rawvideo` lays the bytes out
@@ -51810,5 +52078,4 @@ exit 0
51810 }52078 }
51811 let _ = std::fs::remove_dir_all(&dir);52079 let _ = std::fs::remove_dir_all(&dir);
51812 }52080 }
51813-
51814 }52081 }