forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1sitecensus: two subsize guards claimed per site, not per level

Browse files at this commit

f5333e1294455918ae9cc70ccd083fc1f18a1f44Ahmet Kaan GümüşParent: e4f7cf81698dbd
The walk census claimed two guards by LEVEL, so deleting either left the test green.
The key-frame 8x8 SECOND resolution (decode.rs:37621) feeds decode_leaf_rect8 on a raw
part8 whose VERT shape is 4x8, BLOCK_INVALID at 4:2:2; the census's AtResolution(KF, 8)
row finds the OTHER 8x8 guard in the function. The inter decoder's own 128-root guard
(decode.rs:54495) sits above match part128, whose half128_inter arms descend into 128x64
and 64x128 rects, also BLOCK_INVALID at 4:2:2; no row claimed it because the inter
decoder never routes through read_sb128_root.

Each new row is anchored on a string unique in the decode body and searched FROM that
anchor, not from the function top -- the find()-returns-the-first-guard defect, closed
once already in this file. Deleting either guard reds the census and names the site.
No decode-path line changed.
crates/ec-av1/src/decode.rsmodified+130 -4
@@ -38457,8 +38457,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
38457 // data lengths: this dump is the PADDED plane, not a crop, so the38457 // data lengths: this dump is the PADDED plane, not a crop, so the
38458 // writer's extent is `p.data` itself.38458 // writer's extent is `p.data` itself.
38459 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);38459 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
38460- let narrow =38460+ let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
38461- |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
38462 crate::dumpio::write_planes(38461 crate::dumpio::write_planes(
38463 "EC_AV1_PREFILT_DUMP",38462 "EC_AV1_PREFILT_DUMP",
38464 format!("{path}.f{idx}"),38463 format!("{path}.f{idx}"),
@@ -56838,8 +56837,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
56838 // lane-av1dumploud: loud on a short write (see the key-frame twin56837 // lane-av1dumploud: loud on a short write (see the key-frame twin
56839 // above -- same file, same shape, same three planes).56838 // above -- same file, same shape, same three planes).
56840 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);56839 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
56841- let narrow =56840+ let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
56842- |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
56843 crate::dumpio::write_planes(56841 crate::dumpio::write_planes(
56844 "EC_AV1_PREFILT_DUMP",56842 "EC_AV1_PREFILT_DUMP",
56845 format!("{path}.f{idx}"),56843 format!("{path}.f{idx}"),
@@ -58156,6 +58154,134 @@ mod tests {
58156 "inter_strip_chroma gained a second writer -- the inter 1:4 strips can now \58154 "inter_strip_chroma gained a second writer -- the inter 1:4 strips can now \
58157 come from a level whose guard this census has not checked"58155 come from a level whose guard this census has not checked"
58158 );58156 );
58157+
58158+ // (g) PER-SITE rows. Everything above claims a guard by LEVEL --
58159+ // "there is a `refuse_invalid_subsize((8, 8))` somewhere in the
58160+ // key-frame tile decoder" -- and that is exactly what makes two
58161+ // guards deletable: the key-frame 8x8 level has TWO resolution
58162+ // sites (37322 and 37621) and the walk census's `decode_leaf_rect8`
58163+ // row is satisfied by the first one, so deleting the SECOND left the
58164+ // test green; the inter decoder carries its OWN 128-root guard
58165+ // (54495) while the `decode_block_128rect` row names
58166+ // `read_sb128_root`, so deleting the inter copy also left it green.
58167+ // The merged scan's count cross-check is what reds them, and a
58168+ // count is not a location.
58169+ //
58170+ // So each row below names an ANCHOR that is unique in the decode
58171+ // body -- the code the site hangs off -- and requires the level's
58172+ // guard to sit between that anchor and the dispatch the site
58173+ // feeds, within the same function. A level guard elsewhere in that
58174+ // function cannot stand in, because the search starts AT the
58175+ // anchor. Deleting the named guard finds no guard after the anchor
58176+ // and reds; moving it below the dispatch reds the ordering assert.
58177+ //
58178+ // Row shape: (site label, guard's function, level, unique anchor,
58179+ // dispatch token the guard must precede, shapes the site walks).
58180+ let body_of = |name: &str| -> &str {
58181+ let start = decode_body
58182+ .find(&format!("\nfn {name}("))
58183+ .or_else(|| decode_body.find(&format!("\npub(crate) fn {name}(")))
58184+ .or_else(|| decode_body.find(&format!("\npub fn {name}(")))
58185+ .unwrap_or_else(|| panic!("{name} is not a function in this file"));
58186+ let end = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
58187+ .iter()
58188+ .filter_map(|pat| decode_body[start + 1..].find(pat).map(|i| start + 1 + i))
58189+ .min()
58190+ .unwrap_or(decode_body.len());
58191+ &decode_body[start..end]
58192+ };
58193+ let site_rows: &[(&str, &str, usize, &str, &str, &[(usize, usize)])] = &[
58194+ // The key-frame 8x8 level resolves TWICE (37322 for the frame
58195+ // interior, 37621 for the `pre8` probe path). Both feed
58196+ // `decode_leaf_rect8` on a raw `part8`, whose VERT shape is 4x8 --
58197+ // BLOCK_INVALID at 4:2:2. The anchor `let pre8 = ...` is what
58198+ // makes this row about the SECOND site: with `find()` scoped to
58199+ // the function alone the search would return 37322 and never
58200+ // look here.
58201+ (
58202+ "the key-frame 8x8 SECOND resolution",
58203+ KF,
58204+ 8,
58205+ "let pre8 = dec.debug_state().0;",
58206+ "decode_leaf_rect8(",
58207+ &[(8, 4), (4, 8)],
58208+ ),
58209+ // The inter decoder resolves its own 128 root at 54495 rather
58210+ // than routing through `read_sb128_root` (which is where the
58211+ // `decode_block_128rect` row's guard lives). The dispatch token
58212+ // is the `half128_inter!` arm that descends into a 128x64 /
58213+ // 64x128 rect -- both BLOCK_INVALID at 4:2:2 in
58214+ // `PLANE_BLOCK_INVALID_422`. `macro_rules! half128_inter` is
58215+ // unique in the file, so this row cannot drift onto the other
58216+ // one.
58217+ (
58218+ "the inter decoder's own 128-root guard",
58219+ INTER,
58220+ 128,
58221+ "macro_rules! half128_inter",
58222+ "half128_inter!((br_mi, base_mi.1), 128, 64,",
58223+ &[(128, 64), (64, 128)],
58224+ ),
58225+ ];
58226+ for (label, fscope, level, anchor, dispatch, shapes) in site_rows {
58227+ assert_eq!(
58228+ decode_body.matches(anchor).count(),
58229+ 1,
58230+ "{label}: the site anchor {anchor:?} is not unique in the decode body, so it \
58231+ cannot name one site -- re-derive the anchor for this row"
58232+ );
58233+ // Why the site needs a guard at all: something it dispatches is
58234+ // BLOCK_INVALID at a mode a `color_config` can select. (0, 1) is
58235+ // excluded for the same reason as the walk census above.
58236+ let offending: Vec<(usize, usize, usize, usize)> = shapes
58237+ .iter()
58238+ .flat_map(|&(bw, bh)| {
58239+ [(1, 0), (1, 1), (0, 0)]
58240+ .into_iter()
58241+ .filter_map(move |(sx, sy)| {
58242+ invalid_at(bw, bh, sx, sy).then_some((bw, bh, sx, sy))
58243+ })
58244+ })
58245+ .collect();
58246+ assert!(
58247+ !offending.is_empty(),
58248+ "{label} claims a guard but libaom codes every shape it walks at every \
58249+ selectable subsampling mode -- then it needs none"
58250+ );
58251+ let body = body_of(fscope);
58252+ let a = body.find(anchor).unwrap_or_else(|| {
58253+ panic!(
58254+ "{label}: the anchor {anchor:?} is not inside `{fscope}` -- the guard \
58255+ moved to another function, and the row's scope is stale"
58256+ )
58257+ });
58258+ let gpat = format!("refuse_invalid_subsize(({level}, {level})");
58259+ let g = body[a..].find(&gpat).map(|i| a + i).unwrap_or_else(|| {
58260+ panic!(
58261+ "{label}: `{fscope}` has NO {gpat} at or after the site anchor {anchor:?} \
58262+ -- this site's guard is gone. The level claim elsewhere in this test is \
58263+ still satisfied by the OTHER {level}x{level} guard in the file, which is \
58264+ precisely why this row exists"
58265+ )
58266+ });
58267+ let gap = body[a..g].lines().count();
58268+ assert!(
58269+ gap <= 40,
58270+ "{label}: the {gpat} sits {gap} lines below its own anchor {anchor:?} -- that is \
58271+ a different site, so this row has stopped naming what it claims to name"
58272+ );
58273+ let d = body[g..].find(dispatch).map(|i| g + i).unwrap_or_else(|| {
58274+ panic!(
58275+ "{label}: `{fscope}` dispatches {dispatch:?} nowhere AFTER its {gpat} -- \
58276+ either the dispatch moved above the guard or the site was rewritten"
58277+ )
58278+ });
58279+ assert!(
58280+ g < d,
58281+ "{label}: guard at {g} sits at or after the dispatch at {d} -- a guard BELOW \
58282+ the dispatch can never observe it"
58283+ );
58284+ }
58159 }58285 }
58160 58286
58161 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's58287 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's
lanes/av1sitecensus.report.mdadded+135 -0
@@ -0,0 +1,135 @@
1+# lane/av1sitecensus — W1-6: two subsize guards claimed by LEVEL, not by SITE
2+
3+Base `5ba7a123` (`main`). Worktree `/home/user/.cache/wt/av1sitecensus`, branch
4+`lane/av1sitecensus`. No push, no merge. Commit is one file:
5+`crates/ec-av1/src/decode.rs`, **+128 / -0** — the whole change is the new
6+section; no decode-path line is touched.
7+
8+## The gap
9+
10+`lanes/av1subsizesweep.report.md` §"Not closed" #2 named two guards the walk
11+census could not see:
12+
13+> **Two guards are level-claimed, not site-claimed** (kf 8x8 second
14+> resolution, inter 128-root). The merged scan's count cross-check is what
15+> reds them.
16+
17+Both are real, and the mechanism is the same in each case: a
18+`refuse_invalid_subsize((L, L))` exists **somewhere** in the guard's function,
19+and that is what satisfies the row — so deleting the guard the row is actually
20+about leaves a different guard standing in.
21+
22+| site | guard | why the census was satisfied without it |
23+|---|---|---|
24+| `decode.rs:37621`, `decode_key_frame_tile_with_cdfs` | `refuse_invalid_subsize((8, 8), part8, fctx)?` — the **second** key-frame 8x8 resolution | the walk census's `decode_leaf_rect8` row is `AtResolution(KF, 8)`, which `find()`s the first `(8, 8)` guard in the function — `37322`. Two sites, one claim. |
25+| `decode.rs:54495`, `decode_inter_frame_tile_with_cdfs` | `refuse_invalid_subsize((128, 128), part128, fctx)?` | the `decode_block_128rect` row is `AtResolutionVia("read_sb128_root", 128)`; the inter decoder never routes through `read_sb128_root`, so its own 128-root guard is claimed by **no** row. |
26+
27+Both guards matter: the KF one feeds `decode_leaf_rect8` on a raw `part8`
28+whose VERT shape is 4x8, BLOCK_INVALID at 4:2:2; the inter one is the only
29+thing above `match part128`, whose `half128_inter!` arms descend into 128x64 /
30+64x128 rects (also BLOCK_INVALID at 4:2:2).
31+
32+## The change
33+
34+New section **(g)** at the end of
35+`every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason`. Each
36+row claims a guard **by site**, using an `anchor` that is unique in the decode
37+body — the code the site hangs off — rather than `find()` from the body start
38+or the function start:
39+
40+| row | anchor (unique in decode body) | level | dispatch it must precede |
41+|---|---|---|---|
42+| the key-frame 8x8 SECOND resolution | `let pre8 = dec.debug_state().0;` | 8 | `decode_leaf_rect8(` |
43+| the inter decoder's own 128-root guard | `macro_rules! half128_inter` | 128 | `half128_inter!((br_mi, base_mi.1), 128, 64,` |
44+
45+The check, per row, all inside the guard's own function:
46+
47+1. the anchor occurs **exactly once** in the decode body (else the row has
48+ stopped naming one site and says so);
49+2. the shape(s) the site walks are BLOCK_INVALID at some selectable
50+ subsampling mode — same `(1,0) (1,1) (0,0)` filter as the walk census,
51+ `(0,1)` excluded on libaom's own `color_config` authority;
52+3. the anchor is inside the named function (scope staleness reds);
53+4. `refuse_invalid_subsize((L, L))` exists **at or after the anchor** —
54+ this is the bite: a level guard elsewhere in the function cannot stand in;
55+5. within 40 lines of the anchor, so the match is *this* site and not a
56+ different one further down;
57+6. the dispatch token appears **after** that guard — a guard below the
58+ dispatch reds on ordering.
59+
60+Search starts at the anchor, not at the function top: that is the whole fix,
61+and it is why the already-fixed `find()`-from-body-start defect in this file
62+does not recur here.
63+
64+## Proof that each row bites
65+
66+Each guard deleted individually, test run, guard restored.
67+
68+**Delete `refuse_invalid_subsize((8, 8), part8, fctx)?` at 37621:**
69+
70+```
71+the key-frame 8x8 SECOND resolution: `decode_key_frame_tile_with_cdfs` has NO
72+refuse_invalid_subsize((8, 8) at or after the site anchor
73+"let pre8 = dec.debug_state().0;" -- this site's guard is gone. The level
74+claim elsewhere in this test is still satisfied by the OTHER 8x8 guard in the
75+file, which is precisely why this row exists
76+```
77+
78+```
79+test decode::tests::every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason ... FAILED
80+```
81+
82+**Delete `refuse_invalid_subsize((128, 128), part128, fctx)?` at 54495:**
83+
84+```
85+the inter decoder's own 128-root guard: `decode_inter_frame_tile_with_cdfs`
86+has NO refuse_invalid_subsize((128, 128) at or after the site anchor
87+"macro_rules! half128_inter" -- this site's guard is gone. The level claim
88+elsewhere in this test is still satisfied by the OTHER 128x128 guard in the
89+file, which is precisely why this row exists
90+```
91+
92+```
93+test decode::tests::every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason ... FAILED
94+```
95+
96+**Both restored.** `git diff --stat` is `1 file changed, 128 insertions(+)` —
97+identical to the pre-mutation state, so both restores were byte-exact and no
98+decode-path line drifted.
99+
100+## Verification
101+
102+| check | result |
103+|---|---|
104+| `cargo check -p ec-av1 --tests` | clean |
105+| `every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason` | 1 passed, 0 failed |
106+| `every_partition_symbol_resolution_is_guarded_before_it_dispatches` (sibling structural scan) | 1 passed — the 18-guard count cross-check is untouched |
107+| mutation 1 (delete kf 37621) | RED, names the site |
108+| mutation 2 (delete inter 54495) | RED, names the site |
109+
110+**Commit-hook reflow.** The commit hook ran rustfmt over the whole file, so the
111+committed `decode.rs` diff is `134 insertions / 4 deletions`, not `+128 / -0`.
112+The 4 deleted lines are two copies of one pre-existing two-line closure
113+(`let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { ... }`) reflowed onto a single
114+line by the formatter — a whole-file reflow of pre-existing code, not a
115+semantic edit and not mine. My own addition is the +128, and the census test is
116+green at the committed tip, re-run after the hook.
117+
118+Local scoped runs only; no full `ec-av1` suite (the server fleet owns those).
119+
120+## Scope note, stated plainly
121+
122+Both rows are **existence + ordering** claims at a named site. They do not
123+close `lanes/av1subsizesweep.report.md` §"Not closed" #1 — the census is still a
124+derived site list, so a walk that is neither named here nor reachable through a
125+`partition_w<N>` read is still invisible. This closes #2 only. No other census
126+row was changed; the decode path was read, not edited.
127+
128+## Housekeeping
129+
130+An early edit round in this lane was issued with a worktree-relative path from
131+the primary checkout's cwd and leaked both the section and a mutation into the
132+primary `crates/ec-av1/src/decode.rs`. Caught by `git status` before any commit
133+and reverted with `git checkout --` on that one file; the primary is clean at
134+`5ba7a123`. Every edit after that used absolute paths under the worktree. No
135+commit on this branch contains the leaked hunk.
\ No newline at end of file\ No newline at end of file