[Python-checkins] cpython (2.7): Issue #13546: Fixed an overflow issue that could crash the intepreter when

amaury.forgeotdarc python-checkins at python.org
Wed Dec 7 21:51:15 CET 2011


http://hg.python.org/cpython/rev/57de1ad15c54
changeset: 73880:57de1ad15c54
branch: 2.7
parent: 73872:5910c385fab6
user: Amaury Forgeot d'Arc <amauryfa at gmail.com>
date: Wed Dec 07 21:46:48 2011 +0100
summary:
 Issue #13546: Fixed an overflow issue that could crash the intepreter when
calling sys.setrecursionlimit((1<<31)-1).
2.7 only.
files:
 Lib/test/test_sys.py | 12 ++++++++++++
 Misc/NEWS | 3 +++
 Python/errors.c | 6 ++++--
 3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -224,6 +224,18 @@
 self.assertEqual(sys.getrecursionlimit(), 10000)
 sys.setrecursionlimit(oldlimit)
 
+ self.assertRaises(OverflowError, sys.setrecursionlimit, 1 << 31)
+ try:
+ sys.setrecursionlimit((1 << 31) - 5)
+ try:
+ # issue13546: isinstance(e, ValueError) used to fail
+ # when the recursion limit is close to 1<<31
+ raise ValueError()
+ except ValueError, e:
+ pass
+ finally:
+ sys.setrecursionlimit(oldlimit)
+
 def test_getwindowsversion(self):
 # Raise SkipTest if sys doesn't have getwindowsversion attribute
 test.test_support.get_attribute(sys, "getwindowsversion")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
 Core and Builtins
 -----------------
 
+- Issue #13546: Fixed an overflow issue that could crash the intepreter when
+ calling sys.setrecursionlimit((1<<31)-1).
+
 - Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder
 already accepts them).
 
diff --git a/Python/errors.c b/Python/errors.c
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -111,9 +111,11 @@
 PyErr_Fetch(&exception, &value, &tb);
 /* Temporarily bump the recursion limit, so that in the most
 common case PyObject_IsSubclass will not raise a recursion
- error we have to ignore anyway. */
+ error we have to ignore anyway. Don't do it when the limit
+ is already insanely high, to avoid overflow */
 reclimit = Py_GetRecursionLimit();
- Py_SetRecursionLimit(reclimit + 5);
+ if (reclimit < (1 << 30))
+ Py_SetRecursionLimit(reclimit + 5);
 res = PyObject_IsSubclass(err, exc);
 Py_SetRecursionLimit(reclimit);
 /* This function must not fail, so print the error here */
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /