Skip to content

UAF in Element.findtext() when tag __eq__ mutates parent #148735

Closed

Description

@StanFromIreland

Crash report

What happened?

Similar to #126037.

from xml.etree.ElementTree import Element, SubElement

class T(str):
    def __eq__(self, other):
        root.clear()
        return True

root = Element('a')
SubElement(root, T('a')).text = str(object())
repr(root.findtext('a'))

Under UBSan results in:

Objects/object.c:766:19: runtime error: member access within misaligned address 0xdddddddddddddddd for type 'struct PyTypeObject', which requires 8 byte alignment
0xdddddddddddddddd: note: pointer points here
<memory cannot be printed>
Segmentation fault         (core dumped)

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Output from running 'python -VV' on the command line:

No response

Linked PRs

Activity

  1. added 3 commits that reference this issue on Apr 23, 2026
  2. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

extension-modulesC modules in the Modules dirtopic-XMLtype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions