]> granicus.if.org Git - python/commitdiff
Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 3 Jan 2013 02:33:21 +0000 (03:33 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 3 Jan 2013 02:33:21 +0000 (03:33 +0100)
Misc/NEWS
Modules/_io/fileio.c

index 224e45667aa18a9ab3110606e83fdb4bf2415ed9..097f205a102d167c4015c608bade3490dd8053ce 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,8 @@ What's New in Python 2.7.4
 Core and Builtins
 -----------------
 
+- Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
+
 - Issue #15516: Fix a bug in PyString_FromFormat where it failed to properly
   ignore errors from a __int__() method.
 
index 54116656012bc021feaf8a262fc56588bbe72552..7fe245491bb481f711e0c369ba128f3f4c0d29c8 100644 (file)
@@ -530,7 +530,7 @@ fileio_readall(fileio *self)
 {
     PyObject *result;
     Py_ssize_t total = 0;
-    int n;
+    Py_ssize_t n;
 
     if (self->fd < 0)
         return err_closed();
@@ -563,9 +563,18 @@ fileio_readall(fileio *self)
         }
         Py_BEGIN_ALLOW_THREADS
         errno = 0;
+        n = newsize - total;
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+        if (n > INT_MAX)
+            n = INT_MAX;
+        n = read(self->fd,
+                 PyBytes_AS_STRING(result) + total,
+                 (int)n);
+#else
         n = read(self->fd,
                  PyBytes_AS_STRING(result) + total,
-                 newsize - total);
+                 n);
+#endif
         Py_END_ALLOW_THREADS
         if (n == 0)
             break;