summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/symtable.c8
2 files changed, 9 insertions, 2 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index f39bd88..a2b230d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ Core and Builtins
- Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional.
+- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
+ absurbly high.
+
Library
-------
diff --git a/Python/symtable.c b/Python/symtable.c
index 618a814..da164aa 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -239,6 +239,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
asdl_seq *seq;
int i;
PyThreadState *tstate;
+ int recursion_limit = Py_GetRecursionLimit();
if (st == NULL)
return NULL;
@@ -256,8 +257,11 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
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) ||