Skip to content

[release/11.0] Enforce BigInteger maximum length for shifts - #137427

Merged
tannergooding merged 1 commit into
dotnet:release/11.0from
tannergooding:tannergooding-backport-issue-137327
Nov 16, 2026
Merged

tannergooding merged 1 commit into
dotnet:release/11.0from
tannergooding:tannergooding-backport-issue-137327

Conversation

@tannergooding

@tannergooding tannergooding commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #137327

main PR #132709

Description

Guard inline and array-backed BigInteger left shifts before allocation so results exceeding the existing maximum limb count throw OverflowException. Add regression coverage for large shifts, BigInteger.Pow, int.MinValue right-shift reversal, and a carry that would exceed the limit.

Customer Impact

In .NET 11, oversized shifts can create invalid BigInteger values (about 256 MiB for the reported case). Later arithmetic may throw unexpectedly, and RotateLeft can return an incorrect result.

This was reported by a customer after the .NET 11 release, in BigInteger left shift no longer enforces the maximum length in .NET 11 (#137327).

Regression

Yes. .NET 11 accepts shifts whose results exceed the maximum length; .NET 10 throws OverflowException at the shift.

Testing

  • From the repository root, .\build.cmd clr+libs -rc release — passed baseline build.
  • From src\libraries\System.Runtime.Numerics\tests, dotnet build /t:Test — passed, 8,428 tests.
  • Before the fix, from the same test directory, dotnet build /t:Test /p:XunitMethodName=System.Numerics.Tests.BigIntegerPropertyTests.PowerOfTwoResultsRespectMaximumLength — failed as expected when the oversized value violated the maximum-length assertion.
  • From the repository root, .\build.cmd tasks -c Release and .\build.cmd clr+libs -rc release -lc release — passed Release test prerequisites.
  • The first Release test run could not start because its testhost had not yet been built; after building the prerequisites above, from the test directory, dotnet build /t:Test -c Release /p:XunitMethodName=System.Numerics.Tests.BigIntegerPropertyTests.PowerOfTwoResultsRespectMaximumLength — passed, 1 test.

Risk

Low. Only shifts whose computed limb count exceeds the existing maximum now throw before allocating. Normal-sized shift behavior is unchanged.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Resolves #137327

Note

This pull request description was drafted with GitHub Copilot.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression. We should do math operations with consistent behavior. Was this customer reported?

@jeffhandley jeffhandley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean backport of fix already made in main (.NET 12), addressing a customer-reported regression in .NET 11 with BigInteger left shift no longer enforces the maximum length in .NET 11 (#137327).

/cc @artl93 Yes, customer-reported after GA.

@ViveliDuCh

Copy link
Copy Markdown
Member

Hi,

the code complete date for 11.0.1 (the December 2026 release) is Monday 16 November. Make sure to merge this PR on that date at the latest, or it won't make it into that release.

As a reminder, if this is a product change, you also need Tactics approval before merging this PR (test-only or infra-only changes don't require Tactics approval).

Happy to help with the merge if needed!

@tannergooding

Copy link
Copy Markdown
Member Author

/ba-g unrelated http test abort

@tannergooding tannergooding added the Servicing-approved Approved for servicing release label Nov 16, 2026
@tannergooding
tannergooding merged commit 8a9c164 into dotnet:release/11.0 Nov 16, 2026
90 of 94 checks passed
@tannergooding
tannergooding deleted the tannergooding-backport-issue-137327 branch November 16, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Numerics Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants