-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/7.0] React to CheckForOverflowUnderflow in regex source generator #78256
Conversation
The regex source generator uses code patterns that might have arithmetic overflows, e.g. a bounds check with `(uint)index < span.Length`. These are intentional, and they're benign... unless the project/compilation has opted-in to overflow/underflow checking (CheckForOverflowUnderflow). In that case, the code for many patterns can start throwing false positive overflow exceptions, making the source generator unusable. This commit causes the generator to look at the CheckOverflow setting in the compilation options, and if it's set, to emit `unchecked { ... }` around all the relevant code.
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsBackport of #78228 to release/7.0 /cc @stephentoub Customer ImpactTestingRiskIMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary package authoring and gotten it explicitly reviewed.
|
@ViktorHofer, do I need to do anything here for package authoring? |
Shouldn't need to. Regex ships inbox as part of the shared framework, so no special packaging changes should be needed here. |
But the generator? |
Same, it ships in the targeting pack (ref pack) which ships with no need of doing package authoring. |
The net48 failure is a known issue and will be fixed via: #78250 |
Great, thanks |
As Joe said, both components ship eclusively inbox and therefore package authoring changes aren't required. |
Approved by Tactics. Signed off by area owners. CI failure is unrelated. No OOB package authoring changes needed. |
Backport of #78228 to release/7.0
Fixes #78214
/cc @stephentoub
Customer Impact
The regex source generator produces code that throws overflow exceptions when the CheckForOverflowUnderflow compiler option is set. It uses code patterns that overflow by design (e.g.
(uint)index < span.Length
). The fix simply surrounds the code withunchecked
.Testing
Changed most tests to use the more conservative /checked. Added new ones for covering various configurations of checked and unchecked in combination with other features.
Risk
Low.
IMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary package authoring and gotten it explicitly reviewed.