Skip to content

pyexpat: CPython can be crashed through resetting StartDoctypeDeclHandler with pyexpat at the wrong time #160442

Open

Description

@hartwork

Hello!

It has been brought to my attention that the Expat XML parser can be crashed via a segmentation fault by resetting member StartDoctypeDeclHandler at the wrong time, like this:

from xml.parsers.expat import ParserCreate

parser = ParserCreate()

def reset_start_doctype_handler():
    parser.StartDoctypeDeclHandler = None
    return True

parser.StartDoctypeDeclHandler = lambda *_: None
parser.NotStandaloneHandler = reset_start_doctype_handler

parser.Parse(b"<!DOCTYPE r SYSTEM \"s\"><r/>", True)

This affects all versions of Python with all versions of Expat up to 2.9.0 including. Expat upstream pull request libexpat/libexpat#1437 fixes this issue for itself and CPython and the fix will be contained in the next release that may come out as early as next Monday. So updating to the next release will fix this for Python for free, I just wanted to let you know.

Credits for this finding go to Bartłomiej Dmitruk (@hackerman70000) of https://www.striga.ai/ .

Bartłomiej reported this as defense-in-depth to me and we both do not consider this a vulnerability. If you come to difference conclusions, please let me know.

Best, Sebastian

CC @StanFromIreland @picnixz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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