Skip to content

Commit c51866d

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

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,40 @@ def test_parse_again(self):
275275
parser.ParseFile(file)
276276
self.assertEqual(expat.ErrorString(cm.exception.code),
277277
expat.errors.XML_ERROR_FINISHED)
278+
279+
def test_reentrant_parse_crash(self):
280+
from xml.parsers import expat
281+
import sys
282+
p = expat.ParserCreate(encoding="utf-16")
283+
def start(name, attrs):
284+
285+
def handler(data):
286+
p.Parse(data, 0)
287+
p.CharacterDataHandler = handler
288+
289+
290+
p.StartElementHandler = start
291+
data = b"\xff\xfe<\x00a\x00>\x00x\x00"
292+
with self.assertRaises(RuntimeError) as cm:
293+
for i in range(len(data)):
294+
try:
295+
p.Parse(data[i:i+1], i == len(data) - 1)
296+
except Exception as e:
297+
raise
298+
299+
self.assertEqual(str(cm.exception),
300+
"cannot call Parse() from within a handler")
301+
302+
303+
def test_parse_normal(self):
304+
from xml.parsers import expat
305+
p = expat.ParserCreate()
306+
data = "<root><child/></root>".encode('utf-8')
307+
try:
308+
p.Parse(data, 1)
309+
except RuntimeError:
310+
self.fail("Parse() raised RuntimeError during normal operation")
311+
278312

279313
class NamespaceSeparatorTest(unittest.TestCase):
280314
def test_legal(self):

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)