(Merge 3.2) Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
diff --git a/Misc/NEWS b/Misc/NEWS
index 2877eed..e4fd504 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@
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
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 6e0bbee..ca25209 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -607,7 +607,7 @@
#endif
PyObject *result;
Py_ssize_t total = 0;
- int n;
+ Py_ssize_t n;
size_t newsize;
if (self->fd < 0)
@@ -656,9 +656,18 @@
}
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,
- newsize - total);
+ (int)n);
+#else
+ n = read(self->fd,
+ PyBytes_AS_STRING(result) + total,
+ n);
+#endif
Py_END_ALLOW_THREADS
if (n == 0)
break;