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

stoeckmann

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.

@cpython-cla-bot

All commit authors signed the Contributor License Agreement.
CLA signed

@stoeckmann stoeckmann changed the title Use constant value check during runtime gh-91421: Use constant value check during runtime

Apr 10, 2022

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.

@stoeckmann

The blurb-it web tool required a bpo, but the command line tool blurb was already adjusted.

This looks good. One assembly instruction can be reduced.

@@ -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.

@miss-islington

Thanks @stoeckmann for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot

miss-islington pushed a commit to miss-islington/cpython that referenced this issue

Apr 13, 2022
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 pythonGH-91421.
(cherry picked from commit 0859368)

Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>

@bedevere-bot

gvanrossum pushed a commit to gvanrossum/cpython that referenced this issue

Apr 13, 2022
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 pythonGH-91421.

JelleZijlstra pushed a commit that referenced this issue

Apr 14, 2022
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 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, 2022
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 GH-91421.
(cherry picked from commit 0859368)

Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>