Skip to content

Prevent overflow in file-lines range normalization - #6993

Open
cuishuang wants to merge 1 commit into
rust-lang:mainfrom
cuishuang:main
Open

Prevent overflow in file-lines range normalization#6993
cuishuang wants to merge 1 commit into
rust-lang:mainfrom
cuishuang:main

Conversation

@cuishuang

Copy link
Copy Markdown
Contributor

Fixes #6992

Range::adjacent_to previously added one directly to user-controlled --file-lines upper bounds. An upper bound of usize::MAX could therefore panic when overflow checks were enabled or wrap in release builds.

The wrapping case could also incorrectly merge non-adjacent ranges because the JSON parser accepted line zero, despite --file-lines being documented as 1-based.

This change:

  • uses checked_add for range adjacency checks;
  • rejects zero-based and reversed ranges parsed from --file-lines;
  • keeps usize::MAX as a valid upper bound;
  • adds regression tests for maximum bounds and invalid ranges.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Jul 28, 2026
@ytmimi ytmimi added the UO-file_lines Unstable option: file_lines label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties. UO-file_lines Unstable option: file_lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--file-lines range normalization can overflow at usize::MAX

3 participants