Repository navigation
tail: stop reading past the original end of file - #15063
Merged
Merged
Conversation
When tail's output is appended back to the file it reads (`tail -n1 f >> f`), the unbounded forward copy never sees EOF because its own writes keep extending the file, so it never terminates and the file grows without bound. For 'lines from the end' mode, bound the forward copy to the portion of the file that existed when it was opened, matching GNU tail, which computes the end position once.
This was referenced Oct 4, 2026
|
GNU testsuite comparison: |
Collaborator
|
@sylvestre, sorry, but this was merged while the |
Contributor
|
@wspperrimh sorry, i had to revert this 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.
tail -n1 f >> fnever terminated once the file was larger than thefilesystem block size:
bounded_tailcopies from the start of thelast lines until EOF, but its own appended output keeps extending the
file, so EOF never arrives and the file grows without bound. GNU tail
9.12 appends the requested lines once and exits.
For
FilterMode::Lines(Signum::Negative), bound the forward copy tothe bytes between the seek position and the file size captured when
the file was opened, reusing
print_target_section's existinglimitpath (
take/send_n_bytes).-c Nwas already bounded by the count,and the
+Nmodes keep GNU's read-until-EOF semantics.Adds a regression test that appends
tail -n1output back to a256 KiB input under an
RLIMIT_FSIZEcap, so a broken implementationfails instead of filling the disk.
Closes #15057.
This patch was written with AI assistance (Devin), as allowed by the
project's AI policy; I reviewed the diff and can justify it in review.