fix(iterator): stop silently truncating spread/Array.from at 100,000 elements (#7562) - #7567
Merged
Merged
Conversation
added 2 commits
August 7, 2026 05:12
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
📝 WalkthroughWalkthroughIterator drains now use a shared ChangesIterator drain truncation fix
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Fixes #7562.
The bug
[...m.values()]on a 250,000-entry Map returned 100,000 elements. No error, no warning — a plausible-looking wrong answer.Three drain loops in
array/iterator.rscarried a hardcodedfor _ in 0..100_000"safety limit" and simply fell out of the loop when it was hit, returning whatever had accumulated. This affected every spread,Array.from, and iterator-protocol drain — Maps, Sets, generators, user iterables alike.Same severity class as the JSON key-loss corruption fixed earlier (#7546): silent wrong output is worse than a crash, because nothing signals it.
The fix, and why not simply remove the limit
MAX_ITERATOR_DRAIN= JavaScript's own maximum array length (u32::MAX - 1). Every realistic workload is unaffected.RangeErrorinstead of truncating.Node applies no limit at all:
[...it]runs until the iterator finishes or the process runs out of memory. Matching that exactly would trade silent truncation for an unbounded loop on a runaway iterator — so I kept a bound but made it report itself. A visible, recoverable error is the right third option; returning short data is strictly worse than either hanging or throwing.Verification
test_gap_7562_iterator_no_truncation.ts— all three drain paths past the old bound (Map values/keys/entries and[...m], a 130k Set, a 120k generator), plus a small-iterator case to prove the common path is untouched. Byte-identical to node 26.5.1.cargo test -p perry-runtime --no-fail-fast: 1808 passed, 0 failed.raw_handle_debt.py998 (baseline),check_file_size.sh,check_test_registration.py,cargo fmt --all --checkall clean.Pre-existing — confirmed at
969b447cc. Found by themap_1minvestigation (#7561) while building its semantics matrix.CI has a deep repo-wide runner backlog and may not report; the above is local validation and I am not claiming CI green.
Summary by CodeRabbit
Bug Fixes
Map,Set, and generator iterators now preserve all values.RangeError.Tests
Chores
0.5.1319.