Uh oh!
There was an error while loading. Please reload this page.
gh-139400: Make sure that parent parsers outlive their subparsers in pyexpat - #139403
Conversation
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)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hartwork
commented
Sep 28, 2025
@picnixz I'm not sure what that means 😃
I cannot figure out why or what to do with |
picnixz
commented
Sep 28, 2025
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hartwork
commented
Sep 28, 2025
@picnixz after a recompile with |
hartwork
commented
Sep 28, 2025
@picnixz no worries, same UTC+2 here. Thank you! 👍 👍 |
hartwork
commented
Sep 28, 2025
Related: libexpat/libexpat#1066 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
As suggested by @picnixz
Suggested by @picnixz
Uh oh!
There was an error while loading. Please reload this page.
picnixz
commented
Oct 5, 2025
Lucky me, 3.14 has a clean backport :) |
picnixz
commented
Oct 5, 2025
@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). |
hartwork
commented
Oct 5, 2025
@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. |
picnixz
commented
Oct 5, 2025
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"
bedevere-bot
commented
Oct 7, 2025
|
…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