Repository navigation
Reject negative parameter steps before expanding ranges - #951
Merged
sharkdp merged 1 commit intoOct 5, 2026
Merged
Conversation
Owner
|
Thank you |
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.
Reject negative
--parameter-step-sizevalues before expanding a range, preventing small invalid integer scans from growing until memory allocation fails. Report a clear error and document that the step must be positive.AI disclosure: prepared and tested with Codex (GPT-6 Astra, model label supplied by the user).
Before and after
Reproduction and implementation
On upstream master (
0f7ae35), this invalid scan starts generatingecho 0,echo -3,echo -6, … instead of rejecting the negative step:hyperfine --runs=1 -P n 0 1 --parameter-step-size=-3 'echo {n}'RangeStep::newrejects zero steps but not negative ones. Integer division in the size estimate rounds(1 - 0 + 1) / -3to zero, so the scan passes the size limit. Command construction then keeps appending values moving away from the upper bound. Under a 256 MiB address-space limit, both debug and release builds aborted with a memory allocation failure before running a benchmark. The single-value range-P n 0 0 --parameter-step-size=-2reproduces the same problem.The added check returns
Parameter step size must be positivebefore calculating the range size. Decimal negative steps get the same actionable diagnostic, replacing the misleadingParameter range is too largeerror. Zero-step behavior is preserved. The CLI help and man page state the positive-step requirement.This complements the positive-step overflow fixes proposed in #921 and #930; neither rejects negative steps in range construction.
Validation
Linux, Rust 1.97.0:
cargo test --locked --offline: 108 passed.cargo fmt -- --checkandcargo clippy --locked --offline --all-targets: passed.cargo build --locked --offline --release: passed.