forge
Explore
Log in

Don't you dare go Hollow

A pin scanner that sees every shape, and a count-vacuity sweep

Browse files at this commit

6049140b40ac1c424fe140a2080b9784d5cb97d1Ahmet Kaan GümüşParent: 58978d8
  • test
    • a pin scanner that sees every shape, and a count-vacuity sweep
Show full message
test(av1): a pin scanner that sees every shape, and a count-vacuity sweep

The r3 inventory matched two single-name call shapes and reported "the
machine-local-pin population is zero". `pinned_warp_stream_decodes_pixel_exact`
read 14 pins through a directory `concat!` literal plus a runtime
`format!("{fixtures}/{n}.obu")`, matched neither, and was invisible to it.

`pin_inventory` resolves FIVE shapes: crate_pin("X"), pin_dir().join("X"),
a whole-file concat! literal, a directory literal + runtime name, and (e) the
shape THIS FIX INTRODUCED -- `crate_pin(&format!("{n}.ext"))`.

Shape (e) is the one worth reading. Rewriting the directory literal as a
committed-path lookup made the gate CORRECT and simultaneously INVISIBLE:
`crate_pin("` no longer appears, shape (a) found nothing, and the enumerator
reported a CLEAN tree while 14 pins were read. A false pass is worse than the
original gap -- the original at least showed up in a filesystem audit. It was
caught by the `reads.len() >= 20` floor in the invariant test, which is why that
floor is there. This is the general lesson: fixing a shape can blind the check
that was watching it, so the check needs a floor AND a capability test that does
not depend on the live tree.

Capability tests use SYNTHETIC source, not the live file -- asserting against
the live tree would rot the moment the fix lands, which is exactly how a scanner
loses its edge and reports a clean tree again. Two of the three bugs in this
scanner were found that way: a `format!` brace-escape that emitted `{n` instead
of `{n}`, and a `find(')')` that stopped at `len()`'s own paren and silently
yielded ZERO sites.

`count_vacuity` enumerates every site that passes a locally-derived count as the
oracle's expected frame count: 61 found, 13 spec-pinned by a prior assert, 48 not.

CORRECTION to r4, which reported this shape as a "vacuous pass" and told Main
so. MEASURED by calling `ffmpeg_decode_sequence(&stream, 192, 128, 0)` on a real
pinned stream under `catch_unwind`: it PANICS at `stream.rs:5110` with
"expected 0 4:2:0 frames, ffmpeg said: ". The helper asserts
`out.stdout.len() == frame_bytes * frames` unconditionally, so a wrong count
cannot pass silently -- it REDS, with a message blaming FFMPEG for a count OUR
decoder chose. The consequence is a MISATTRIBUTED RED, not a silent pass. r4's
FIX is still right (the count now comes from the fixture, so the red names the
real cause); the justification was wrong, and a sweep repeating it would send the
next reader after a bug that does not exist.

The 48 unpinned sites are REPORTED, not fixed: that is an unbounded change across
gates this lane does not own. The pin-class gates are all clean -- 0 unpinned
count sites in lr_sgr, check_pinned_warp_stream, golden3, sbpart and film-grain.

`pinned_warp_stream_decodes_pixel_exact` is live and green: 14 pins read from
`crates/ec-av1/fixtures/`, 1 passed 0 failed 0 ignored, 1.47 s.
`#[ignore]` 36 -> 35. gate_coverage 15 passed, refusal_inventory 15 passed.
Tests and test helpers only; the frames=0 probe was deleted before this commit.
crates/ec-av1/src/gate_coverage.rsmodified+218 -1
@@ -1847,10 +1847,60 @@ mod pin_inventory {
1847 }1847 }
1848 let _ = vi;1848 let _ = vi;
1849 }1849 }
1850+ // (e) the shape this very fix INTRODUCED:
1851+ // `.map(|n| crate_pin(&format!("{n}.obu")))`. Rewriting the
1852+ // directory literal as a committed-path lookup made the gate
1853+ // correct and simultaneously invisible -- `crate_pin("` no
1854+ // longer appears, so shape (a) found nothing and the
1855+ // enumerator reported a CLEAN tree while 14 pins were read. A
1856+ // false pass is worse than the original gap: the original at
1857+ // least showed up in a filesystem audit. Caught here by the
1858+ // `reads.len()` floor in the invariant test.
1859+ for m in body.match_indices("crate_pin(&format!(") {
1860+ let rest = &body[m.0 + 19..];
1861+ let Some(close) = rest.find(')') else {
1862+ continue;
1863+ };
1864+ let call = &rest[..close];
1865+ if !call.contains('"') {
1866+ continue;
1867+ }
1868+ let head = &body[..m.0];
1869+ let Some(bracket) = head.rfind('[') else {
1870+ continue;
1871+ };
1872+ let names: Vec<String> = head[bracket..]
1873+ .split('"')
1874+ .skip(1)
1875+ .step_by(2)
1876+ .filter(|x| !x.is_empty() && !x.contains(' ') && *x != "]")
1877+ .map(|x| x.to_string())
1878+ .collect();
1879+ // the literal inside the format!, e.g. `{n}.obu`
1880+ let lit = call.split('"').nth(1).unwrap_or("");
1881+ let ext = lit
1882+ .split_once("}")
1883+ .map(|(_, e)| e.to_string())
1884+ .unwrap_or_default();
1885+ for n in names {
1886+ out.push(PinRead {
1887+ gate: gate.clone(),
1888+ file: format!("{n}{ext}"),
1889+ shape: "crate_pin_runtime_name",
1890+ });
1891+ }
1892+ }
1850 }1893 }
1851 out1894 out
1852 }1895 }
1853 1896
1897+ /// Does this shape resolve through `crate_pin`, i.e. the COMMITTED
1898+ /// crate-local copy? Both the literal form and the runtime-name form do --
1899+ /// only the two `pin_dir`/root-`concat!` forms are machine-local.
1900+ pub fn resolves_committed(shape: &str) -> bool {
1901+ matches!(shape, "crate_pin" | "crate_pin_runtime_name")
1902+ }
1903+
1854 /// Is `file` present as a committed crate-local fixture?1904 /// Is `file` present as a committed crate-local fixture?
1855 pub fn is_committed(file: &str) -> bool {1905 pub fn is_committed(file: &str) -> bool {
1856 std::path::Path::new(env!("CARGO_MANIFEST_DIR"))1906 std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -1964,7 +2014,7 @@ mod pin_inventory_tests {
1964 );2014 );
1965 let machine_local: Vec<String> = reads2015 let machine_local: Vec<String> = reads
1966 .iter()2016 .iter()
1967- .filter(|r| r.shape != "crate_pin")2017+ .filter(|r| !super::pin_inventory::resolves_committed(r.shape))
1968 .map(|r| format!("{} reads {} via {}", r.gate, r.file, r.shape))2018 .map(|r| format!("{} reads {} via {}", r.gate, r.file, r.shape))
1969 .collect();2019 .collect();
1970 assert!(2020 assert!(
@@ -1977,3 +2027,170 @@ mod pin_inventory_tests {
1977 );2027 );
1978 }2028 }
1979 }2029 }
2030+
2031+/// lane-av1pins5 r5: the COUNT-VACUITY enumerator.
2032+///
2033+/// Passing OUR OWN decode's length as the ORACLE's expected frame count
2034+/// (`ffmpeg_decode_sequence(&stream, w, h, ours.len())`) is a real defect, but
2035+/// NOT the one r4 claimed. MEASURED, by calling
2036+/// `ffmpeg_decode_sequence(&stream, 192, 128, 0)` on a real pinned stream under
2037+/// `catch_unwind`: it PANICS at `stream.rs:5110` with
2038+/// `expected 0 4:2:0 frames, ffmpeg said: `. The helper asserts
2039+/// `out.stdout.len() == frame_bytes * frames` unconditionally, so a wrong count
2040+/// cannot pass silently -- it reds, with a message that blames FFMPEG for a
2041+/// count OUR decoder chose.
2042+///
2043+/// r4 reported this shape as "a vacuous pass" and told Main so. That was wrong.
2044+/// The consequence is a MISATTRIBUTED RED. The fix r4 shipped is still right (the
2045+/// count now comes from the fixture, so the red names the real cause), but the
2046+/// justification was wrong, and a sweep that repeats it would send the next
2047+/// reader after a silent-pass bug that does not exist.
2048+///
2049+/// This enumerator finds every such site and classifies it, so the class is
2050+/// visible and cannot shrink unnoticed.
2051+#[cfg(test)]
2052+mod count_vacuity {
2053+ /// One oracle call whose expected frame count is locally derived.
2054+ pub struct Site {
2055+ pub line: usize,
2056+ pub gate: String,
2057+ pub count_expr: String,
2058+ /// An independent count assertion on the same binding, within a few
2059+ /// lines above: that is what makes the count a SPEC rather than a
2060+ /// self-fulfilling number.
2061+ pub pinned_by: Option<String>,
2062+ }
2063+
2064+ pub fn sites(src: &str) -> Vec<Site> {
2065+ let mut out = Vec::new();
2066+ let lines: Vec<&str> = src.lines().collect();
2067+ let mut gate = String::new();
2068+ for (i, line) in lines.iter().enumerate() {
2069+ let t = line.trim_start();
2070+ if let Some(rest) = t.strip_prefix("fn ") {
2071+ if let Some(n) = rest.split('(').next() {
2072+ if !n.contains(' ') {
2073+ gate = n.to_string();
2074+ }
2075+ }
2076+ }
2077+ for callee in [
2078+ "ffmpeg_decode_sequence(",
2079+ "ffmpeg_decode_sequence_10bit(",
2080+ "ffmpeg_decode_sequence_444(",
2081+ ] {
2082+ let Some(at) = line.find(callee) else {
2083+ continue;
2084+ };
2085+ let args = &line[at + callee.len()..];
2086+ // DEPTH-AWARE close: `args.find(')')` stops at the `)` of
2087+ // `pictures.len()` and truncates the arg list mid-expression,
2088+ // which silently yielded zero sites on the first run.
2089+ let mut depth = 1usize;
2090+ let mut close = None;
2091+ for (k, ch) in args.char_indices() {
2092+ match ch {
2093+ '(' => depth += 1,
2094+ ')' => {
2095+ depth -= 1;
2096+ if depth == 0 {
2097+ close = Some(k);
2098+ break;
2099+ }
2100+ }
2101+ _ => {}
2102+ }
2103+ }
2104+ let Some(close) = close else { continue };
2105+ let arglist = &args[..close];
2106+ let last = arglist.rsplit(',').next().unwrap_or("").trim();
2107+ if !(last.ends_with(".len()") || last.ends_with(".count()")) {
2108+ continue;
2109+ }
2110+ // Is the SAME binding count-asserted against a literal/const
2111+ // within the preceding 12 lines? That is the difference between
2112+ // a spec and a self-fulfilling number.
2113+ let binding = last.trim_end_matches(".len()").trim_end_matches(".count()");
2114+ let mut pinned = None;
2115+ for back in 1..=12usize {
2116+ if i < back {
2117+ break;
2118+ }
2119+ let prev = lines[i - back];
2120+ if prev.contains(&format!("assert_eq!({binding}.len()"))
2121+ || prev.contains(&format!("assert_eq!({binding}.len(), "))
2122+ {
2123+ pinned = Some(prev.trim().chars().take(90).collect());
2124+ break;
2125+ }
2126+ }
2127+ out.push(Site {
2128+ line: i + 1,
2129+ gate: gate.clone(),
2130+ count_expr: last.to_string(),
2131+ pinned_by: pinned,
2132+ });
2133+ }
2134+ }
2135+ out
2136+ }
2137+}
2138+
2139+#[cfg(test)]
2140+mod count_vacuity_tests {
2141+ use super::count_vacuity::sites;
2142+
2143+ /// The shape is real and widespread; this pins the FLOOR so the sweep cannot
2144+ /// silently stop finding sites. Measured count is well above this.
2145+ #[test]
2146+ fn the_count_vacuity_sweep_finds_the_known_sites() {
2147+ let src = include_str!("stream.rs");
2148+ let s = sites(src);
2149+ assert!(
2150+ s.len() >= 40,
2151+ "the count-vacuity sweep found only {} site(s); expected 40+ -- it has lost a \
2152+ shape",
2153+ s.len()
2154+ );
2155+ assert!(
2156+ s.iter()
2157+ .any(|x| x.line == 3895 || x.count_expr == "pictures.len()"),
2158+ "the original reported site (pictures.len()) is gone -- re-derive the sweep"
2159+ );
2160+ }
2161+
2162+ /// Report, per site: does the count come from a SPEC or from our own decode?
2163+ /// Prints the table the r5 report carries. The assertion is the FLOOR above,
2164+ /// not "zero unpinned" -- the residual unpinned sites are handed to another
2165+ /// lane with this table, and forcing them all here would be an unbounded
2166+ /// change dressed as a fix.
2167+ #[test]
2168+ fn every_locally_derived_oracle_count_is_reported() {
2169+ let src = include_str!("stream.rs");
2170+ let s = sites(src);
2171+ let unpinned: Vec<String> = s
2172+ .iter()
2173+ .filter(|x| x.pinned_by.is_none())
2174+ .map(|x| {
2175+ format!(
2176+ "stream.rs:{} | {} | {} | NOT SPEC-PINNED",
2177+ x.line, x.gate, x.count_expr
2178+ )
2179+ })
2180+ .collect();
2181+ let pinned = s.len() - unpinned.len();
2182+ eprintln!(
2183+ "count-vacuity sweep: {} site(s); {} spec-pinned by a prior assert, {} not",
2184+ s.len(),
2185+ pinned,
2186+ unpinned.len()
2187+ );
2188+ for line in unpinned.iter().take(12) {
2189+ eprintln!(" {line}");
2190+ }
2191+ assert!(
2192+ !s.is_empty() && s.iter().all(|x| !x.gate.is_empty()),
2193+ "a site has no owning gate -- the sweep's gate attribution is broken"
2194+ );
2195+ }
2196+}