[Python-checkins] r58096 - in python/trunk: Lib/test/list_tests.py Misc/NEWS Objects/listobject.c
brett.cannon
python-checkins at python.org
Mon Sep 10 23:38:27 CEST 2007
Author: brett.cannon
Date: Mon Sep 10 23:38:27 2007
New Revision: 58096
Modified:
python/trunk/Lib/test/list_tests.py
python/trunk/Misc/NEWS
python/trunk/Objects/listobject.c
Log:
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
Modified: python/trunk/Lib/test/list_tests.py
==============================================================================
--- python/trunk/Lib/test/list_tests.py (original)
+++ python/trunk/Lib/test/list_tests.py Mon Sep 10 23:38:27 2007
@@ -46,6 +46,11 @@
self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")
+ l0 = []
+ for i in xrange(sys.getrecursionlimit() + 100):
+ l0 = [l0]
+ self.assertRaises(RuntimeError, repr, l0)
+
def test_print(self):
d = self.type2test(xrange(200))
d.append(d)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Mon Sep 10 23:38:27 2007
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Issue #1096: Prevent a segfault from getting the repr of a very deeply nested
+ list by using the recursion counter.
+
- Issue #1202533: Fix infinite recursion calls triggered by calls to
PyObject_Call() never calling back out to Python code to trigger recursion
depth updates/checks. Required the creation of a static RuntimeError
Modified: python/trunk/Objects/listobject.c
==============================================================================
--- python/trunk/Objects/listobject.c (original)
+++ python/trunk/Objects/listobject.c Mon Sep 10 23:38:27 2007
@@ -324,7 +324,10 @@
so must refetch the list size on each iteration. */
for (i = 0; i < Py_Size(v); ++i) {
int status;
+ if (Py_EnterRecursiveCall(" while getting the repr of a list"))
+ goto Done;
s = PyObject_Repr(v->ob_item[i]);
+ Py_LeaveRecursiveCall();
if (s == NULL)
goto Done;
status = PyList_Append(pieces, s);
More information about the Python-checkins
mailing list