Mercurial > cpython-lru_cache-weakref
diff Python/symtable.c @ 85803:c3df31cbcd0a 3.3
don't scale compiler stack frames if the recursion limit is huge (closes #19098)
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Thu, 26 Sep 2013 22:17:45 -0400 |
| parents | 86783c4fd528 |
| children | 9a7ec433bf59 |
line wrap: on
line diff
--- a/Python/symtable.c Mon Sep 23 23:20:07 2013 +0300 +++ b/Python/symtable.c Thu Sep 26 22:17:45 2013 -0400 @@ -239,6 +239,7 @@ asdl_seq *seq; int i; PyThreadState *tstate; + int recursion_limit = Py_GetRecursionLimit(); if (st == NULL) return st; @@ -251,8 +252,11 @@ 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) ||
