]> granicus.if.org Git - python/commitdiff
Backport of r59241: str.decode fails on very long strings on 64bit platforms.
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 30 Nov 2007 21:53:17 +0000 (21:53 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 30 Nov 2007 21:53:17 +0000 (21:53 +0000)
PyArgs_ParseTuple t# and w# formats truncated the lengths to 32bit.

Lib/test/test_bigmem.py
Misc/NEWS
Python/getargs.c

index 6d6c37ceea6ba56faba0e10d5f4774bab906378f..d4fc6eb478510c495cc21bf181f6eaf717bb83f6 100644 (file)
@@ -65,13 +65,15 @@ class StrTest(unittest.TestCase):
         self.assertEquals(s.count('i'), 1)
         self.assertEquals(s.count('j'), 0)
 
-    @bigmemtest(minsize=0, memuse=1)
+    @bigmemtest(minsize=_2G + 2, memuse=3)
     def test_decode(self, size):
-        pass
+        s = '.' * size
+        self.assertEquals(len(s.decode('utf-8')), size)
 
-    @bigmemtest(minsize=0, memuse=1)
+    @bigmemtest(minsize=_2G + 2, memuse=3)
     def test_encode(self, size):
-        pass
+        s = u'.' * size
+        self.assertEquals(len(s.encode('utf-8')), size)
 
     @bigmemtest(minsize=_2G, memuse=2)
     def test_endswith(self, size):
index 30c45d142f0eb30d2cc044a7c5456fecf8d79844..2c9f5fd1a4547b4003a53200595ea19b742a0b1a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,11 @@ What's New in Python 2.5.2c1?
 Core and builtins
 -----------------
 
+- Issue #1521: On 64bit platforms, using PyArgs_ParseTuple with the t# of w#
+  format code incorrectly truncated the length to an int, even when
+  PY_SSIZE_T_CLEAN is set.  The str.decode method used to return incorrect
+  results with huge strings.
+
 - Issue #1445: Fix a SystemError when accessing the ``cell_contents`` 
   attribute of an empty cell object.
 
index d6255986327cd7b7d133ab1e5b16ea5b51801241..d94edce50b0a0fc1f9ddd026696ed82b73b498a8 100644 (file)
@@ -894,7 +894,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
                char **buffer;
                const char *encoding;
                PyObject *s;
-               int size, recode_strings;
+               Py_ssize_t size;
+               int recode_strings;
 
                /* Get 'e' parameter: the encoding name */
                encoding = (const char *)va_arg(*p_va, const char *);
@@ -1144,7 +1145,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
        case 'w': { /* memory buffer, read-write access */
                void **p = va_arg(*p_va, void **);
                PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
-               int count;
+               Py_ssize_t count;
                        
                if (pb == NULL || 
                    pb->bf_getwritebuffer == NULL ||
@@ -1166,7 +1167,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
        case 't': { /* 8-bit character buffer, read-only access */
                char **p = va_arg(*p_va, char **);
                PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
-               int count;
+               Py_ssize_t count;
                
                if (*format++ != '#')
                        return converterr(