Repository navigation
Fix last crash when the count is too large to allocate - #19295
Merged
Merged
Conversation
`last` on a byte stream reserved a buffer as large as the requested count, so a count too large to allocate panicked with a capacity overflow. The buffer is already trimmed to the count after each read, so let it grow with the data that is actually read. Add tests for a huge count on a byte stream and on binary input. Signed-off-by: G. Manoj Kumar <[email protected]>
Contributor
|
Thanks |
fdncred
pushed a commit
that referenced
this pull request
Oct 20, 2026
…locate (#19296) ## Description `table --abbreviated` crashes when the count is too large to allocate. On current main: > 1..5 | table --abbreviated 9223372036854775807 panicked: capacity overflow > [[a]; [1]] | table --abbreviated 9223372036854775807 panicked: capacity overflow `stream_collect_abbreviated` reserves the head and the tail with `with_capacity(size)`, where `size` is the number the user typed. Both buffers only ever hold rows that are actually read, so they are now sized from the iterator's size hint: `head` reserves `hint.min(2 * size + 1)`, which is its final length with the `...` row, and `tail` reserves `hint.saturating_sub(size).min(size)`. Inputs without a hint, like a range or `every`, start empty and grow. The output doesn't change: a count larger than the input shows every row, as before. This is the same problem as #19286 (`chunks`), #19288 (`window`) and #19295 (`last`). I added tests that a huge count prints the same table as a normal count, for a plain list and for a list stream, and a huge-count range case in `table_abbreviation_cut`. I ran the `table::abbreviation` tests locally and they pass. I did not run the full workspace suite. AI assistance: I used Claude to help find the issue and draft the change. I reviewed and tested it myself. ## User-facing changes (Release notes) Fixed a crash when `table --abbreviated` is given a row count too large to allocate, such as 9223372036854775807. ## Additional notes n/a --------- Signed-off-by: G. Manoj Kumar <[email protected]>
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.
Description
lastcrashes on byte streams when the count is too large to allocate. On current main:It comes from
VecDeque::with_capacity(rows + TAKE as usize), whererowsis the number the user typed. The loop already drains the buffer down torowsafter every read, so the buffer only needs to grow with the data that is actually read.The buffer now starts empty, so memory use follows the data and not the argument. This is the same problem as #19286 (
chunks) and #19288 (window).I added tests for a huge count on a byte stream and on binary input, comparing the values. I ran the
lasttests locally and they pass. I did not run the full workspace suite.AI assistance: I used Claude to help find the issue and draft the change. I reviewed and tested it myself.
User-facing changes (Release notes)
Fixed a crash when
lastis given a count too large to allocate, such as 9223372036854775807, on byte stream input.Additional notes
n/a