Skip to content

Commit 2a4a62b

Browse files
authored
bpo-33720: Reduces maximum marshal recursion depth on release builds. (GH-7401)
1 parent b609e68 commit 2a4a62b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Lib/test/test_marshal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ def test_recursion_limit(self):
222222
# Create a deeply nested structure.
223223
head = last = []
224224
# The max stack depth should match the value in Python/marshal.c.
225-
if os.name == 'nt' and hasattr(sys, 'gettotalrefcount'):
225+
# BUG: https://bugs.python.org/issue33720
226+
# Windows always limits the maximum depth on release and debug builds
227+
#if os.name == 'nt' and hasattr(sys, 'gettotalrefcount'):
228+
if os.name == 'nt':
226229
MAX_MARSHAL_STACK_DEPTH = 1000
227230
else:
228231
MAX_MARSHAL_STACK_DEPTH = 2000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduces maximum marshal recursion depth on release builds.

Python/marshal.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ module marshal
2525
* and risks coring the interpreter. When the object stack gets this deep,
2626
* raise an exception instead of continuing.
2727
* On Windows debug builds, reduce this value.
28+
*
29+
* BUG: https://bugs.python.org/issue33720
30+
* On Windows PGO builds, the r_object function overallocates its stack and
31+
* can cause a stack overflow. We reduce the maximum depth for all Windows
32+
* releases to protect against this.
33+
* #if defined(MS_WINDOWS) && defined(_DEBUG)
2834
*/
29-
#if defined(MS_WINDOWS) && defined(_DEBUG)
35+
#if defined(MS_WINDOWS)
3036
#define MAX_MARSHAL_STACK_DEPTH 1000
3137
#else
3238
#define MAX_MARSHAL_STACK_DEPTH 2000

0 commit comments

Comments
 (0)