Repository navigation
Fix chunks crash when the chunk size is too large to allocate - #19286
Merged
Merged
Conversation
`chunks` reserved a buffer as large as the requested chunk size before reading any input. A size larger than the memory available panicked with a capacity overflow for lists and aborted with an allocation failure for binary input. Let the buffers grow with the data that is actually read instead, and add tests for a chunk size larger than the input. Signed-off-by: G. Manoj Kumar <[email protected]>
fdncred
reviewed
Oct 18, 2026
Contributor
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
Both allocation changes are correct, but the new tests skip the list stream and byte stream inputs, which crash on main too.
Findings: 0
Open (5)
Stream inputs with a huge chunk size have no test The binary test only checks the chunk countvec![first]plusextendallocates twice per chunk "Larger than the input" isn't what crashedwindow's gap path takes the same one-line fix. You mentionedwindowreadscapacity()as its window size. That's onlyWindowOverlapIter(window.rs:155).WindowGapIter::next(window.rs:221) doesVec::with_capacity(self.size)and compares againstself.size, so swapping inVec::new()there works as-is. On main,[1 2 3] | window 9223372036854775807 --stride 9223372036854775807panics through that path, and[1 2 3] | window 9223372036854775807panics through the overlap path. Fine for this PR or the follow-up.
Notes from my clanker, checked on 193370f. I didn't build the branch. The crash repros ran on a main release build (973c590), the suggested test expressions were checked there too, and the allocation counts come from a standalone Rust program.
Add tests for huge chunk sizes on list streams and byte streams, and compare the chunk contents in the binary test instead of only the count. Build each list chunk with `once(first).chain(..).collect()` so it allocates once instead of twice. Signed-off-by: G. Manoj Kumar <[email protected]>
chunks crash when the chunk size is larger than the inputchunks crash when the chunk size is too large to allocate
Contributor
Author
|
@fdncred good to go? thanks for the review btw :) pushed a follow-up commit with the stream tests, the value comparison, and the once/chain/collect change, and updated the title and release note. i'll send |
Contributor
|
Thanks! |
This was referenced Oct 19, 2026
fdncred
pushed a commit
that referenced
this pull request
Oct 19, 2026
## Description `last` crashes on byte streams when the count is too large to allocate. On current main: > random binary 16b | last 9223372036854775807 | length panicked: capacity overflow It comes from `VecDeque::with_capacity(rows + TAKE as usize)`, where `rows` is the number the user typed. The loop already drains the buffer down to `rows` after 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 `last` 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 `last` is given a count too large to allocate, such as 9223372036854775807, on byte stream input. ## Additional notes n/a Signed-off-by: G. Manoj Kumar <[email protected]>
fdncred
pushed a commit
that referenced
this pull request
Oct 20, 2026
) ## Description `window` crashes when the window size is too large to allocate. On current main: > [1 2 3] | window 9223372036854775807 panicked: capacity overflow > [1 2 3] | window 9223372036854775807 --stride 9223372036854775807 panicked: capacity overflow Both come from `Vec::with_capacity` taking the size the user typed. `WindowOverlapIter` reserved it in `new`, and `WindowGapIter` reserved it on every call to `next`. The overlapping iterator also used `self.window.capacity()` as the window size, so it depended on the reservation. It now keeps `size` as a field. The overlap buffer starts empty and is filled with `extend`, and the gap iterator collects its window, so neither reserves the typed size. This is the same problem that #19286 fixed for `chunks`. With `--remainder` and a stride equal to the size, `window` hands off to `chunks`, so that case works now too. I added tests for a huge size on a list, with a huge stride, on list streams (both iterators), and with `--remainder`, where they check the actual windows. I ran the `window` and `chunks` 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 `window` is given a window size too large to allocate, such as 9223372036854775807. ## Additional notes n/a --------- Signed-off-by: G. Manoj Kumar <[email protected]>
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
chunkscrashes when the chunk size is too large to allocate. On current main:The stream versions (
[0 1 2] | every 1 | chunks 9223372036854775807andrandom binary 16b | chunks 9223372036854775807) crash the same way, as pointed out in review.All of them come from
Vec::with_capacity(self.size), wheresizeis the number the user typed. The whole chunk size is reserved before any input is read.For lists, each chunk is now built with
once(first).chain(..).collect(). That has an exact size hint for list input, so it allocates once, and nothing is reserved from the user's number. For binary input,ChunkReadstarts with an empty buffer and grows it with the bytes it reads.Trade-off: stream and binary input now grow by doubling instead of one up-front allocation, so there is a bit more copying. Memory use follows the data, not the argument.
I added tests for a huge chunk size on a list, a list stream, a binary and a byte stream. I ran the
chunkstests locally and they pass. I did not run the full workspace suite.windowhas the same pattern and I'm sending it as a separate PR.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
chunksis given a chunk size too large to allocate, such as 9223372036854775807.Additional notes
n/a