Skip to content

Reject oversized --parameter-scan ranges without overflowing i32 - #930

Open
00200200 wants to merge 2 commits into
sharkdp:masterfrom
00200200:reject-i32-parameter-scan-overflow
Open

00200200 wants to merge 2 commits into
sharkdp:masterfrom
00200200:reject-i32-parameter-scan-overflow

Conversation

@00200200

Copy link
Copy Markdown

--parameter-scan panics in debug builds (and wraps in release) when the range is so wide that (end - start + 1) / step overflows i32. That happens while computing the size hint, so the existing 100,000-parameter cap never gets a chance to reject the range.

$ hyperfine --parameter-scan x -2147483648 2147483647 true
thread 'main' panicked at src/parameter/range_step.rs:85:18:
attempt to subtract with overflow

A narrower but still huge span overflows on the + 1 instead:

$ hyperfine --parameter-scan x 0 2147483647 true
thread 'main' panicked at src/parameter/range_step.rs:85:17:
attempt to add with overflow

Integer scans now compute that count in i64 and return the usual "Parameter range is too large" error.

Related to #920. The next() overflow near i32::MAX is covered by #921; this is the remaining construction-time overflow called out in that review.

On master the two new unit tests panic with attempt to add/subtract with overflow. With this change they pass, along with the CLI test parameter_scan_full_i32_range_is_rejected. cargo test: 46 + 19 + 40.

range_step_size_hint evaluated (end - start + 1) / step in i32, so a
full-width scan panicked in debug (and wrapped in release) before the
MAX_PARAMETERS cap could reject it. Compute that count in i64 instead.
@00200200
00200200 force-pushed the reject-i32-parameter-scan-overflow branch from 5b660ef to c670f92 Compare October 5, 2026 11:52
Preserve the oversized parameter-scan fix and its regression test while retaining upstream's removal of speed_comparison_sort_order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant