Skip to content

tail: don't panic on '-c +N' with a huge N - #14034

Open
nagendramohan wants to merge 2 commits into
uutils:mainfrom
nagendramohan:fix/tail-positive-bytes-seek-overflow-13887
Open

tail: don't panic on '-c +N' with a huge N#14034
nagendramohan wants to merge 2 commits into
uutils:mainfrom
nagendramohan:fix/tail-positive-bytes-seek-overflow-13887

Conversation

@nagendramohan

Copy link
Copy Markdown

tail -c +N FILE on a regular file larger than the block size seeks to byte N-1. When N-1 exceeds what the OS can seek to (any offset above i64::MAX always fails with EINVAL), the .unwrap() aborted the process.

Clamp the start offset to the file length. A start beyond the end of the file produces no output (matching GNU tail), and clamping also avoids seeking to an offset the OS cannot represent — so the pathological case yields empty output instead of panicking. Behavior is unchanged for valid offsets.

Adds a regression test (verified failing before the fix). Closes #13887.

Closes #13887.

tail -c +N FILE on a regular file larger than the block size seeks to byte N-1. When N-1 exceeds what the OS can seek to (any offset above i64::MAX fails with EINVAL), the .unwrap() aborted the process:

$ yes | head -c 8192 > big
$ tail -c +18446744073709551615 big # -> SIGABRT / exit 134

Fix: clamp the start offset to the file length. A start beyond EOF produces no output (matching GNU tail), and clamping avoids the un-seekable offset
entirely. Behavior is unchanged for valid offsets.

Adds a regression test (verified failing before the fix). cargo fmt, cargo clippy, and the tail test suite pass.

`tail -c +N FILE` on a regular file larger than the block size seeks to
byte N-1. When N-1 exceeds what the OS can seek to (any offset above
i64::MAX always fails with EINVAL), the `.unwrap()` aborted the process.

Clamp the start offset to the file length. A start beyond the end of the
file produces no output (matching GNU `tail`), and clamping also avoids
seeking to an offset the OS cannot represent — so the pathological case
yields empty output instead of panicking. Behavior is unchanged for
valid offsets.

Adds a regression test (verified failing before the fix). Closes uutils#13887.
Comment thread src/uu/tail/src/tail.rs Outdated
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/tail/end-of-device. tests/tail/end-of-device is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/io-errors (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.

tail panics (aborts) on -c +N with a very large N (seek .unwrap() on EINVAL)

2 participants