Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-25750: fix refcounts in type_getattro() #6118
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
the-knights-who-say-ni
Mar 14, 2018
Hello, and thanks for your contribution!
I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).
Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.
Thanks again to your contribution and we look forward to looking at it!
the-knights-who-say-ni
commented
Mar 14, 2018
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
the-knights-who-say-ni
added
the
CLA not signed
label
Mar 14, 2018
bedevere-bot
added
the
awaiting review
label
Mar 14, 2018
the-knights-who-say-ni
added
CLA signed
and removed
CLA not signed
labels
Mar 14, 2018
berkerpeksag
reviewed
Mar 23, 2018
In https://bugs.python.org/issue25750#msg255566 you said:
My patch does fix the crash in Lib/test/crashers/borrowed_ref_2.py on Python 2.7.10.
Is it possible to convert https://github.com/python/cpython/blob/2.7/Lib/test/crashers/borrowed_ref_2.py to a simple test case?
Thanks!
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Mar 24, 2018
Contributor
Is it possible to convert https://github.com/python/cpython/blob/2.7/Lib/test/crashers/borrowed_ref_2.py to a simple test case?
I can try, but I never managed to get the vanilla Python testsuite to pass on my system, so it's hard to test it myself.
I can try, but I never managed to get the vanilla Python testsuite to pass on my system, so it's hard to test it myself. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
berkerpeksag
Mar 24, 2018
Member
We can use Travis to test it :)
By the way, the test suite should pass on most systems. I suggest reporting test failures on your system on bugs.p.o.
We can use Travis to test it :) By the way, the test suite should pass on most systems. I suggest reporting test failures on your system on bugs.p.o. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Apr 2, 2018
Contributor
Is it possible to convert https://github.com/python/cpython/blob/2.7/Lib/test/crashers/borrowed_ref_2.py to a simple test case?
That example seems to crash only on Python 2, not Python 3. In fact, I do not know how to reproduce the crash on Python 3.
That example seems to crash only on Python 2, not Python 3. In fact, I do not know how to reproduce the crash on Python 3. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Apr 20, 2018
Contributor
I added a testcase. This was a lot harder to reproduce on Python 3.8 than Python 2.7, probably due to the changes regarding calling functions.
I added a testcase. This was a lot harder to reproduce on Python 3.8 than Python 2.7, probably due to the changes regarding calling functions. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Apr 20, 2018
Contributor
So, in some sense, the backport to Python 2.7 is more important than the fix to Python 3.8. The underlying issue is the same, it's just harder to accidentally hit it because of unrelated changes.
So, in some sense, the backport to Python 2.7 is more important than the fix to Python 3.8. The underlying issue is the same, it's just harder to accidentally hit it because of unrelated changes. |
timokau
referenced this pull request
Apr 26, 2018
Closed
python-2.7.14: Fix #27177 and #25750 #39555
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
@berkerpeksag Can you please finish the review of this PR? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Jul 5, 2018
Contributor
If you insist, here is a pure Python 3 reproducer:
import pickle
class Descr:
__get__ = pickle.dump
__set__ = None
class M(type):
def __int__(self):
self.write = None
return 0
class X(type, metaclass=M):
write = Descr()
class Y(metaclass=X):
pass
Y.write
However, this code is so artificial that it would be really strange to add it to the testsuite. I think that the current C code does a much better job of showing the error.
If you insist, here is a pure Python 3 reproducer:
However, this code is so artificial that it would be really strange to add it to the testsuite. I think that the current C code does a much better job of showing the error. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
I made the requested changes on the branch. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Jul 29, 2018
Contributor
if it's not possible to crash the interpreter in a pure Python 3 code, I wonder whether we should only fix this in Python 2.7.
First of all, it is possible to crash the interpreter using pickle.dump
as I demonstrated above.
Second, CPython is more than just the Python interpreter: even if a bug is only relevant for the Python/C API, it's still a bug that should be fixed.
So we can get this merged finally? It's an obvious bug fix, and I see nothing controversial about it.
First of all, it is possible to crash the interpreter using Second, CPython is more than just the Python interpreter: even if a bug is only relevant for the Python/C API, it's still a bug that should be fixed. So we can get this merged finally? It's an obvious bug fix, and I see nothing controversial about it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
@vstinner You obviously care about abusing borrowed references... |
vstinner
reviewed
Sep 5, 2018
The typeobject.c fix LGTM, but I'm not sure about the test. The test seems quite complicated and not reliable :-( Do we really have to add an unit test for that?
@serhiy-storchaka: Would you be ok to omit the test on such fix?
I dislike having a test doing "cls.descr = None" and "Create this large list to corrupt some unused memory". IMHO the test is too close to the exact C implementation.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
I added a testcase by request of @berkerpeksag |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Sep 5, 2018
Contributor
I dislike having a test doing "cls.descr = None"
Why? That is exactly the main point of the test (unless you prefer del cls.descr
?). Only the "Create this large list to corrupt some unused memory" part is hackish indeed.
Why? That is exactly the main point of the test (unless you prefer |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
vstinner
Sep 5, 2018
Member
I dislike having a test doing "cls.descr = None"
Why? That is exactly the main point of the test (unless you prefer del cls.descr?).
If it becomes part of the test suite, it means that we have to support this weird use case. I'm not sure that it should be part of the "language specification".
If it becomes part of the test suite, it means that we have to support this weird use case. I'm not sure that it should be part of the "language specification". |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
berkerpeksag
Sep 5, 2018
Member
The whole point of this issue and PR is that someone is already depending on this behavior. We already have tests for more rare cases (e.g. https://bugs.python.org/issue31781) than this one.
We could wrap the test with the @cpython_only
decorator if you think that the test is too close to the implementation.
The whole point of this issue and PR is that someone is already depending on this behavior. We already have tests for more rare cases (e.g. https://bugs.python.org/issue31781) than this one. We could wrap the test with the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Sep 6, 2018
Contributor
I'm not sure that it should be part of the "language specification".
So you think that doing cls.descr = None
is not part of the language specification? I would guess that adding/changing attributes of classes like that is a reasonable standard feature.
So you think that doing |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
vstinner
Sep 6, 2018
Member
I have no strong opinion on this change. I let someone else take a decision.
I have no strong opinion on this change. I let someone else take a decision. |
jdemeyer
referenced this pull request
Sep 6, 2018
Open
bpo-25750: add testcase on bad descriptor __get__() #9084
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdemeyer
Sep 6, 2018
Contributor
Since the testcase is apparently controversial, I decided to separate it as a new pull request: #9084
I really hope that this issue can now finally be fixed.
Since the testcase is apparently controversial, I decided to separate it as a new pull request: #9084 I really hope that this issue can now finally be fixed. |
vstinner
merged commit 8f73548
into
python:master
Sep 7, 2018
9 checks passed
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
miss-islington
commented
Sep 7, 2018
bedevere-bot
removed
the
awaiting review
label
Sep 7, 2018
added a commit
to miss-islington/cpython
that referenced
this pull request
Sep 7, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bedevere-bot
commented
Sep 7, 2018
GH-9087 is a backport of this pull request to the 3.7 branch. |
bedevere-bot
removed
needs backport to 3.7
needs backport to 3.6
labels
Sep 7, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bedevere-bot
commented
Sep 7, 2018
GH-9088 is a backport of this pull request to the 3.6 branch. |
added a commit
to miss-islington/cpython
that referenced
this pull request
Sep 7, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bedevere-bot
commented
Sep 7, 2018
GH-9089 is a backport of this pull request to the 2.7 branch. |
bedevere-bot
removed
the
needs backport to 2.7
label
Sep 7, 2018
added a commit
to miss-islington/cpython
that referenced
this pull request
Sep 7, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
vstinner
Sep 7, 2018
Member
Since the testcase is apparently controversial, I decided to separate it as a new pull request: #9084
I'm sorry for being picky :-(
I really hope that this issue can now finally be fixed.
Sure, I just merged it. miss-inlington bot created the 3 backports and I already approved them, they will be merged once the CI tests pass.
I'm sorry for being picky :-(
Sure, I just merged it. miss-inlington bot created the 3 backports and I already approved them, they will be merged once the CI tests pass. |
jdemeyer commentedMar 14, 2018
•
edited
When calling
tp_descr_get(attr, obj, type)
, make sure that we own a reference toattr
. In the existing code, we only have a borrowed reference.This bug goes back to at least Python 2.7, so ideally it should be backported to all previous versions.
https://bugs.python.org/issue25750
Downstream: https://trac.sagemath.org/ticket/19633