gh-91421: Use constant value check during runtime by stoeckmann · Pull Request #91422 · python/cpython
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
The left-hand side expression of the if-check can be converted to a
constant by the compiler, but the addition on the right-hand side is
performed during runtime.
Move the addition from the right-hand side to the left-hand side by
turning it into a subtraction there. Since the values are known to
be large enough to not turn negative, this is a safe operation.
Prevents a very unlikely integer overflow on 32 bit systems.
Fixes issue #91421.
stoeckmann
changed the title
Use constant value check during runtime
gh-91421: Use constant value check during runtime
Thanks, this looks right to me but I'll leave others some time to speak up if there's something I missed.
This will need a NEWS entry, which you can add using blurb: https://devguide.python.org/?highlight=blurb#quick-reference. We're still working on updating some bpo references there, but I believe the blurb-it online tool has already been updated to point to GitHub.
| @@ -0,0 +1 @@ | |||
| Use constant value check during runtime in _Py_DecodeUTF8Ex. | |||
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Use constant value check during runtime in _Py_DecodeUTF8Ex. | |
| Fix a potential integer overflow in _Py_DecodeUTF8Ex. |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted.
The left-hand side expression of the if-check can be converted to a constant by the compiler, but the addition on the right-hand side is performed during runtime. Move the addition from the right-hand side to the left-hand side by turning it into a subtraction there. Since the values are known to be large enough to not turn negative, this is a safe operation. Prevents a very unlikely integer overflow on 32 bit systems.
Thanks @stoeckmann for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖
miss-islington pushed a commit to miss-islington/cpython that referenced this issue
Apr 13, 2022The left-hand side expression of the if-check can be converted to a constant by the compiler, but the addition on the right-hand side is performed during runtime. Move the addition from the right-hand side to the left-hand side by turning it into a subtraction there. Since the values are known to be large enough to not turn negative, this is a safe operation. Prevents a very unlikely integer overflow on 32 bit systems. Fixes pythonGH-91421. (cherry picked from commit 0859368) Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>
gvanrossum pushed a commit to gvanrossum/cpython that referenced this issue
Apr 13, 2022The left-hand side expression of the if-check can be converted to a constant by the compiler, but the addition on the right-hand side is performed during runtime. Move the addition from the right-hand side to the left-hand side by turning it into a subtraction there. Since the values are known to be large enough to not turn negative, this is a safe operation. Prevents a very unlikely integer overflow on 32 bit systems. Fixes pythonGH-91421.
JelleZijlstra pushed a commit that referenced this issue
Apr 14, 2022The left-hand side expression of the if-check can be converted to a constant by the compiler, but the addition on the right-hand side is performed during runtime. Move the addition from the right-hand side to the left-hand side by turning it into a subtraction there. Since the values are known to be large enough to not turn negative, this is a safe operation. Prevents a very unlikely integer overflow on 32 bit systems. Fixes GH-91421. (cherry picked from commit 0859368) Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>
JelleZijlstra pushed a commit that referenced this issue
Apr 14, 2022The left-hand side expression of the if-check can be converted to a constant by the compiler, but the addition on the right-hand side is performed during runtime. Move the addition from the right-hand side to the left-hand side by turning it into a subtraction there. Since the values are known to be large enough to not turn negative, this is a safe operation. Prevents a very unlikely integer overflow on 32 bit systems. Fixes GH-91421. (cherry picked from commit 0859368) Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>