forge
Explore
Log in

Don't you dare go Hollow

Make the frame-count failure name the real cause, and classify the defect

Browse files at this commit

e107603a9488f3c96f7e18a8535e47356fbb3295Ahmet Kaan GümüşParent: 32ee762
  • test
    • make the frame-count failure name the real cause, and classify the defect
Show full message
test(av1): make the frame-count failure name the real cause, and classify the defect

Main's r6 item 1, and it is the change that matters: a caller passing our own
decode's length as the oracle's expected count used to get

    expected N 4:2:0 frames, ffmpeg said: <empty>

with an EMPTY tail, because ffmpeg runs at `-v error` and succeeds. The message
named ffmpeg, said nothing about where N came from, and sent the next reader
hunting ffmpeg for a count ffmpeg never chose. All three helpers
(`ffmpeg_decode_sequence`, `_10bit`, `_444`) now share `frame_count_diagnosis`,
which reports the caller's count, ffmpeg's ACTUAL count, the byte arithmetic, and
states that `frames` is the caller's assertion rather than a measurement -- and
that if it came from our own decode_stream(), the disagreement is OURS.

Measured, same probe as r5:
    FRAME COUNT MISMATCH (4:2:0 192x128): the caller passed `frames=0`, ffmpeg
    produced 1 frame(s) (36864 bytes, 0 byte(s) not a whole frame, at 36864 B/frame).
    `frames` is the EXPECTED count the CALLER asserted -- it is NOT measured from
    ffmpeg... the fix is on OUR side, not ffmpeg's. ffmpeg itself exited cleanly.

This converts most of the 44 from confusing to diagnosable WITHOUT touching a
single caller, which is the whole point: 44 edits of unclear value was the risk.

`count_vacuity` keeps the floor and gains the note r6 item 3 asked for, naming
the TWO defect classes so the next reader does not repeat r4's mistake:
MISATTRIBUTED RED (what these sites are) vs SILENT PASS (a different defect with
a different fix, which these are NOT).

Sweep result, after fixing two detection bugs of mine: 61 sites, 17 spec-pinned,
44 not, across 30 distinct gates. The line/gate/count columns are exact (a
line-based scan with no body slicing). The `pixel_comparing` column is
APPROXIMATE and under-reports -- I sampled three gates it marks `false` and all
three plainly compare planes (4-5 plane-compare lines each). Its body slice is a
hand-rolled brace walk, and this crate's compare idioms vary enough that the
heuristic is not trustworthy. I am reporting that rather than shipping a 44-row
table derived from it: the classification needs a reader, not a regex.

Sites FIXED at the source: none beyond r4's. The 44 are reported with gate and
count expression, and fixing them means deriving each count from the fixture or
from the encoder's own frame count -- per-gate work across 30 gates, which is the
next lane, not this commit.

gate_coverage 15 passed, refusal_inventory 15, count_vacuity 2, pin_inventory 3,
pinned_golden3 green. 0 warnings. `#[ignore]` unchanged at 34.
crates/ec-av1/src/gate_coverage.rsmodified+141 -6
@@ -2040,6 +2040,16 @@ mod pin_inventory_tests {
20402040 /// cannot pass silently -- it reds, with a message that blames FFMPEG for a
20412041 /// count OUR decoder chose.
20422042 ///
2043+/// TWO DEFECT CLASSES, DO NOT CONFLATE THEM (lane-av1pins5 r6):
2044+/// * MISATTRIBUTED RED -- a wrong count reds, and the old message blamed
2045+/// ffmpeg for a number OUR decoder chose. This is what these sites are.
2046+/// `ffmpeg_decode_sequence`'s `stdout.len() == frame_bytes * frames` assert
2047+/// is unconditional, so it cannot pass silently.
2048+/// * SILENT PASS -- the compare is skipped or truncated and the gate reports
2049+/// green. A DIFFERENT defect with a DIFFERENT fix, and r4 mislabelled these
2050+/// sites as belonging to it. If you are reading this to decide what to fix,
2051+/// fix the message and the count SOURCE; do not go looking for a silent pass.
2052+///
20432053 /// r4 reported this shape as "a vacuous pass" and told Main so. That was wrong.
20442054 /// The consequence is a MISATTRIBUTED RED. The fix r4 shipped is still right (the
20452055 /// count now comes from the fixture, so the red names the real cause), but the
@@ -2059,18 +2069,28 @@ mod count_vacuity {
20592069 /// lines above: that is what makes the count a SPEC rather than a
20602070 /// self-fulfilling number.
20612071 pub pinned_by: Option<String>,
2072+ /// Does this gate actually COMPARE PIXELS (so a wrong count would
2073+ /// corrupt a verdict), or is it a report-only probe?
2074+ pub pixel_comparing: bool,
2075+ /// A frame count already in scope that is a SPEC rather than a
2076+ /// self-fulfilling number -- e.g. the `FRAMES` the gate encoded, or a
2077+ /// count asserted on the pinned stream. `Some(..)` means the fix is a
2078+ /// one-line swap at this site.
2079+ pub fixable_from: Option<String>,
20622080 }
20632081
20642082 pub fn sites(src: &str) -> Vec<Site> {
20652083 let mut out = Vec::new();
20662084 let lines: Vec<&str> = src.lines().collect();
20672085 let mut gate = String::new();
2086+ let mut fn_start = 0usize;
20682087 for (i, line) in lines.iter().enumerate() {
20692088 let t = line.trim_start();
20702089 if let Some(rest) = t.strip_prefix("fn ") {
20712090 if let Some(n) = rest.split('(').next() {
20722091 if !n.contains(' ') {
20732092 gate = n.to_string();
2093+ fn_start = i;
20742094 }
20752095 }
20762096 }
@@ -2111,16 +2131,118 @@ mod count_vacuity {
21112131 // within the preceding 12 lines? That is the difference between
21122132 // a spec and a self-fulfilling number.
21132133 let binding = last.trim_end_matches(".len()").trim_end_matches(".count()");
2134+ // Match the assertion across a LINE BREAK: rustfmt puts
2135+ // assert_eq!(
2136+ // frames.len(),
2137+ // so requiring `assert_eq!(frames.len()` on one line missed
2138+ // every multi-line spelling and inflated the unpinned count.
2139+ let want = format!("{binding}.len()");
21142140 let mut pinned = None;
2115- for back in 1..=12usize {
2141+ for back in 1..=14usize {
21162142 if i < back {
21172143 break;
21182144 }
2119- let prev = lines[i - back];
2120- if prev.contains(&format!("assert_eq!({binding}.len()"))
2121- || prev.contains(&format!("assert_eq!({binding}.len(), "))
2145+ let prev = lines[i - back].trim_start();
2146+ if !prev.starts_with("assert") || !prev.contains('(') {
2147+ continue;
2148+ }
2149+ // rustfmt splits `assert_eq!(` from its first argument, so
2150+ // the binding is on THIS line or the NEXT one.
2151+ let here = prev.contains(&want);
2152+ let next = lines
2153+ .get(i - back + 1)
2154+ .map(|l| l.trim_start().contains(&want))
2155+ .unwrap_or(false);
2156+ if here || next {
2157+ pinned = Some(prev.chars().take(60).collect());
2158+ break;
2159+ }
2160+ }
2161+ // Pixel-comparing? A gate that compares planes is the only
2162+ // place a wrong count corrupts a verdict; a report-only probe
2163+ // just prints.
2164+ // Bound to THIS fn only. Slicing to EOF matched a later gate's
2165+ // `const FRAMES` and its `assert_eq!(got.y`, which reported all
2166+ // 48 sites as pixel-comparing with a spec in scope -- the same
2167+ // over-broad-scope bug the class keeps teaching.
2168+ // Brace-depth walk, not `find("\n }")`: a gate with an
2169+ // early 4-space `}` (a bare block, a `match` arm tail) truncated
2170+ // the slice and made the compare-detection read false.
2171+ // STRING-AWARE brace walk. Counting raw bytes counts a `}`
2172+ // inside a format string as a closing brace, which truncated the
2173+ // body and made every compare-detection read false -- the same
2174+ // trap that made stream.rs look 2 braces short in the first
2175+ // review of this wave.
2176+ let bytes = src.as_bytes();
2177+ let mut depth = 0i32;
2178+ let mut started = false;
2179+ let mut fn_end = src.len();
2180+ let mut in_str = false;
2181+ let mut in_line_comment = false;
2182+ let mut k = fn_start;
2183+ while k < bytes.len() {
2184+ let c = bytes[k];
2185+ if in_line_comment {
2186+ if c == b'\n' {
2187+ in_line_comment = false;
2188+ }
2189+ k += 1;
2190+ continue;
2191+ }
2192+ if in_str {
2193+ if c == b'\\' {
2194+ k += 2;
2195+ continue;
2196+ }
2197+ if c == b'"' {
2198+ in_str = false;
2199+ }
2200+ k += 1;
2201+ continue;
2202+ }
2203+ match c {
2204+ b'"' => in_str = true,
2205+ b'/' if bytes.get(k + 1) == Some(&b'/') => {
2206+ in_line_comment = true;
2207+ k += 1;
2208+ }
2209+ b'{' => {
2210+ depth += 1;
2211+ started = true;
2212+ }
2213+ b'}' => {
2214+ depth -= 1;
2215+ if started && depth == 0 {
2216+ fn_end = k + 1;
2217+ break;
2218+ }
2219+ }
2220+ _ => {}
2221+ }
2222+ k += 1;
2223+ }
2224+ let body = &src[fn_start..fn_end];
2225+ // APPROXIMATE, and known to be so: the body slice is a
2226+ // hand-rolled brace walk, and this crate's compare idioms vary
2227+ // enough that the column under-reports. The LINE, GATE and
2228+ // COUNT EXPR columns are exact (line-based scan, no body
2229+ // slicing); treat `pixel_comparing` as a hint, not a verdict.
2230+ // Idiom-tolerant: this crate spells the compare every which way
2231+ // (`assert_eq!(got.y, want.y)`, `assert_eq!(g, w)`,
2232+ // `let ok = ours.y == ref_f.y`, `ours.y, want.y`), so match the
2233+ // PLANE inside an assertion, not one fixed spelling.
2234+ let pixel_comparing = body.contains("assert")
2235+ && (body.contains(".y,")
2236+ || body.contains(".y ==")
2237+ || body.contains(".y)")
2238+ || body.contains("vs ffmpeg"));
2239+ // A SPEC already in scope for this gate?
2240+ let mut fixable = None;
2241+ for cand in ["FRAMES", "frame_count", "NFRAMES", "frames_expected"] {
2242+ if body.contains(&format!("const {cand}"))
2243+ || body.contains(&format!("let {cand}"))
21222244 {
2123- pinned = Some(prev.trim().chars().take(90).collect());
2245+ fixable = Some(cand.to_string());
21242246 break;
21252247 }
21262248 }
@@ -2129,6 +2251,8 @@ mod count_vacuity {
21292251 gate: gate.clone(),
21302252 count_expr: last.to_string(),
21312253 pinned_by: pinned,
2254+ pixel_comparing,
2255+ fixable_from: fixable,
21322256 });
21332257 }
21342258 }
@@ -2185,9 +2309,20 @@ mod count_vacuity_tests {
21852309 pinned,
21862310 unpinned.len()
21872311 );
2188- for line in unpinned.iter().take(12) {
2312+ for line in unpinned.iter() {
21892313 eprintln!(" {line}");
21902314 }
2315+ // The table Main asked for, as columns the guard itself computes.
2316+ for x in s.iter().filter(|x| x.pinned_by.is_none()) {
2317+ eprintln!(
2318+ "ROW {} | {} | {} | pixel_comparing={} | spec_in_scope={}",
2319+ x.line,
2320+ x.gate,
2321+ x.count_expr,
2322+ x.pixel_comparing,
2323+ x.fixable_from.clone().unwrap_or_else(|| "-".into())
2324+ );
2325+ }
21912326 assert!(
21922327 !s.is_empty() && s.iter().all(|x| !x.gate.is_empty()),
21932328 "a site has no owning gate -- the sweep's gate attribution is broken"
crates/ec-av1/src/stream.rsmodified+81 -6
@@ -5290,6 +5290,57 @@ pub(crate) mod tests {
52905290 }
52915291
52925292 /// Decodes `frames` concatenated 4:2:0 frames out of one AV1 OBU stream.
5293+ /// The frame-count diagnostic shared by the three `ffmpeg_decode_sequence*`
5294+ /// helpers (lane-av1pins5 r6).
5295+ ///
5296+ /// Before this, a caller that passed its OWN decode's length as the expected
5297+ /// count got `expected N 4:2:0 frames, ffmpeg said: ` -- with an EMPTY tail,
5298+ /// because ffmpeg ran at `-v error` and succeeded. The message named ffmpeg,
5299+ /// said nothing about where `N` came from, and sent the next reader hunting
5300+ /// ffmpeg for a count ffmpeg never chose.
5301+ ///
5302+ /// The class is MISATTRIBUTED RED, not silent pass: the helper's
5303+ /// `out.stdout.len() == frame_bytes * frames` assert fires unconditionally, so
5304+ /// a wrong count cannot pass -- it just fails while blaming the wrong
5305+ /// component. (Measured: `ffmpeg_decode_sequence(&s, 192, 128, 0)` panics
5306+ /// here, not silently.) Naming the real cause is the whole fix; no caller has
5307+ /// to change to benefit.
5308+ fn frame_count_diagnosis(
5309+ format: &str,
5310+ frames: usize,
5311+ width: usize,
5312+ height: usize,
5313+ frame_bytes: usize,
5314+ got: usize,
5315+ stderr: &[u8],
5316+ ) -> String {
5317+ let actual = if frame_bytes == 0 {
5318+ 0
5319+ } else {
5320+ got / frame_bytes
5321+ };
5322+ let leftover = if frame_bytes == 0 {
5323+ got
5324+ } else {
5325+ got % frame_bytes
5326+ };
5327+ format!(
5328+ "FRAME COUNT MISMATCH ({format} {width}x{height}): the caller passed \
5329+ `frames={frames}`, ffmpeg produced {actual} frame(s) ({got} bytes, \
5330+ {leftover} byte(s) not a whole frame, at {frame_bytes} B/frame).\n\
5331+ `frames` is the EXPECTED count the CALLER asserted -- it is NOT measured \
5332+ from ffmpeg, so it never had ffmpeg's agreement. If it came from our own \
5333+ decode_stream(), this is OUR decoder disagreeing with ffmpeg about how many \
5334+ frames the stream holds, and the fix is on OUR side, not ffmpeg's. ffmpeg \
5335+ itself exited cleanly{}.",
5336+ if stderr.is_empty() {
5337+ " with no diagnostics (`-v error`)"
5338+ } else {
5339+ ""
5340+ }
5341+ )
5342+ }
5343+
52935344 fn ffmpeg_decode_sequence(
52945345 stream: &[u8],
52955346 width: usize,
@@ -5312,8 +5363,16 @@ pub(crate) mod tests {
53125363 assert_eq!(
53135364 out.stdout.len(),
53145365 frame_bytes * frames,
5315- "expected {frames} 4:2:0 frames, ffmpeg said: {}",
5316- String::from_utf8_lossy(&out.stderr)
5366+ "{}",
5367+ frame_count_diagnosis(
5368+ "4:2:0",
5369+ frames,
5370+ width,
5371+ height,
5372+ frame_bytes,
5373+ out.stdout.len(),
5374+ &out.stderr
5375+ )
53175376 );
53185377 (0..frames)
53195378 .map(|i| {
@@ -5406,8 +5465,16 @@ pub(crate) mod tests {
54065465 assert_eq!(
54075466 out.stdout.len(),
54085467 frame_bytes * frames,
5409- "expected {frames} 4:2:0 10-bit frames, ffmpeg said: {}",
5410- String::from_utf8_lossy(&out.stderr)
5468+ "{}",
5469+ frame_count_diagnosis(
5470+ "4:2:0 10-bit",
5471+ frames,
5472+ width,
5473+ height,
5474+ frame_bytes,
5475+ out.stdout.len(),
5476+ &out.stderr
5477+ )
54115478 );
54125479 fn le16(bytes: &[u8]) -> Vec<u16> {
54135480 bytes
@@ -6811,8 +6878,16 @@ pub(crate) mod tests {
68116878 assert_eq!(
68126879 out.stdout.len(),
68136880 frame_bytes * frames,
6814- "expected {frames} 4:4:4 frames, ffmpeg said: {}",
6815- String::from_utf8_lossy(&out.stderr)
6881+ "{}",
6882+ frame_count_diagnosis(
6883+ "4:4:4",
6884+ frames,
6885+ width,
6886+ height,
6887+ frame_bytes,
6888+ out.stdout.len(),
6889+ &out.stderr
6890+ )
68166891 );
68176892 (0..frames)
68186893 .map(|i| {