]> git.ipfire.org Git - thirdparty/Python/cpython.git/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 fdd372d993ef7b1cfe0030a44a913bc0f0d80f49..fdb6fa835b4d144cd1684d5fba6bd9a2dc94893a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
+
 - Issue #16455: On FreeBSD and Solaris, if the locale is C, the
   ASCII/surrogateescape codec is now used, instead of the locale encoding, to
   decode the command line arguments. This change fixes inconsistencies with
index 605ad51e355381c48739ff2967951038d53fee37..8ea7c58aa8cd566ab533756199865f9466e1cfc5 100644 (file)
@@ -558,7 +558,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();
@@ -591,9 +591,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;