-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Improve size validation in _Py_DecodeUTF8Ex #91421
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
Comments
This was referenced Apr 13, 2022
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
hello-adam
pushed a commit
to hello-adam/cpython
that referenced
this issue
Jun 2, 2022
…) (pythonGH-91493) 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 <[email protected]>
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The size check in _Py_DecodeUTF8Ex can be improved to always check against a constant value without further arithmetic involved. This is already done at other places within the file, e.g. here.
I was curious if this could actually be triggered with a proof of concept by overflowing the check and eventually performing an out of boundary heap access. And in fact, with a very artificial setup, it is possible on a 32 bit system which tries to convert a 2 GB long string:
I doubt that this is really reachable with actual code. But at least it is a good showcase that actual arithmetic is left over in the if-check. Let's remove it and save us this possible headache.
PS: Not sure if this is the correct way to create python issues with GitHub now. Let me know if something's missing or wrong!
The text was updated successfully, but these errors were encountered: