tail: don't panic on '-c +N' with a huge N - #14034
Open
nagendramohan wants to merge 2 commits into
Open
Conversation
`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.
sylvestre
reviewed
Aug 19, 2026
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
|
GNU testsuite comparison: |
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.
tail -c +N FILEon 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:
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.