gh-139400: Make sure that parent parsers outlive their subparsers in pyexpat#139403
gh-139400: Make sure that parent parsers outlive their subparsers in pyexpat#139403picnixz merged 22 commits intopython:mainfrom
pyexpat#139403Conversation
Within libexpat, a parser created via XML_ExternalEntityParserCreate is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected by CPython. This fixes related reference counting, to stop that from happening.
picnixz
left a comment
There was a problem hiding this comment.
Now, this looks like Tcl/Tk and their callbacks. If you want to check for reference leaks, you should also run the tests with -R (python -m test -R the_test)
@picnixz I'm not sure what that means 😃
I cannot figure out why or what to do with |
Sorry, to be precise the $ ./python -m test test_pyexpat -m test_parent_parser_outlives_its_subparsers -R : |
Tcl/Tk is a graphic library that allows to have delayed callbacks and the callback data is the Python object. Here, for Expat, the handler data is the XML parser itself as well. I wanted to make a parallel between those two constructions. |
picnixz
left a comment
There was a problem hiding this comment.
I'm a bit tired (it's 01:33 AM here) so the review might not be perfect. I'll have another look tomorrow.
@picnixz after a recompile with |
@picnixz no worries, same UTC+2 here. Thank you! 👍 👍 |
|
Related: libexpat/libexpat#1066 |
Misc/NEWS.d/next/Core_and_Builtins/2025-09-29-00-01-28.gh-issue-139400.X2T-jO.rst
Outdated
Show resolved
Hide resolved
As suggested by @picnixz
Suggested by @picnixz
|
Lucky me, 3.14 has a clean backport :) |
|
@hartwork Could you make the backports for 3.10-3.13 please? I'm not on my dev session now (sorry for bothering you with this). |
|
@picnixz thanks for your help getting this over the finish line 🙏 🎉 I can look into the backports for this and report back if I hit any roadblocks. |
|
Thank you for writing libexpat :') |
…rs in `pyexpat` (python#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
|
GH-139608 is a backport of this pull request to the 3.13 branch. |
…rs in `pyexpat` (python#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
|
GH-139609 is a backport of this pull request to the 3.12 branch. |
…rs in `pyexpat` (python#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
|
GH-139612 is a backport of this pull request to the 3.11 branch. |
|
GH-139608 is a backport of this pull request to the 3.13 branch. |
|
GH-139609 is a backport of this pull request to the 3.12 branch. |
|
GH-139612 is a backport of this pull request to the 3.11 branch. |
…rs in `pyexpat` (python#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
|
GH-139613 is a backport of this pull request to the 3.10 branch. |
…rs in `pyexpat` (python#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
|
GH-139614 is a backport of this pull request to the 3.9 branch. |
…ers in `pyexpat` (GH-139403) (GH-139608) Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
…ers in `pyexpat` (GH-139403) (#139612) * gh-139400: Make sure that parent parsers outlive their subparsers in `pyexpat` (#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd) * Move news item from section "Core and Builtins" to section "Security"
…ers in `pyexpat` (GH-139403) (#139613) * gh-139400: Make sure that parent parsers outlive their subparsers in `pyexpat` (#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd) * Move news item to from section "Core and Builtins" to section "Security"
|
…rs in `pyexpat` (python#139403) * Modules/pyexpat.c: Disallow collection of in-use parent parsers. Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early.
…rs in `pyexpat` (GH-139403) (GH-139614) Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
…ers in `pyexpat` (GH-139403) (GH-139609) Within libexpat, a parser created via `XML_ExternalEntityParserCreate` is relying on its parent parser throughout its entire lifetime. Prior to this fix, is was possible for the parent parser to be garbage-collected too early. (cherry picked from commit 6edb2dd)
CC @picnixz
pyexpatrelated to.ExternalEntityParserCreate#139400