gh-111784: Add PyCapsule_ImportCapsule and fix segfault in _elementtree.c#112053
gh-111784: Add PyCapsule_ImportCapsule and fix segfault in _elementtree.c#112053Eclips4 wants to merge 1 commit intopython:mainfrom
PyCapsule_ImportCapsule and fix segfault in _elementtree.c#112053Conversation
|
@mgorny can you confirm that this fixes the issue? |
| "PyCapsule_Import \"%s\" is not valid", | ||
| name); | ||
| } | ||
| EXIT: |
There was a problem hiding this comment.
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.
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.
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
NEWSentry 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
pyexpatmodule._elementtree.XMLParser#111784