Repository navigation
tail: fix -c N printing too much on pipes with short reads - #15845
Open
DevKaurav-14 wants to merge 1 commit into
Open
DevKaurav-14 wants to merge 1 commit into
DevKaurav-14 wants to merge 1 commit into
Conversation
BytesChunkBuffer::fill removed at most one old chunk per read, but reads from a pipe can be short, so chunks differ in size and one full read can make several old chunks superfluous. The leftovers were then printed, so `tail -c 100` could output up to 8192 * 100 bytes. Evict every chunk that is no longer needed after each read, and add a unit test with a reader that returns short reads followed by full ones. Closes uutils#15804
This branch has not been deployed
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.
Closes #15804
When reading from a pipe,
BytesChunkBuffer::fillstores eachread()as its own chunk but removed at most one old chunk per read. If the first reads are short and later ones are full, the old chunks pile up and get printed, sotail -c 100could print 819200 bytes.The fix drops every chunk that is no longer needed after each read (
if→while). I added a unit test with a reader that returns 101 one-byte reads followed by full 8 KiB reads; it fails without the change. The reproducer from the issue now prints 100 bytes, andtest_tailpasses.This doesn't address the separate memory use from many short reads mentioned in the issue.