]> granicus.if.org Git - python/commitdiff
Merged revisions 81820 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Mon, 7 Jun 2010 22:31:26 +0000 (22:31 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 7 Jun 2010 22:31:26 +0000 (22:31 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81820 | benjamin.peterson | 2010-06-07 17:23:23 -0500 (Mon, 07 Jun 2010) | 1 line

  correctly overflow when indexes are too large
........

Lib/test/test_unicode.py
Misc/NEWS
Objects/stringlib/string_format.h

index 4ac07123b86d6e7db25d9ebd854ba37baeebbd68..10714c82d56b7e24133e278b28eb648d3853840e 100644 (file)
@@ -681,6 +681,9 @@ class UnicodeTest(string_tests.CommonTest,
         self.assertRaises(IndexError, "{:}".format)
         self.assertRaises(IndexError, "{:s}".format)
         self.assertRaises(IndexError, "{}".format)
+        big = "23098475029384702983476098230754973209482573"
+        self.assertRaises(ValueError, ("{" + big + "}").format)
+        self.assertRaises(ValueError, ("{[" + big + "]}").format, [0])
 
         # issue 6089
         self.assertRaises(ValueError, "{0[0]x}".format, [None])
index d83af836e3a529b28433e97a2c29b0f3bf2759f0..fc3dd77997136fdfcbe2ef3abb62c6d62ef9debc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and Builtins
 - Issue #8837: Remove "O?" format of PyArg_Parse*() functions. The format is no
   used anymore and it was never documented.
 
+- In the str.format(), raise a ValueError when either indexes to arguments are
+  too large.
+
 - Issue #2844: Make int('42', n) consistently raise ValueError for
   invalid integers n (including n = -909).
 
index ecb00a9a1e7b6c1964b948676479540b7f6b2622..bc70e97be4ba47144b8842a99e977c2fb4340710 100644 (file)
@@ -373,6 +373,8 @@ FieldNameIterator_next(FieldNameIterator *self, int *is_attribute,
         if (_FieldNameIterator_item(self, name) == 0)
             return 0;
         *name_idx = get_integer(name);
+        if (*name_idx == -1 && PyErr_Occurred())
+            return 0;
         break;
     default:
         /* Invalid character follows ']' */
@@ -429,6 +431,8 @@ field_name_split(STRINGLIB_CHAR *ptr, Py_ssize_t len, SubString *first,
 
     /* see if "first" is an integer, in which case it's used as an index */
     *first_idx = get_integer(first);
+    if (*first_idx == -1 && PyErr_Occurred())
+        return 0;
 
     field_name_is_empty = first->ptr >= first->end;