Skip to content

Fix window crash when the window size is too large to allocate - #19288

Merged
fdncred merged 3 commits into
nushell:mainfrom
manoj-1407:fix/window-large-size
Oct 20, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
manoj-1407:fix/window-large-size

Conversation

@manoj-1407

@manoj-1407 manoj-1407 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

`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]>

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 2 Medium severity · 4 Low severity

Open (6)

Notes from my clanker, checked on 7a8b7d0. Probes ran on the main release build 973c590; branch not built.

Comment thread crates/nu-command/src/filters/window.rs Resolved
Comment thread crates/nu-command/src/filters/window.rs Resolved
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]>
@manoj-1407
manoj-1407 requested a review from fdncred October 19, 2026 05:01
@manoj-1407

Copy link
Copy Markdown
Contributor Author

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).

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

fdncred commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

please respond to each review comment to ensure nothing is missed

@manoj-1407

Copy link
Copy Markdown
Contributor Author

responded to each review. thanks for pointing out !

@fdncred
fdncred merged commit ab78152 into nushell:main Oct 20, 2026
11 checks passed
@fdncred

fdncred commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 20, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 20, 2026
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]>
@manoj-1407
manoj-1407 deleted the fix/window-large-size branch October 20, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants