Skip to content

fix: compare oversized numeric prerelease IDs with big.Int - #211

Closed
BetterAndBetterII wants to merge 1 commit into
hashicorp:mainfrom
BetterAndBetterII:fix/prerelease-numeric-int64-overflow
Closed

BetterAndBetterII wants to merge 1 commit into
hashicorp:mainfrom
BetterAndBetterII:fix/prerelease-numeric-int64-overflow

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

comparePart used strconv.ParseInt, so digit-only prerelease identifiers larger than int64 fell back to string comparison. That made 1.2-99999999999999999999 sort after 1.2-100000000000000000000.

Parse both sides with math/big and use Cmp so SemVer numeric ordering still holds past int64.

Fixes #204

Test plan

  • go test -count=1 -run '^TestComparePreReleases$' .
  • go test -race -count=1 ./...
  • New cases cover the issue repro, int64 boundary, and numeric vs alphanumeric

strconv.ParseInt treated digit-only prerelease identifiers larger than
int64 as strings, so 1.2-999... sorted after 1.2-1000.... Parse with
math/big and Cmp so SemVer numeric ordering still holds past int64.

Fixes hashicorp#204
@hashicorp-cla-app

hashicorp-cla-app Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tgross

tgross commented Sep 3, 2026

Copy link
Copy Markdown
Member

More AI slop PRs

@tgross tgross closed this Sep 3, 2026
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.

Numeric prerelease identifiers larger than int64 are ordered incorrectly

2 participants