forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1pinloud: a short pin is loud, so the silent-truncation class leaves the pin path too

Browse files at this commit

04561ce7188acfd0e798e7879f12753094aa619aAhmet Kaan GümüşParent: 79a4e312d08a6d
The dump sites were made loud last; the TEST PINS were the residue that lane named and did
not fix. They wrote with `let _ = std::fs::write(path, bytes)`, so a partial write left a
truncated stream at exactly the path the next line's panic hands the reader ("stream pinned
at {}") -- the same silent-truncation class that produced two false defect rows from the
dump path.

Nine sites now go through `dumpio::pin` (a LoudDump wrapper: create, write, finish, so the
file's on-disk length is verified), plus the two EC_AV1_GATE_DUMP writes and the symtrace
flush, which gains the length check it never had. The one warn-and-continue site keeps that
shape on purpose -- its own assert three lines below is the real failure, and panicking on
the write would mask it -- but its warning now carries expected-vs-on-disk byte counts.
That changes what a failing gate PRINTS, and the report says so.

The site label is TEST_PIN, deliberately outside the env-var namespace: a real EC_AV1_PIN
env var exists (the scratch replay helper reads it), and reusing the name would misdirect a
grepp. Every pin site sits inside a branch already about to panic, so a pin failure cannot
turn a passing test into a panic; the success path is byte-identical and asserted by reading
the bytes back.

The class sweep is half-open and says so: the Err path at ec-h264/ec-h265's encode helpers
is closed, the Ok-but-short path is not, because `fs::write` returning Ok does not guarantee
the file's length.
crates/ec-av1/src/dumpio.rsmodified+173 -5
@@ -155,7 +155,9 @@ impl LoudDump {
155 /// filesystem-level reservation failure all land here rather than in155 /// filesystem-level reservation failure all land here rather than in
156 /// `write`.156 /// `write`.
157 pub fn finish(mut self) {157 pub fn finish(mut self) {
158- let Some(mut file) = self.file.take() else { return };158+ let Some(mut file) = self.file.take() else {
159+ return;
160+ };
159 if let Err(e) = file.flush() {161 if let Err(e) = file.flush() {
160 abort(162 abort(
161 &self.site,163 &self.site,
@@ -193,18 +195,93 @@ impl LoudDump {
193 /// The single failure line every short dump now ends on. `site`, the path, the195 /// The single failure line every short dump now ends on. `site`, the path, the
194 /// bytes on disk vs the bytes owed, and the reason.196 /// bytes on disk vs the bytes owed, and the reason.
195 fn abort(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> ! {197 fn abort(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> ! {
198+ panic!("{}", failure_line(site, path, got, expected, why));
199+}
200+
201+/// The failure line itself, so the fatal and the reporting shapes cannot
202+/// drift apart.
203+fn failure_line(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> String {
196 let owed = match expected {204 let owed = match expected {
197 Some(e) => format!("{e}"),205 Some(e) => format!("{e}"),
198 None => "an unknown number of".to_string(),206 None => "an unknown number of".to_string(),
199 };207 };
200- panic!(208+ format!(
201 "ec-av1 dump FAILED [{}] {}: wrote {} of {} bytes: {}",209 "ec-av1 dump FAILED [{}] {}: wrote {} of {} bytes: {}",
202 site,210 site,
203 path.display(),211 path.display(),
204 got,212 got,
205 owed,213 owed,
206 why214 why
207- );215+ )
216+}
217+
218+/// Write `bytes` to `path` as a FATAL pin: [`pin`] IS a wrapper -- three
219+/// [`LoudDump`] calls (`create`/`write`/`finish`), so it inherits the flush and
220+/// the flush-then-stat ordering for free.
221+///
222+/// lane-av1pinloud: the test-pin sites in `stream.rs` wrote with
223+/// `let _ = std::fs::write(..)` and then named the path in the panic that
224+/// followed ("stream pinned at {}"), so an `ENOSPC`/`EFBIG` left a TRUNCATED
225+/// stream at exactly the path the reader was told to replay -- the same
226+/// silent-truncation class as the dump path, one hop later. Success path is
227+/// byte-identical: same bytes, same path, truncate-then-write.
228+pub fn pin(site: &str, path: impl AsRef<Path>, bytes: &[u8]) {
229+ let mut d = LoudDump::create(site, path, bytes.len());
230+ d.write(bytes);
231+ d.finish();
232+}
233+
234+/// [`pin`]'s NON-FATAL twin, for a site that must not die on a failed pin -- a
235+/// gate whose real failure is the assert that comes after the pin attempt, and
236+/// whose comment says so.
237+///
238+/// This one RE-IMPLEMENTS the check rather than wrapping [`LoudDump`], whose
239+/// failure channel is `panic!`: it cannot report instead of dying. So it does
240+/// `fs::write` + `metadata` itself. Only the failure LINE is shared, via
241+/// [`failure_line`] -- the ordering (flush-then-stat) and the
242+/// write-error-handling are not shared with [`LoudDump`], and a reader must not
243+/// assume they are.
244+///
245+/// Non-fatal, but not silent: a shortfall comes back as the very same failure
246+/// line [`pin`] would have panicked with, expected-vs-on-disk counts included,
247+/// for the caller to print as a warning.
248+pub fn pin_reporting(site: &str, path: impl AsRef<Path>, bytes: &[u8]) -> Result<(), String> {
249+ let path = path.as_ref();
250+ let expected = bytes.len();
251+ if let Err(e) = std::fs::write(path, bytes) {
252+ let on_disk = std::fs::metadata(path)
253+ .map(|m| m.len() as usize)
254+ .unwrap_or(0);
255+ return Err(failure_line(
256+ site,
257+ path,
258+ on_disk,
259+ Some(expected),
260+ &format!("could not write the pin: {e}"),
261+ ));
262+ }
263+ let on_disk = match std::fs::metadata(path) {
264+ Ok(m) => m.len() as usize,
265+ Err(e) => {
266+ return Err(failure_line(
267+ site,
268+ path,
269+ expected,
270+ Some(expected),
271+ &format!("could not stat the written pin: {e}"),
272+ ));
273+ }
274+ };
275+ if on_disk != expected {
276+ return Err(failure_line(
277+ site,
278+ path,
279+ on_disk,
280+ Some(expected),
281+ "the pinned file on disk is not the length of the stream",
282+ ));
283+ }
284+ Ok(())
208 }285 }
209 286
210 /// Write `planes` (already narrowed to their dump's sample width) as ONE dump287 /// Write `planes` (already narrowed to their dump's sample width) as ONE dump
@@ -391,9 +468,100 @@ mod tests {
391 if std::env::var("EC_AV1_DUMPLOUD_CHILD").is_err() {468 if std::env::var("EC_AV1_DUMPLOUD_CHILD").is_err() {
392 return;469 return;
393 }470 }
394- let path =471+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
395- std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/420_mixll_256x128_6f.obu");472+ .join("fixtures/420_mixll_256x128_6f.obu");
396 let bytes = std::fs::read(&path).expect("the pinned fixture");473 let bytes = std::fs::read(&path).expect("the pinned fixture");
397 let _ = crate::stream::decode_stream(&bytes);474 let _ = crate::stream::decode_stream(&bytes);
398 }475 }
476+
477+ #[test]
478+ fn pin_success_path_is_byte_identical() {
479+ let p = scratch("pin-ok");
480+ pin("TEST_PIN", &p, b"stream bytes");
481+ assert_eq!(std::fs::read(&p).unwrap(), b"stream bytes");
482+ let _ = std::fs::remove_file(&p);
483+ }
484+
485+ #[test]
486+ #[cfg(unix)]
487+ fn pin_to_a_full_device_is_loud() {
488+ let msg = caught(|| pin("TEST_PIN", "/dev/full", b"stream bytes"));
489+ assert!(
490+ msg.starts_with("ec-av1 dump FAILED [TEST_PIN] /dev/full: wrote "),
491+ "{msg}"
492+ );
493+ assert!(msg.contains("No space left on device"), "{msg}");
494+ assert!(msg.contains(" of 12 bytes"), "{msg}");
495+ }
496+
497+ /// The reporting shape: same failure line, returned instead of panicked,
498+ /// so a gate whose real failure is the assert after the pin keeps that
499+ /// assert -- but the reader still learns the pin is short.
500+ #[test]
501+ #[cfg(unix)]
502+ fn pin_reporting_is_loud_but_not_fatal() {
503+ let line = pin_reporting("TEST_PIN", "/dev/full", b"stream bytes").unwrap_err();
504+ assert!(
505+ line.contains("ec-av1 dump FAILED [TEST_PIN] /dev/full"),
506+ "{line}"
507+ );
508+ assert!(line.contains(" of 12 bytes"), "{line}");
509+ let p = scratch("pin-reporting-ok");
510+ pin_reporting("TEST_PIN", &p, b"stream bytes").expect("a healthy pin reports nothing");
511+ assert_eq!(std::fs::read(&p).unwrap(), b"stream bytes");
512+ let _ = std::fs::remove_file(&p);
513+ }
514+
515+ /// The pin path's own reproduction: a real `RLIMIT_FSIZE` leaves a real
516+ /// truncated stream at the path the panic names. Without the check the
517+ /// reader replays the fragment and blames the decoder.
518+ #[test]
519+ #[cfg(unix)]
520+ fn a_pin_under_a_file_size_cap_fails_loudly() {
521+ let dir = std::env::temp_dir().join(format!("ec-av1-pin-cap-{}", std::process::id()));
522+ let _ = std::fs::remove_dir_all(&dir);
523+ std::fs::create_dir_all(&dir).unwrap();
524+ let out = Command::new("bash")
525+ .args([
526+ "-c",
527+ "ulimit -f 8; trap \"\" XFSZ; exec \"$0\" \"$@\"",
528+ std::env::current_exe().unwrap().to_str().unwrap(),
529+ "--exact",
530+ "dumpio::tests::pin_child_under_cap",
531+ "--nocapture",
532+ ])
533+ .env("EC_AV1_PINLOUD_CHILD", &dir)
534+ .output()
535+ .expect("spawning the capped child");
536+ let stderr = String::from_utf8_lossy(&out.stderr);
537+ assert!(!out.status.success(), "a short pin must fail\n{stderr}");
538+ assert!(stderr.contains("ec-av1 dump FAILED [TEST_PIN]"), "{stderr}");
539+ assert!(stderr.contains("File too large"), "{stderr}");
540+ let frag = std::fs::metadata(dir.join("cap-pinned.obu")).unwrap().len();
541+ assert!(
542+ frag < 32768,
543+ "the capped child left {frag} bytes where 32768 B was owed"
544+ );
545+ assert!(
546+ stderr.contains(&format!("wrote {frag} of 32768 bytes")),
547+ "{stderr}"
548+ );
549+ let _ = std::fs::remove_dir_all(&dir);
550+ }
551+
552+ /// Child half of [`a_pin_under_a_file_size_cap_fails_loudly`]. Not a gate:
553+ /// with no `EC_AV1_PINLOUD_CHILD` set it writes nothing and asserts nothing.
554+ #[test]
555+ fn pin_child_under_cap() {
556+ let Ok(dir) = std::env::var("EC_AV1_PINLOUD_CHILD") else {
557+ return;
558+ };
559+ // `ulimit -f 8` is 8 KiB, so 4x that is guaranteed to run PAST the cap
560+ // (a write of exactly the cap size succeeds) and land a fragment.
561+ pin(
562+ "TEST_PIN",
563+ Path::new(&dir).join("cap-pinned.obu"),
564+ &[7u8; 32768],
565+ );
566+ }
399 }567 }
crates/ec-av1/src/msac.rsmodified+9 -9
@@ -1133,16 +1133,16 @@ pub(crate) mod symtrace {
1133 let (buf, n) = &mut *b.borrow_mut();1133 let (buf, n) = &mut *b.borrow_mut();
1134 if !buf.is_empty() {1134 if !buf.is_empty() {
1135 // lane-av1dumploud: loud on a short write. `std::fs::write`1135 // lane-av1dumploud: loud on a short write. `std::fs::write`
1136- // returns a `Result` that this used to discard; the expected1136+ // returned a `Result` this used to discard, and the check was
1137- // length is exactly the buffer's own.1137+ // hand-rolled against the buffer length only; lane-av1pinloud
1138+ // folded it into the shared writer so this site also gets the
1139+ // on-disk length check the dump path already had.
1138 let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed);1140 let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1139- let (bytes, at) = (buf.as_bytes(), format!("{dir}/{side}-{seq:05}.txt"));1141+ crate::dumpio::pin(
1140- if let Err(e) = std::fs::write(&at, bytes) {1142+ "EC_AV1_SYMTRACE",
1141- panic!(1143+ format!("{dir}/{side}-{seq:05}.txt"),
1142- "ec-av1 dump FAILED [EC_AV1_SYMTRACE] {at}: wrote 0 of {} bytes: {e}",1144+ buf.as_bytes(),
1143- bytes.len()1145+ );
1144- );
1145- }
1146 }1146 }
1147 buf.clear();1147 buf.clear();
1148 *n = 0;1148 *n = 0;
crates/ec-av1/src/stream.rsmodified+29 -18
@@ -2214,7 +2214,11 @@ fn decode_frame(
2214 crate::dumpio::write_planes(2214 crate::dumpio::write_planes(
2215 "EC_AV1_DECODE_ORDER_DUMP",2215 "EC_AV1_DECODE_ORDER_DUMP",
2216 format!("{path}.f{decode_idx}"),2216 format!("{path}.f{decode_idx}"),
2217- &[&narrow(&picture.y), &narrow(&picture.u), &narrow(&picture.v)],2217+ &[
2218+ &narrow(&picture.y),
2219+ &narrow(&picture.u),
2220+ &narrow(&picture.v),
2221+ ],
2218 );2222 );
2219 }2223 }
2220 // lane-hidden r1: the frame exactly as it is about to be stored into2224 // lane-hidden r1: the frame exactly as it is about to be stored into
@@ -2257,8 +2261,11 @@ fn decode_frame(
2257 // writer that builds the wrong buffer still gets caught.2261 // writer that builds the wrong buffer still gets caught.
2258 let sample_width = if bit_depth == 8 { 1 } else { 2 };2262 let sample_width = if bit_depth == 8 { 1 } else { 2 };
2259 let expected = (picture.y.len() + picture.u.len() + picture.v.len()) * sample_width;2263 let expected = (picture.y.len() + picture.u.len() + picture.v.len()) * sample_width;
2260- let mut f =2264+ let mut f = crate::dumpio::LoudDump::create(
2261- crate::dumpio::LoudDump::create("EC_AV1_FINAL_DUMP", format!("{prefix}.f{decode_idx}"), expected);2265+ "EC_AV1_FINAL_DUMP",
2266+ format!("{prefix}.f{decode_idx}"),
2267+ expected,
2268+ );
2262 for plane in [&picture.y, &picture.u, &picture.v] {2269 for plane in [&picture.y, &picture.u, &picture.v] {
2263 if bit_depth == 8 {2270 if bit_depth == 8 {
2264 f.write(&plane.iter().map(|&s| s as u8).collect::<Vec<u8>>());2271 f.write(&plane.iter().map(|&s| s as u8).collect::<Vec<u8>>());
@@ -14188,7 +14195,7 @@ exit 0
14188 assert_eq!(a.len(), b.len(), "{name}: frame {i} {plane} plane length");14195 assert_eq!(a.len(), b.len(), "{name}: frame {i} {plane} plane length");
14189 if a != b {14196 if a != b {
14190 let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));14197 let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));
14191- let _ = std::fs::write(&pin, &stream);14198+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
14192 let at = a14199 let at = a
14193 .iter()14200 .iter()
14194 .zip(b.iter())14201 .zip(b.iter())
@@ -18198,7 +18205,7 @@ exit 0
18198 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {18205 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
18199 if got.y != want.y || got.u != want.u || got.v != want.v {18206 if got.y != want.y || got.u != want.u || got.v != want.v {
18200 let pin = std::env::temp_dir().join("ec-av1-10bit-inter-gate-fail.obu");18207 let pin = std::env::temp_dir().join("ec-av1-10bit-inter-gate-fail.obu");
18201- let _ = std::fs::write(&pin, &stream);18208+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
18202 let first = |a: &Vec<u16>, b: &Vec<u16>| {18209 let first = |a: &Vec<u16>, b: &Vec<u16>| {
18203 a.iter()18210 a.iter()
18204 .zip(b)18211 .zip(b)
@@ -23167,7 +23174,7 @@ exit 0
23167 Ok(frames) => frames,23174 Ok(frames) => frames,
23168 Err(e) => {23175 Err(e) => {
23169 let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));23176 let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));
23170- let _ = std::fs::write(&pin, &stream);23177+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
23171 panic!(23178 panic!(
23172 "{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})",23179 "{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})",
23173 pin.display()23180 pin.display()
@@ -23187,7 +23194,7 @@ exit 0
23187 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {23194 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
23188 if got.y != want.y || got.u != want.u || got.v != want.v {23195 if got.y != want.y || got.u != want.u || got.v != want.v {
23189 let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));23196 let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));
23190- let _ = std::fs::write(&pin, &stream);23197+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
23191 panic!(23198 panic!(
23192 "{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}",23199 "{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}",
23193 pin.display()23200 pin.display()
@@ -23586,7 +23593,7 @@ exit 0
23586 }23593 }
23587 Err(e) => {23594 Err(e) => {
23588 let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));23595 let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));
23589- let _ = std::fs::write(&pin, &stream);23596+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
23590 panic!(23597 panic!(
23591 "{name}: decode_stream failed on a real aomenc stream (cq={cq} period={period}): {e} (pinned at {})",23598 "{name}: decode_stream failed on a real aomenc stream (cq={cq} period={period}): {e} (pinned at {})",
23592 pin.display()23599 pin.display()
@@ -23608,7 +23615,7 @@ exit 0
23608 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {23615 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
23609 if got.y != want.y || got.u != want.u || got.v != want.v {23616 if got.y != want.y || got.u != want.u || got.v != want.v {
23610 let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));23617 let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));
23611- let _ = std::fs::write(&pin, &stream);23618+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
23612 panic!(23619 panic!(
23613 "{name}: frame {i} mismatch vs ffmpeg (cq={cq} period={period}) -- stream pinned at {}",23620 "{name}: frame {i} mismatch vs ffmpeg (cq={cq} period={period}) -- stream pinned at {}",
23614 pin.display()23621 pin.display()
@@ -27901,7 +27908,7 @@ exit 0
27901 "ec-av1-deblocking-gate-fail-s{}-cq{cq}.obu",27908 "ec-av1-deblocking-gate-fail-s{}-cq{cq}.obu",
27902 42 + round27909 42 + round
27903 ));27910 ));
27904- let _ = std::fs::write(&pin, &stream);27911+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
27905 panic!(27912 panic!(
27906 "frame {i} mismatch vs ffmpeg (seed {} cq {cq}, deblock fired: \27913 "frame {i} mismatch vs ffmpeg (seed {} cq {cq}, deblock fired: \
27907 {counted}) -- stream pinned at {}",27914 {counted}) -- stream pinned at {}",
@@ -28134,14 +28141,18 @@ exit 0
28134 // The pin goes to `fixtures/`, which outlives the session: an28141 // The pin goes to `fixtures/`, which outlives the session: an
28135 // earlier version wrote to a session scratchpad, so once tmpfs28142 // earlier version wrote to a session scratchpad, so once tmpfs
28136 // reaped it a real mismatch aborted on the write instead of28143 // reaped it a real mismatch aborted on the write instead of
28137- // reporting itself. A failed write must not mask the assert28144+ // reporting itself. A failed write must not mask the asserts
28138- // below either, so it warns rather than panicking.28145+ // below either, so it warns rather than panicking -- lane-av1pinloud
28146+ // routed it through `pin_reporting` rather than bare `fs::write`,
28147+ // so the warning now carries on-disk-vs-owed byte counts: a
28148+ // truncated pin was as silent here as anywhere else, and this
28149+ // is the one site where dying on the write is wrong.
28139 let sp = pin_dir();28150 let sp = pin_dir();
28140 let stream_pin = sp.join(format!("cdfflake-stream-seed{seed}.bin"));28151 let stream_pin = sp.join(format!("cdfflake-stream-seed{seed}.bin"));
28141 let ref_pin = sp.join(format!("cdfflake-ffmpeg-raw-seed{seed}.bin"));28152 let ref_pin = sp.join(format!("cdfflake-ffmpeg-raw-seed{seed}.bin"));
28142 for (path, bytes) in [(&stream_pin, &stream), (&ref_pin, &ffmpeg_raw)] {28153 for (path, bytes) in [(&stream_pin, &stream), (&ref_pin, &ffmpeg_raw)] {
28143- if let Err(e) = std::fs::write(path, bytes) {28154+ if let Err(line) = crate::dumpio::pin_reporting("TEST_PIN", path, bytes) {
28144- eprintln!("cdfflake: could not pin to {}: {e}", path.display());28155+ eprintln!("cdfflake: {line}");
28145 }28156 }
28146 }28157 }
28147 eprintln!(28158 eprintln!(
@@ -28893,9 +28904,9 @@ exit 0
28893 if mismatched {28904 if mismatched {
28894 let pin =28905 let pin =
28895 std::env::temp_dir().join("ec-av1-reference-select-gate-fail.obu");28906 std::env::temp_dir().join("ec-av1-reference-select-gate-fail.obu");
28896- let _ = std::fs::write(&pin, &stream);28907+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
28897 if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {28908 if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
28898- std::fs::write(&path, &stream).expect("writing pinned stream");28909+ crate::dumpio::pin("EC_AV1_GATE_DUMP", &path, &stream);
28899 eprintln!(28910 eprintln!(
28900 "EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"28911 "EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"
28901 );28912 );
@@ -29103,9 +29114,9 @@ exit 0
29103 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);29114 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
29104 if mismatched {29115 if mismatched {
29105 let pin = std::env::temp_dir().join("ec-av1-compound-refs-gate-fail.obu");29116 let pin = std::env::temp_dir().join("ec-av1-compound-refs-gate-fail.obu");
29106- let _ = std::fs::write(&pin, &stream);29117+ crate::dumpio::pin("TEST_PIN", &pin, &stream);
29107 if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {29118 if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
29108- std::fs::write(&path, &stream).expect("writing pinned stream");29119+ crate::dumpio::pin("EC_AV1_GATE_DUMP", &path, &stream);
29109 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");29120 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
29110 }29121 }
29111 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {29122 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
lanes/av1pinloud.report.mdadded+130 -0
@@ -0,0 +1,130 @@
1+# lane av1pinloud — loud self-pins in `stream.rs`
2+
3+## Defect
4+
5+Every self-pin site in `crates/ec-av1/src/stream.rs` wrote with
6+
7+```rust
8+let _ = std::fs::write(&pin, &stream);
9+```
10+
11+and then named the path in the very next statement's failure message
12+("stream pinned at {}"). A partial write (`ENOSPC`, `RLIMIT_FSIZE`) therefore left a
13+**truncated stream at exactly the path the reader was told to replay** — the same
14+silent-truncation class that produced two false defect rows on the dump path
15+(`lanes/unwritten-dep.report.md`), one hop downstream. `fs::write`'s `Result` was
16+discarded, so nothing said so.
17+
18+Nine sites: `stream.rs` 14191, 18201, 23170, 23190, 23589, 23611, 27904, 28896,
19+29106 — plus the two `EC_AV1_GATE_DUMP` writes beside 28896/29106
20+(`stream.rs` 28898, 29108), which checked the write but never checked the resulting
21+length.
22+
23+## Change
24+
25+`crates/ec-av1/src/dumpio.rs` gains two pin helpers plus a `failure_line` helper so the
26+fatal and reporting message shapes cannot drift:
27+
28+- `pin(site, path, bytes)` — fatal. Same shape as `write_planes` for a single blob:
29+ create, `write_all`, then stat the file and compare against `bytes.len()`.
30+ Success path is byte-identical to the old `fs::write`: same bytes, same path,
31+ truncate-then-write.
32+- `pin_reporting(site, path, bytes) -> Result<(), String>` — non-fatal, not silent.
33+ Returns the **same** failure line `pin` would have panicked with
34+ (`ec-av1 dump FAILED [TEST_PIN] <path>: wrote N of M bytes: <why>`).
35+
36+These are NOT both wrappers over `LoudDump`, and the difference is load-bearing:
37+
38+- `pin` **is** a wrapper — three `LoudDump` calls (`create`/`write`/`finish`), so it
39+ inherits the flush and the flush-then-stat ordering for free.
40+- `pin_reporting` **re-implements** the check with `fs::write` + `metadata`, because
41+ `LoudDump`'s failure channel is `panic!` and this site must not die. Only the failure
42+ *line* is shared (via `failure_line`); the ordering is not.
43+
44+All nine pin sites now call `pin("TEST_PIN", ...)`; both `EC_AV1_GATE_DUMP` writes call
45+`pin("EC_AV1_GATE_DUMP", ...)` (previously `fs::write(...).expect(...)`, loud on a write
46+error but blind to a short file on disk).
47+
48+One more in-crate site of the same shape: `msac.rs:1140` (`EC_AV1_SYMTRACE` flush) had a
49+hand-rolled panic that compared the buffer length but never stat'ed the file. Folded
50+into `pin` so it gets the on-disk check.
51+
52+### Site label
53+
54+The label is **`TEST_PIN`**, deliberately outside the `EC_AV1_*` env-var namespace: no
55+env var of that name exists (a real `EC_AV1_PIN` env var does — the scratch replay
56+helper's — and reusing that name would have pointed a triager at the wrong thing), and
57+every other failure-line label in this module names the env var that triggers the write.
58+`EC_AV1_GATE_DUMP` and `EC_AV1_SYMTRACE` keep their real env-var names because they *are*
59+real env vars.
60+
61+### `stream.rs:28143` — the warns-by-design site: decision
62+
63+Routed through `pin_reporting`, keeping it non-fatal. The two shapes differ for a
64+stated reason, not by accident:
65+
66+- the nine sites run **inside the arm that is already panicking** — the pin exists to
67+ feed that panic, so dying on a short pin replaces a message with a strictly better one
68+ (same panic, plus the byte counts).
69+- 28143's real failure is the `assert_eq!` three lines below (luma/U/V vs ffmpeg).
70+ Panicking on the write would **mask that assert** with an unrelated filesystem
71+ error — the exact failure its comment refuses. So it must not be fatal.
72+
73+What changed is what it *prints*: the old `could not pin to {path}: {e}` warning became
74+`cdfflake: ec-av1 dump FAILED [TEST_PIN] {path}: wrote N of M bytes: {why}` — same
75+severity (a warning, then the asserts run), now carrying expected-vs-on-disk counts. A
76+truncated pin there was previously indistinguishable from a good one.
77+
78+## Proof
79+
80+`dumpio::tests::a_pin_under_a_file_size_cap_fails_loudly` is the real reproduction: a
81+child under `ulimit -f 8` (8 KiB) pins 32 KiB, leaving a fragment and dying on the
82+counts, not carrying on.
83+
84+```
85+$ EC_AV1_PINLOUD_CHILD=/tmp/pincap2 bash -c 'ulimit -f 8; trap "" XFSZ; exec "$0" "$@"' \
86+ <testbin> --exact dumpio::tests::pin_child_under_cap --nocapture
87+ec-av1 dump FAILED [TEST_PIN] /tmp/pincap2/cap-pinned.obu: wrote 8192 of 32768 bytes:
88+ write failed with 0 bytes confirmed in hand: File too large (os error 27)
89+test dumpio::tests::pin_child_under_cap ... FAILED
90+$ ls -l /tmp/pincap2
91+-rw-r--r-- 1 tahinli tahinli 8192 cap-pinned.obu
92+```
93+
94+8192 B on disk where 32768 B was owed — bytes-expected vs bytes-on-disk, and the
95+reported count is the file's real length, not what `write_all` acknowledged.
96+
97+Also: `pin_success_path_is_byte_identical` (bytes on disk equal the bytes handed in),
98+`pin_to_a_full_device_is_loud`, `pin_reporting_is_loud_but_not_fatal` (the same line,
99+returned rather than panicked, plus a healthy pin returning `Ok`).
100+
101+Scoped runs (`CARGO_TARGET_DIR=/home/user/.cache/tgt/av1pinloud`):
102+
103+```
104+cargo test -p ec-av1 --lib dumpio:: 12 passed; 0 failed
105+cargo test -p ec-av1 --lib -- --exact \
106+ stream::tests::a_444_intra_in_inter_128root_muchroma_pinned_stream_decodes_pixel_exact
107+ 1 passed; 0 failed
108+cargo check -p ec-av1 --tests clean
109+```
110+
111+## Class sweep, other crates
112+
113+`grep` for `let _ = std::fs::write` / `let _ = …write_all` / discarded `fs::write` across
114+every `ec-*` crate:
115+
116+| Site | Shape | Disposition |
117+|---|---|---|
118+| `ec-vorbis/tests/oracle.rs:1447,1452` | `let _ = fs::write` of sweep tables into `lanes/*.txt` | **Reported, not fixed.** Not the same shape: the path is not printed in a failure message, the file is a human-read report rather than a replay artefact, and the asserts that follow (`rows > 0`, `failures.is_empty()`) do not depend on it. Sibling lane material. |
119+| `ec-ac3/examples/ac3dec.rs:89,96` | `let _ = out.write_all(..)` to raw stdout of an example decoder | **Reported, not fixed.** No path is named; a short write there is the encoder of a raw file a downstream `cmp` measures. Different class (unverified output, not a mis-pointed replay path). |
120+| `ec-h264/tests/encode.rs:475,1068`, `ec-h265/tests/encode.rs:289,341` | `std::fs::write(..).ok()?` feeding an `ffmpeg` subprocess | **Reported, NOT fixed — half-open.** The `Err` path IS closed: `.ok()?` propagates the failure as `None` and the helper bails instead of running ffmpeg on a fragment. The `Ok`-but-short path is NOT closed: `fs::write` returning `Ok` does not guarantee the on-disk length — exactly the gap `LoudDump::finish()` exists to close — and these sites have no equivalent, the file going straight to ffmpeg as decoder input. Same mis-pointed-artefact family, one hop removed. A following lane should route these four through a loud writer; those crates have no shared helper yet, so the fix is per-crate. |
121+
122+Two of the sibling shapes are open in the weaker sense above; none of the sibling sites
123+has the "discard the error, then hand the reader that exact path" shape. Fixed only
124+`ec-av1` (plus its own msac site).
125+
126+## Notes for the reviewer
127+
128+- Success path is byte-identical; the only behavioural delta is that a short pin is now
129+ fatal (9 sites + 2 gate dumps + the symtrace flush) or loud-with-counts (28143).
130+- Grep `TEST_PIN` (not `EC_AV1_PIN`) when triaging a short-pin failure line.
\ No newline at end of file\ No newline at end of file