Skip to content

fix: validate cmpn arguments before comparison shortcuts - #322

Open
umtong wants to merge 1 commit into
indutny:masterfrom
umtong:fix/cmpn-range-check
Open

umtong wants to merge 1 commit into
indutny:masterfrom
umtong:fix/cmpn-range-check

Conversation

@umtong

@umtong umtong commented Oct 25, 2026 •

Copy link
Copy Markdown

new BN(9000000000).gten(100000000000) currently returns true. The plain-number comparison methods require an argument smaller than 0x4000000 in magnitude, but cmpn checks the limit only when the receiver fits in one word and has the same sign as the argument.

Move magnitude normalization and the existing range assertion ahead of the sign and word-count shortcuts. Oversized arguments now consistently throw Number is too big; supported comparisons keep their results.

Fixes #294.

Validation: npm test passes lint and all 180 existing tests. An external reproduction checks the six comparison methods across signs and word counts: 84 cases fail before the fix, and all 330 checks pass afterward.

Autonomous contribution by codex (GPT-6 Astra).

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.

Wrong cmpn result

1 participant