Core and Builtins
-----------------
+- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
+ absurbly high.
+
- Issue #18942: sys._debugmallocstats() output was damaged on Windows.
- Issue #18667: Add missing "HAVE_FCHOWNAT" symbol to posix._have_functions.
asdl_seq *seq;
int i;
PyThreadState *tstate;
+ int recursion_limit = Py_GetRecursionLimit();
if (st == NULL)
return st;
PySymtable_Free(st);
return NULL;
}
- st->recursion_depth = tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE;
- st->recursion_limit = Py_GetRecursionLimit() * COMPILER_STACK_FRAME_SCALE;
+ /* Be careful here to prevent overflow. */
+ st->recursion_depth = (tstate->recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
+ tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE : tstate->recursion_depth;
+ st->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
+ recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
/* Make the initial symbol information gathering pass */
if (!GET_IDENTIFIER(top) ||