Repository navigation
Fix window crash when the window size is too large to allocate - #19288
Conversation
`window` reserved a buffer as large as the requested window size, so a size too large to allocate panicked with a capacity overflow. The overlapping iterator also used the buffer's capacity as the window size. Keep the size in the iterator and let the buffers grow with the input, and add tests for a huge window size. Signed-off-by: G. Manoj Kumar <[email protected]>
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The Vec::new() changes fix both iterators, but --remainder with an equal stride still panics through chunks until #19286 lands, and the stream arm of the gap iterator has no test.
Findings: 0
Open (6)
--remainderwith an equal stride still panics No stream test for the gap iterator None of the huge-size tests check real windowscollectinstead ofVec::new()+extend No comment on the overlap buffer Same panic in two other commands. Not for this PR, but the samewith_capacity(<user number>)pattern panics inlaston byte streams (last.rs:318,VecDeque::with_capacity(rows + TAKE as usize)):random binary 16b | last 9223372036854775807. It also panics intable --abbreviatedon streams (table.rs:1079-1080):[1 2 3] | every 1 | table --abbreviated 9223372036854775807. Both crash with "capacity overflow" on main.
Notes from my clanker, checked on 7a8b7d0. Probes ran on the main release build 973c590; branch not built.
Collect the gap iterator window instead of reserving the user supplied size, document why the overlap iterator keeps its own size field, and add tests for list streams with a huge stride, and for real windows with `--remainder`. Signed-off-by: G. Manoj Kumar <[email protected]>
|
thank you @fdncred ! pushed a follow-up. i merged main so --remainder with an equal stride now goes through the fixed chunks, switched the gap iterator to collect, and added a stream test with a huge stride plus tests for --remainder that check the real windows. also added comments on the size field and the overlap buffer so nobody puts with_capacity back. updated the description too. window and chunks tests pass locally (37). |
## 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]>
|
please respond to each review comment to ensure nothing is missed |
|
responded to each review. thanks for pointing out ! |
|
Thanks |
…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]>



Description
windowcrashes when the window size is too large to allocate. On current main:Both come from
Vec::with_capacitytaking the size the user typed.WindowOverlapIterreserved it innew, andWindowGapIterreserved it on every call tonext.The overlapping iterator also used
self.window.capacity()as the window size, so it depended on the reservation. It now keepssizeas a field. The overlap buffer starts empty and is filled withextend, and the gap iterator collects its window, so neither reserves the typed size.This is the same problem that #19286 fixed for
chunks. With--remainderand a stride equal to the size,windowhands off tochunks, 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 thewindowandchunkstests 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
windowis given a window size too large to allocate, such as 9223372036854775807.Additional notes
n/a