From 99bcf5ce08d3f326e2a869bff2556ed363256737 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 8 Jun 2010 15:12:17 +0000 Subject: [PATCH] Merged revisions 81823,81835 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r81823 | benjamin.peterson | 2010-06-07 17:31:26 -0500 (Mon, 07 Jun 2010) | 9 lines Merged revisions 81820 via svnmerge from 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 ........ ................ r81835 | benjamin.peterson | 2010-06-08 09:57:22 -0500 (Tue, 08 Jun 2010) | 9 lines Merged revisions 81834 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81834 | benjamin.peterson | 2010-06-08 09:53:29 -0500 (Tue, 08 Jun 2010) | 1 line kill extra word ........ ................ --- Lib/test/test_unicode.py | 3 +++ Misc/NEWS | 3 +++ Objects/stringlib/string_format.h | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 6e4f0484a4d..75637f8f580 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -687,6 +687,9 @@ class UnicodeTest( 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]) diff --git a/Misc/NEWS b/Misc/NEWS index 92a7c65641e..5fe35fc4667 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.1.3? Core and Builtins ----------------- +- In the str.format(), raise a ValueError when indexes to arguments are too + large. + - Issue #8766: Initialize _warnings module before importing the first module. Fix a crash if an empty directory called "encodings" exists in sys.path. diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index ecb00a9a1e7..bc70e97be4b 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -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;