-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-111784: Add PyCapsule_ImportCapsule
and fix segfault in _elementtree.c
#112053
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
@mgorny can you confirm that this fixes the issue? |
"PyCapsule_Import \"%s\" is not valid", | ||
name); | ||
} | ||
EXIT: |
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.
We don't need here Py_XDECREF(object)
as in the PyCapsule_Import
, because we do it later manually. So, we can control a process of capsule's deallocation
@Eclips4, it is reduced but not minimal :) |
Other, a bit hacky repro: import _elementtree
x = _elementtree.XMLParser()
import sys
del sys.modules['pyexpat'] Looks obvious in hindsight, as all what we need is to deallocate |
name); | ||
} | ||
EXIT: | ||
if (name_dup) { |
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.
name_dup
is always non-NULL here, as we return MemoryError
at line 236 if PyMem_Malloc
fails.
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.
It's not a final version 😅
Currently we just talking about idea, sadly, but this solution is incorrect :(
FYI, it's just copied from PyCapsule_Import
Yep, I thinking about the same. |
This PR fixes only one segfault (there's two segfaults actually) and way to fix this segfault is really weird. So I'm closing this. |
That's a PoC.
We can add a
NEWS
entry and doc about new public API later, if we consider this as the right solution.Also, I was incorrect in issue. We need to keep reference to the capsule, not
pyexpat
module._elementtree.XMLParser
#111784