Skip to content

Fix BigInt exponentiation bypassing execution constraints#2350

Merged
lahma merged 1 commit into
sebastienros:mainfrom
lahma:fix-biginteger
Mar 22, 2026
Merged

Fix BigInt exponentiation bypassing execution constraints#2350
lahma merged 1 commit into
sebastienros:mainfrom
lahma:fix-biginteger

Conversation

@lahma

@lahma lahma commented Mar 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Validate estimated result bit length before calling BigInteger.Pow to prevent memory exhaustion from small inputs like 11n**711111111n
  • Limits BigInt exponentiation result to ~1 million bits (~125 KB), throwing RangeError: Maximum BigInt size exceeded for excessive sizes
  • Fixes missing negative exponent check in **= assignment operator

Fixes #2349

Test plan

  • Added tests for excessive BigInt exponentiation (** and **= operators)
  • Added tests verifying reasonable exponentiation still works (e.g. 2n ** 100n)
  • Added test for negative exponent throwing RangeError
  • Verified with exact reproduction from issue: 11n**711111111n now throws immediately
  • All 29 BigInt tests pass on both net10.0 and net472

🤖 Generated with Claude Code

…os#2349)

Validate estimated result size before calling BigInteger.Pow to prevent
memory exhaustion from inputs like 11n**711111111n. Limits result to
~1 million bits (~125 KB), throwing RangeError for excessive sizes.
Also fixes missing negative exponent check in **= assignment operator.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lahma
lahma enabled auto-merge (squash) March 22, 2026 18:09
@lahma
lahma merged commit c63dcc7 into sebastienros:main Mar 22, 2026
4 checks passed
@lahma
lahma deleted the fix-biginteger branch March 22, 2026 18:25
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.

BigInt exponentiation bypasses all execution constraints (LimitMemory, TimeoutInterval, MaxStatements)

1 participant