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

Skip to content

Commit c30d058

Browse files
committed
merge 3.3 (#19098)
2 parents 1891cff + 305e5aa commit c30d058

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
@@ -9,6 +9,9 @@ Core and Builtins
99

1010
- Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional.
1111

12+
- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
13+
absurbly high.
14+
1215
Library
1316
-------
1417

Python/symtable.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *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 NULL;
@@ -256,8 +257,11 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
256257
PySymtable_Free(st);
257258
return NULL;
258259
}
259-
st->recursion_depth = tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE;
260-
st->recursion_limit = Py_GetRecursionLimit() * COMPILER_STACK_FRAME_SCALE;
260+
/* Be careful here to prevent overflow. */
261+
st->recursion_depth = (tstate->recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
262+
tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE : tstate->recursion_depth;
263+
st->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
264+
recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
261265

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

0 commit comments

Comments
 (0)