Skip to content

Fix table --abbreviated crash when the row count is too large to allocate - #19296

Merged
fdncred merged 4 commits into
nushell:mainfrom
manoj-1407:fix/table-abbreviated-large-size
Oct 20, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
manoj-1407:fix/table-abbreviated-large-size

Conversation

@manoj-1407

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

Copy link
Copy Markdown
Contributor

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

`table --abbreviated` reserved the head and tail buffers with the
requested row count, so a count too large to allocate panicked with
a capacity overflow. The buffers only hold the rows that are actually
read, so let them grow instead.

Add tests that a huge count prints the same table as a normal one.

Signed-off-by: G. Manoj Kumar <[email protected]>
@manoj-1407 manoj-1407 changed the title Title: Fix table --abbreviated crash when the row count is too large to allocate Fix table --abbreviated crash when the row count is too large to allocate Oct 19, 2026
@fdncred

fdncred commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

You've added several PRs that change ::with_capacity() to ::new(). Does thatmean we'll have more allocations now? What about something like Vec::with_capacity(size.min(stream.size_hint().0)) or some other way to make all these changes have less allocations?

Reserve the head and tail buffers with the smaller of the requested
count and the stream's size hint, so a huge count no longer panics but
inputs with a known length still allocate once.

Signed-off-by: G. Manoj Kumar <[email protected]>
@fdncred

fdncred commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Probably all your other PRs that do the same thing need to be investigated this way too. What do you think?

@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 size.min(size_hint().0) cap fixes the panic for lists, ranges and streams, and the record path was already safe. The notes below make the reservation match what each buffer can hold and point the tests at the list input that actually uses the hint. None of them block the merge.

Findings: 0 High severity · 0 Medium severity · 5 Low severity

Open (5)

Notes from my clanker, checked on 565fb35. Read-only, branch not built; CI root jobs pass on Linux and Windows (macOS pending). The size hints were read from range.rs, list_stream.rs and every.rs, and {a: 1, b: 2} | table -a 9223372036854775807 prints normally on 0.116.2 while [[a]; [1]] | table -a 9223372036854775807 panics there, as the PR says.

Comment thread crates/nu-command/src/viewers/table.rs Resolved
Comment thread crates/nu-command/src/viewers/table.rs Resolved
Reserve the tail only for the rows left after the head, and the head
for its final length (the first rows, the `...` row and the tail), so
a cut table does not reallocate either buffer.

Test a plain list, which has a size hint, and drop the range test that
repeats what the cut test already checks.

Signed-off-by: G. Manoj Kumar <[email protected]>
Add the huge-count range case as one more assertion in
`table_abbreviation_cut` and name the two new tests with the file's
`table_abbreviation_` prefix.

Signed-off-by: G. Manoj Kumar <[email protected]>
@manoj-1407

Copy link
Copy Markdown
Contributor Author

answering the other concerns here :

  • "does that mean we’ll have more allocations now?" :
    yes, new() meant growing as it fills. it's sized from the iterator's size hint now, so a plain list allocates once and a huge count can't reserve more than the input has.

  • “all your other PRs that do the same thing need to be investigated too?”:

yes, fair. went through them again:

  • chunks on lists and window's gap iterator use collect, so one allocation from the hint
  • window's overlap buffer is filled with extend over a take, so on lists it reserves from the same hint
  • chunks on binary values reads from a cursor, so extend_from_slice should get the whole remaining slice in one go
  • where there is no hint to use (byte streams in chunks and last, and streams like every or ranges) the buffer starts empty and grows, since nothing tells us the length
    i haven't measured allocation counts, only read the code. happy to add follow-ups if you think any of these should change, otherwise i'll leave them.

@manoj-1407
manoj-1407 requested a review from fdncred October 20, 2026 06:34
@fdncred
fdncred merged commit 77726d8 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
@manoj-1407
manoj-1407 deleted the fix/table-abbreviated-large-size branch October 20, 2026 11:41
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 1, 2026
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