Skip to content

head: propagate a write error from the -v filename header - #13996

Open
MsfPablo wants to merge 3 commits into
uutils:mainfrom
MsfPablo:head-header-write-error
Open

head: propagate a write error from the -v filename header#13996
MsfPablo wants to merge 3 commits into
uutils:mainfrom
MsfPablo:head-header-write-error

Conversation

@MsfPablo

Copy link
Copy Markdown
Contributor

Fixes #13264.

print_verbatim(file).unwrap() was the only unchecked write in print_header — the ==> and <== around it already use ?. Switched it to ? so the error travels the same way.

The length threshold in the issue is what makes this reachable: a short filename stays in the stdout buffer and its write error surfaces later at a ?-checked flush, so only a name longer than the buffer forces a flush inside the unwrap.

$ LONG="/dev/$(python3 -c "print('./'*512)")null"
$ head -v "$LONG" > /dev/full

Now reports the write error and exits 1 instead of aborting.

Tests: an integration test following the /dev/full pattern already used in test_paste.rs, gated to Linux for the same reason.

Worth being upfront: I develop on macOS, where /dev/full is not writable, so I could not execute that test locally. I did verify it compiles and runs by temporarily widening the cfg — it reaches the /dev/full open and fails only there — so CI is the real check on the assertion.

The two header writes around it use ?, but the filename went out via
print_verbatim(file).unwrap(). A short name stays buffered and its error
surfaces later at the checked flush; a name longer than the stdout
buffer forces a flush mid-write, so the failure lands in the unwrap and
aborts instead of being reported.

Fixes uutils#13264
@MsfPablo
MsfPablo force-pushed the head-header-write-error branch from bb0d9ba to 7ea2b92 Compare August 17, 2026 21:04
Comment on lines 1074 to 1076
/// Regression for #11972: a symlink that points to a regular file must
/// still be readable by head (the fd-based check must distinguish the
/// fd's mode, not the symlink's).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment got disconnected from test_head_follows_symlink_to_regular_file.

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tty-eof (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.

Pablo Garcia added 2 commits August 19, 2026 17:16
Move the uutils#13887 verbose-header write-error regression test to after
test_head_follows_symlink_to_regular_file so the uutils#11972 doc comment
stays attached to the test it documents (review feedback).
@MsfPablo
MsfPablo force-pushed the head-header-write-error branch from dd2156e to 0b1bad8 Compare August 19, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

head panics (aborts) on a write error while printing a long -v filename header

2 participants