summaryrefslogtreecommitdiff
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-09-26 22:17:45 -0400
committerBenjamin Peterson <benjamin@python.org>2013-09-26 22:17:45 -0400
commit64112d583ff7faa77843f76dcd8a5c4d99575c62 (patch)
tree1ca49574128ebad68cdcbf4b407ae175cc0e7db6 /Python/symtable.c
parentb6a57a1dd6f0eb8a75fb6158990c6354e4f5dbe9 (diff)
downloadcpython-64112d583ff7faa77843f76dcd8a5c4d99575c62.tar.gz
don't scale compiler stack frames if the recursion limit is huge (closes #19098)
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 48495f72a2..1e13b790de 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -239,6 +239,7 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
asdl_seq *seq;
int i;
PyThreadState *tstate;
+ int recursion_limit = Py_GetRecursionLimit();
if (st == NULL)
return st;
@@ -251,8 +252,11 @@ PySymtable_Build(mod_ty mod, const char *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) ||