Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 305e5aa

Browse files
committed
don't scale compiler stack frames if the recursion limit is huge (closes #19098)
1 parent 369606d commit 305e5aa

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.3.3 release candidate 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
16+
absurbly high.
17+
1518
- Issue #18942: sys._debugmallocstats() output was damaged on Windows.
1619

1720
- Issue #18667: Add missing "HAVE_FCHOWNAT" symbol to posix._have_functions.

Python/symtable.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
239239
asdl_seq *seq;
240240
int i;
241241
PyThreadState *tstate;
242+
int recursion_limit = Py_GetRecursionLimit();
242243

243244
if (st == NULL)
244245
return st;
@@ -251,8 +252,11 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
251252
PySymtable_Free(st);
252253
return NULL;
253254
}
254-
st->recursion_depth = tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE;
255-
st->recursion_limit = Py_GetRecursionLimit() * COMPILER_STACK_FRAME_SCALE;
255+
/* Be careful here to prevent overflow. */
256+
st->recursion_depth = (tstate->recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
257+
tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE : tstate->recursion_depth;
258+
st->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
259+
recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
256260

257261
/* Make the initial symbol information gathering pass */
258262
if (!GET_IDENTIFIER(top) ||

0 commit comments

Comments
 (0)