GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Double `Py_DECREF` on parent parser in `pyexpat.xmlparser.ExternalEntityParserCreate` error paths · Issue #145989 · python/cpython Closed as duplicate Closed as duplicate Copy link Labels extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-XMLtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump DescriptionBug reportBug description:Bug Description
Py_DECREF(new_parser); Py_DECREF(self); But Additionally, Affected CodeThree error paths in Path A — buffer malloc failure (line ~1099): if (new_parser->buffer == NULL) { Py_DECREF(new_parser); // → dealloc → Py_CLEAR(parent) → DECREF self Py_DECREF(self); // ← double DECREF return PyErr_NoMemory(); } Path B — if (!new_parser->itself) { Py_DECREF(new_parser); // → dealloc → Py_CLEAR(parent) → DECREF self Py_DECREF(self); // ← double DECREF return PyErr_NoMemory(); } Path C — handlers malloc failure (line ~1119): if (!new_parser->handlers) { Py_DECREF(new_parser); // → dealloc → Py_CLEAR(parent) → DECREF self Py_DECREF(self); // ← double DECREF return PyErr_NoMemory(); } The root cause is that PoCTriggers Path A by setting a large """Minimal PoC: Double Py_DECREF in pyexpat ExternalEntityParserCreate""" import resource, xml.parsers.expat p = xml.parsers.expat.ParserCreate() p.SetParamEntityParsing(xml.parsers.expat.XML_PARAM_ENTITY_PARSING_ALWAYS) p.buffer_text = True p.buffer_size = 2**31 - 1 def handler(context, base, sysid, pubid): p.ExternalEntityParserCreate(context) return 1 p.ExternalEntityRefHandler = handler resource.setrlimit(resource.RLIMIT_AS, (1 << 30, 1 << 30)) p.Parse(b'<?xml version="1.0"?><!DOCTYPE f[<!ENTITY e SYSTEM "x">]><f>&e;</f>', True) Expected: Actual: GDB Backtrace (Python 3.14.2)The crash is at frame #5 ( Suggested FixRemove the three - Py_INCREF(self); ... - new_parser->parent = (PyObject *)self; + new_parser->parent = Py_NewRef(self); ... if (new_parser->buffer == NULL) { Py_DECREF(new_parser); - Py_DECREF(self); return PyErr_NoMemory(); } if (!new_parser->itself) { Py_DECREF(new_parser); - Py_DECREF(self); return PyErr_NoMemory(); } ... if (!new_parser->handlers) { Py_DECREF(new_parser); - Py_DECREF(self); return PyErr_NoMemory(); } VersionsSegfault reproduced on all tested versions:
Ive attached the full gdb backtrace of the crash below. CPython versions tested on:3.14 Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-XMLtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |