Skip to content

elementtree can abort on invalid XML bytes with UTF encoding #150560

@StanFromIreland

Description

@StanFromIreland

Crash report

What happened?

$ ./python -c "from io import BytesIO; from xml.etree.ElementTree import parse; parse(BytesIO(b'<?xml version=\"\" encoding=\"UTF\"?><a> \xd0 '))"
python: Objects/call.c:342: _PyObject_Call: Assertion `!_PyErr_Occurred(tstate)' failed.
Aborted                    (core dumped) ./python -c "from io import BytesIO; from xml.etree.ElementTree import parse; parse(BytesIO(b'<?xml version=\"\" encoding=\"UTF\"?><a> \xd0 '))"

Found by OSS-Fuzz in #517455264. I presumed this regression was introduced by 8ab7b43.

CC @serhiy-storchaka

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

Metadata

Metadata

Labels

extension-modulesC modules in the Modules dirtopic-XMLtype-crashA hard crash of the interpreter, possibly with a core dump
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions