Skip to content

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

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:head-header-write-error
Open

head: propagate a write error from the -v filename header#13996
MsfPablo wants to merge 1 commit 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

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout-group (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)

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