Skip to content

Commit adb61a2

Browse files
Update test
1 parent d3dd837 commit adb61a2

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Lib/test/test_pyexpat.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,19 +701,20 @@ def test_trigger_leak(self):
701701
parser.ElementDeclHandler = lambda _1, _2: None
702702
self.assertRaises(TypeError, parser.Parse, data, True)
703703

704+
@support.skip_if_unlimited_stack_size
705+
@support.skip_emscripten_stack_overflow()
706+
@support.skip_wasi_stack_overflow()
704707
def test_deeply_nested_content_model(self):
705708
data = ('<!DOCTYPE root [\n<!ELEMENT root '
706-
+ '(a, ' * 200000 + 'a'
707-
+ ')' * 200000
709+
+ '(a, ' * 500000 + 'a'
710+
+ ')' * 500000
708711
+ '>\n]>\n<root/>\n').encode('UTF-8')
709712

710713
parser = expat.ParserCreate()
711714
parser.ElementDeclHandler = lambda _1, _2: None
712-
# This shouldn't crash:
713-
try:
714-
parser.ParseFile(BytesIO(data))
715-
except RecursionError:
716-
pass
715+
with self.assertRaises(RecursionError):
716+
with support.infinite_recursion():
717+
parser.ParseFile(BytesIO(data))
717718

718719
class MalformedInputTest(unittest.TestCase):
719720
def test1(self):

Modules/pyexpat.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#endif
44

55
#include "Python.h"
6+
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
67
#include "pycore_import.h" // _PyImport_SetModule()
78
#include "pycore_pyhash.h" // _Py_HashSecret
89
#include "pycore_traceback.h" // _PyTraceback_Add()
@@ -607,7 +608,7 @@ static PyObject *
607608
conv_content_model(XML_Content * const model,
608609
PyObject *(*conv_string)(void *))
609610
{
610-
if (Py_EnterRecursiveCall(" in conv_content_model")) {
611+
if (_Py_EnterRecursiveCall(" in conv_content_model")) {
611612
return NULL;
612613
}
613614

@@ -631,7 +632,7 @@ conv_content_model(XML_Content * const model,
631632
conv_string, model->name, children);
632633
}
633634
done:
634-
Py_LeaveRecursiveCall();
635+
_Py_LeaveRecursiveCall();
635636
return result;
636637
}
637638

0 commit comments

Comments
 (0)