Skip to content

Commit 32ee57b

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

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,39 @@ 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+
p = expat.ParserCreate(encoding="utf-16")
282+
def start(name, attrs):
283+
284+
def handler(data):
285+
p.Parse(data, 0)
286+
p.CharacterDataHandler = handler
287+
288+
289+
p.StartElementHandler = start
290+
data = b"\xff\xfe<\x00a\x00>\x00x\x00"
291+
with self.assertRaises(RuntimeError) as cm:
292+
for i in range(len(data)):
293+
try:
294+
p.Parse(data[i:i+1], i == len(data) - 1)
295+
except Exception as e:
296+
raise
297+
298+
self.assertEqual(str(cm.exception),
299+
"cannot call Parse() from within a handler")
300+
301+
302+
def test_parse_normal(self):
303+
from xml.parsers import expat
304+
p = expat.ParserCreate()
305+
data = "<root><child/></root>".encode('utf-8')
306+
try:
307+
p.Parse(data, 1)
308+
except RuntimeError:
309+
self.fail("Parse() raised RuntimeError during normal operation")
310+
311+
279312
class NamespaceSeparatorTest(unittest.TestCase):
280313
def test_legal(self):
281314
# 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)