Skip to content

Commit 6dfc9f5

Browse files
Sacul0457okiemute04
authored andcommitted
gh-145866 : Update JIT contributor list (GH-146170)
1 parent 52c0186 commit 6dfc9f5

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ The JIT avoids :term:`reference count`\ s where possible. This generally
13581358
reduces the cost of most operations in Python.
13591359

13601360
(Contributed by Ken Jin, Donghee Na, Zheao Li, Hai Zhu, Savannah Ostrowski,
1361-
Reiden Ong, Noam Cohen, Tomas Roun, PuQing, and Cajetan Rodrigues in :gh:`134584`.)
1361+
Reiden Ong, Noam Cohen, Tomas Roun, PuQing, Cajetan Rodrigues, and Sacul in :gh:`134584`.)
13621362

13631363
.. rubric:: Better machine code generation
13641364

Lib/test/test_pyexpat.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,42 @@ def test_parse_again(self):
276276
self.assertEqual(expat.ErrorString(cm.exception.code),
277277
expat.errors.XML_ERROR_FINISHED)
278278

279+
def test_reentrant_parse_crash(self):
280+
from xml.parsers import expat
281+
282+
p = expat.ParserCreate(encoding="utf-16")
283+
284+
def start(name, attrs):
285+
def handler(data):
286+
p.Parse(data, 0)
287+
288+
p.CharacterDataHandler = handler
289+
290+
p.StartElementHandler = start
291+
292+
data = b"\xff\xfe<\x00a\x00>\x00x\x00"
293+
with self.assertRaises(RuntimeError) as cm:
294+
for i in range(len(data)):
295+
try:
296+
p.Parse(data[i:i+1], i == len(data) - 1)
297+
except Exception as e:
298+
raise
299+
300+
self.assertEqual(str(cm.exception),
301+
"cannot call Parse() from within a handler")
302+
303+
304+
def test_parse_normal(self):
305+
from xml.parsers import expat
306+
307+
p = expat.ParserCreate()
308+
data = "<root><child/></root>".encode('utf-8')
309+
try:
310+
p.Parse(data, 1)
311+
except RuntimeError:
312+
self.fail("Parse() raised RuntimeError during normal operation")
313+
314+
279315
class NamespaceSeparatorTest(unittest.TestCase):
280316
def test_legal(self):
281317
# Tests that make sure we get errors when the namespace_separator value
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. gh-issue: 146174
2+
3+
.. section: Library
4+
5+
Prevent re-entrant calls to
6+
:meth:`~xml.parsers.expat.xmlparser.Parse`
7+
from within expat handlers, which could cause a crash. Now raises
8+
:exc:`RuntimeError` when such a call is attempted.

Modules/pyexpat.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,11 @@ pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
857857
PyObject *data, int isfinal)
858858
/*[clinic end generated code: output=8faffe07fe1f862a input=053e0f047e55c05a]*/
859859
{
860+
if (self->in_callback) {
861+
PyErr_SetString(PyExc_RuntimeError,
862+
"cannot call Parse() from within a handler");
863+
return NULL;
864+
}
860865
const char *s;
861866
Py_ssize_t slen;
862867
Py_buffer view;

0 commit comments

Comments
 (0)