[Python-checkins] r55878 - in python/branches/release25-maint: Lib/test/string_tests.py Objects/stringobject.c Objects/unicodeobject.c

neal.norwitz python-checkins at python.org
Mon Jun 11 06:32:49 CEST 2007


Author: neal.norwitz
Date: Mon Jun 11 06:32:41 2007
New Revision: 55878

Modified:
   python/branches/release25-maint/Lib/test/string_tests.py
   python/branches/release25-maint/Objects/stringobject.c
   python/branches/release25-maint/Objects/unicodeobject.c
Log:
Backport 55874:
Fix a bug when there was a newline in the string expandtabs was called on.
This also catches another condition that can overflow.


Modified: python/branches/release25-maint/Lib/test/string_tests.py
==============================================================================
--- python/branches/release25-maint/Lib/test/string_tests.py	(original)
+++ python/branches/release25-maint/Lib/test/string_tests.py	Mon Jun 11 06:32:41 2007
@@ -247,8 +247,13 @@
         self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
         self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
         self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4)
+        self.checkequal('  a\n b', ' \ta\n\tb', 'expandtabs', 1)
 
         self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
+        # This test is only valid when sizeof(int) == sizeof(void*) == 4.
+        if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
+            self.checkraises(OverflowError,
+                             '\ta\n\tb', 'expandtabs', sys.maxint)
 
     def test_split(self):
         self.checkequal(['this', 'is', 'the', 'split', 'function'],

Modified: python/branches/release25-maint/Objects/stringobject.c
==============================================================================
--- python/branches/release25-maint/Objects/stringobject.c	(original)
+++ python/branches/release25-maint/Objects/stringobject.c	Mon Jun 11 06:32:41 2007
@@ -3313,7 +3313,8 @@
 	    if (tabsize > 0) {
 		j += tabsize - (j % tabsize);
 		if (old_j > j) {
-		    PyErr_SetString(PyExc_OverflowError, "new string is too long");
+		    PyErr_SetString(PyExc_OverflowError,
+				    "new string is too long");
 		    return NULL;
 		}
 		old_j = j;
@@ -3323,7 +3324,12 @@
             j++;
             if (*p == '\n' || *p == '\r') {
                 i += j;
-                j = 0;
+                old_j = j = 0;
+                if (i < 0) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "new string is too long");
+                    return NULL;
+                }
             }
         }
 

Modified: python/branches/release25-maint/Objects/unicodeobject.c
==============================================================================
--- python/branches/release25-maint/Objects/unicodeobject.c	(original)
+++ python/branches/release25-maint/Objects/unicodeobject.c	Mon Jun 11 06:32:41 2007
@@ -5701,7 +5701,8 @@
 	    if (tabsize > 0) {
 		j += tabsize - (j % tabsize);
 		if (old_j > j) {
-		    PyErr_SetString(PyExc_OverflowError, "new string is too long");
+		    PyErr_SetString(PyExc_OverflowError,
+				    "new string is too long");
 		    return NULL;
 		}
 		old_j = j;
@@ -5711,7 +5712,12 @@
             j++;
             if (*p == '\n' || *p == '\r') {
                 i += j;
-                j = 0;
+                old_j = j = 0;
+                if (i < 0) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "new string is too long");
+                    return NULL;
+                }
             }
         }
 


More information about the Python-checkins mailing list