-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-35193: Fix an off by one error in the RETURN_VALUE case. #10418
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
By doing a bounds check within find_op so it can return before going past the end as a safety measure. python@7db3c48#diff-a33329ae6ae0bb295d742f0caf93c137 introduced this off by one error while fixing another one nearby.
@@ -417,7 +419,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, | |||
} | |||
if (h > i + 1) { | |||
fill_nops(codestr, i + 1, h); | |||
nexti = find_op(codestr, h); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be simpler to just add a condition in this line?
nexti = (h < codelen) ? find_op(codestr, h) : codelen;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would leave room for the same bug to be introduced in other calls to find_op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other calls find_op()
can't be called with codelen
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's why I said "introduced". this prevents the bug from reappearing when the rest of the code changes.
I don't see how to test for the presence of this out of bounds memory access issue itself from the level of the CPython interpreter, but this test will reliably fail (crash) when the interpreter is built using the clang memory sanitizer.
Fix an off by one error in the bytecode peephole optimizer where it could read | ||
bytes beyond the end of bounds of a bytecode array when removing unreachable | ||
code after a return. This did not always crash an interpreter, but could. | ||
An interpreter compiled using the clang memory sanitizer always failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little longer and more detailed than most news entries... not sure if that's good or bad.
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
GH-10421 is a backport of this pull request to the 3.7 branch. |
Sorry, @gpshead, I could not cleanly backport this to |
…H-10418) Fix an off by one error in the peephole optimizer when checking for unreachable code beyond a return. Do a bounds check within find_op so it can return before going past the end as a safety measure. python@7db3c488335168993689ddae5914a28e16188447GH-diff-a33329ae6ae0bb295d742f0caf93c137 introduced this off by one error while fixing another one nearby. This bug was shipped in all Python 3.6 and 3.7 releases. The included unittest won't fail unless you do a clang msan build. (cherry picked from commit 49fa4a9) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Fix an off by one error in the peephole optimizer when checking for unreachable code beyond a return. Do a bounds check within find_op so it can return before going past the end as a safety measure. 7db3c488335168993689ddae5914a28e16188447GH-diff-a33329ae6ae0bb295d742f0caf93c137 introduced this off by one error while fixing another one nearby. This bug was shipped in all Python 3.6 and 3.7 releases. The included unittest won't fail unless you do a clang msan build. (cherry picked from commit 49fa4a9) Co-authored-by: Gregory P. Smith <greg@krypto.org>
…H-10418) Fix an off by one error in the peephole optimizer when checking for unreachable code beyond a return. Do a bounds check within find_op so it can return before going past the end as a safety measure. python@7db3c48#diff-a33329ae6ae0bb295d742f0caf93c137 introduced this off by one error while fixing another one nearby. This bug was shipped in all Python 3.6 and 3.7 releases. The included unittest won't fail unless you do a clang msan build. (cherry picked from commit 49fa4a9)
GH-10422 is a backport of this pull request to the 3.6 branch. |
… (GH-10422) Fix an off by one error in the peephole optimizer when checking for unreachable code beyond a return. Do a bounds check within find_op so it can return before going past the end as a safety measure. 7db3c48#diff-a33329ae6ae0bb295d742f0caf93c137 introduced this off by one error while fixing another one nearby. This bug was shipped in all Python 3.6 and 3.7 releases. The included unittest won't fail unless you do a clang msan build. (cherry picked from commit 49fa4a9)
By doing a bounds check within find_op so it can
return before going past the end as a safety measure.
7db3c48#diff-a33329ae6ae0bb295d742f0caf93c137
introduced this off by one error while fixing another one nearby.
https://bugs.python.org/issue35193