head: fix panic on write error when printing a long -v filename header#13268
Open
koopatroopa787 wants to merge 1 commit into
Open
head: fix panic on write error when printing a long -v filename header#13268koopatroopa787 wants to merge 1 commit into
koopatroopa787 wants to merge 1 commit into
Conversation
When head prints the ==> <filename> <== header for -v/multi-file mode, the filename was written with print_verbatim(file).unwrap(). If stdout is a full device (ENOSPC) and the filename is longer than the internal LineWriter buffer (~1024 bytes), the write_all inside print_verbatim flushes mid-write, the write error is returned to .unwrap(), and the process panics (exit 134). A short filename stays entirely within the buffer, so its error only surfaces at the next ?-checked write — those fail gracefully. The asymmetry meant only long filenames triggered the panic. Fix: replace .unwrap() with ? so the error is propagated to the enclosing closure, which already returns UResult<()>, and is handled the same way as the surrounding write!/writeln! calls. Adds a regression test using /dev/full and a >1024-byte path built from repeated "./" segments that the OS resolves to /dev/null. Fixes uutils#13264
|
GNU testsuite comparison: |
Contributor
|
duplicated PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
head -vprints a==> <filename> <==header for each file. Thefilename was written with
print_verbatim(file).unwrap(). If stdoutis a full device (
ENOSPC) and the filename is longer than theLineWriterinternal buffer (~1024 bytes),write_allinsideprint_verbatimflushes mid-write, the write error is returned to.unwrap(), and the process panics (exit 134) instead of exitingcleanly.
A short filename stays entirely within the buffer, so its error only
surfaces at the next
?-checkedwriteln!— those fail gracefully.This asymmetry means only long filenames trigger the panic.
GNU
headreports the error and exits with code 1.Fix
Replace
.unwrap()with?so the error propagates through theenclosing
UResult<()>closure, exactly like the surroundingwrite!/writeln!calls.Changes
src/uu/head/src/head.rsline 463:.unwrap()→?tests/by-util/test_head.rs: regression test using/dev/fulland aFixes #13264