You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
find - -printf never flushes stdout, so write errors are lost and output comes after -exec #961
Known:#905 (merged PR) — #905 (related: reports -printf write errors, but only for bytes actually flushed; the unflushed tail is still lost)
-printf writes into the line-buffered stdout and never flushes it, except for \c. When
the format does not end in \n, as in the common -printf '%p\0', the last buffered bytes
are written by the Rust runtime after find has already chosen its exit status. A write
error at that point (ENOSPC, EIO) is dropped, so find exits 0 with nothing on stderr. -print0, which does flush, correctly reports the error. The same missing flush also makes -printf text appear after the output of a later -exec child.
Reproduction
Rust (incorrect)
$ mkdir t && touch t/a t/b
$ ./target/release/find t -printf '%p\0'> /dev/full
# Output: (none)# Exit code: 0
$ ./target/release/find t -print0 > /dev/full # -print0 is fine
find: 'standard output': No space left on device
# Exit code: 1
$ ./target/release/find t -maxdepth 0 -printf 'P:%p ' -exec echo E:{} \;
E:t
P:t
# Exit code: 0
GNU (correct)
$ LC_ALL=C /usr/bin/find t -printf '%p\0'> /dev/full
/usr/bin/find: 'standard output': No space left on device
/usr/bin/find: write error
# Exit code: 1
$ /usr/bin/find t -maxdepth 0 -printf 'P:%p ' -exec echo E:{} \;
P:t E:t
# Exit code: 0
Root cause
Printf::print in src/find/matchers/printf.rs:765-818 writes each component to out. The
only flush() is in the \c branch (line 773):
FormatComponent::Flush => {
out.flush()?;break;}
Printer (-print / -print0) flushes after every record, which is why its errors are
reported.
Test
In tests/test_find.rs:
#[test]#[cfg(target_os = "linux")]fnfind_printf_without_newline_reports_full_disk(){let dev_full = File::create("/dev/full").unwrap();ucmd().args(&["./test_data/simple","-printf","%p\\0"]).set_stdout(dev_full).fails_with_code(1).stderr_contains("No space left on device");}
Reported by Anthropic's OSS Scanner (ANT-2026-1MT0ISRS).
Activity
RagedPanda commentedon Nov 10, 2026
I'd like to work on this. I'll open a PR with a fix and tests shortly.