summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-09-27 02:17:45 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-09-27 02:17:45 (GMT)
commit305e5aac85d8350ef8501b5e53b91555b3d75b84 (patch)
tree1632538a3c15998556a7911e8d9cdd63c7085b58
parent369606df2f9235e8e9bce1feabf1ac48c889f8d5 (diff)
downloadcpython-305e5aac85d8350ef8501b5e53b91555b3d75b84.zip
cpython-305e5aac85d8350ef8501b5e53b91555b3d75b84.tar.gz
cpython-305e5aac85d8350ef8501b5e53b91555b3d75b84.tar.bz2
don't scale compiler stack frames if the recursion limit is huge (closes #19098)
-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 3b232f2..e7910f3 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.3.3 release candidate 1?
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.
diff --git a/Python/symtable.c b/Python/symtable.c
index 48495f7..1e13b790 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) ||