head: fix panic when -v header write fails on a long filename#13430
head: fix panic when -v header write fails on a long filename#13430koopatroopa787 wants to merge 4 commits into
Conversation
|
GNU testsuite comparison: |
|
Please provide a test with this |
When head prints the "==> name <==" header with -v and the filename is longer than stdout's ~1024-byte buffer, a write error (e.g. /dev/full) was surfaced inside print_verbatim().unwrap(), causing an abort instead of a graceful error message. The two adjacent writes already use `?`, but print_verbatim() wrote to a fresh io::stdout() handle and its result was unwrapped. Replace it with stdout.write_all_os(file.as_ref())? so the filename is written through the same locked handle and any error is propagated like the surrounding writes. Fixes uutils#13264
83efada to
a5d770a
Compare
|
Added a |
|
There are CI fails, namely on coding style |
|
Fixed — the |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
When
head -v(or when reading multiple files) prints the==> name <==header and the filename is longer than stdout's ~1024-byte write buffer, a write error (e.g. output to/dev/full) surfaces insideprint_verbatim(file).unwrap()and causes an abort rather than a graceful error message and non-zero exit.The two adjacent writes (
write!(stdout, "==> ")?andwriteln!(stdout, " <==")?) already propagate errors via?, butprint_verbatimwrote directly to a separateio::stdout()handle and its return value was unwrapped — so the error was never propagated.Fix
Replace
print_verbatim(file).unwrap()withstdout.write_all_os(file.as_ref())?— writing the filename through the same lockedStdoutLockas the surrounding writes. Any I/O error is now propagated consistently.Behavior after fix
Fixes #13264