Skip to content

[3.14] gh-161060: Fix pyexpat crash when the default handler is cleared (GH-161061) - #161846

Open
gpshead wants to merge 1 commit into
python:3.14from
gpshead:backport-0fbe3bb-3.14
Open

gpshead wants to merge 1 commit into
python:3.14from
gpshead:backport-0fbe3bb-3.14

Conversation

@gpshead

@gpshead gpshead commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Expat calls the default handler once per 1024-byte piece of a token that
needs encoding conversion. Install a no-op instead of NULL when the
handler is cleared after an error or unset from within a callback, as is
already done for the character data handler.

ANT-2026-0SJB3WWC
(cherry picked from commit 0fbe3bb)

Manual backport notes

Cherry-picked from the 3.15 backport (GH-161842) rather than from main; miss-islington's automatic 3.14 backport failed on conflicts. Both conflicts were in Modules/pyexpat.c:

  • RC_HANDLER macro: 3.15 calls invalid_expat_handler_rv() after Py_DECREF(rv), a helper that does not exist on 3.14. Only the fix itself was kept (self->in_callback = 0 moved to after the Py_DECREF(rv)); the helper was not brought over.
  • xmlparse_handler_setter: the context line on 3.14 lacked the (xmlhandler) cast.

… cleared (pythonGH-161061)

Expat calls the default handler once per 1024-byte piece of a token that
needs encoding conversion.  Install a no-op instead of NULL when the
handler is cleared after an error or unset from within a callback, as is
already done for the character data handler.

ANT-2026-0SJB3WWC
(cherry picked from commit 0fbe3bb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant