Skip to content

Commit 6f84659

Browse files
committed
(Merge 3.2) Issue python#16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
2 parents 269b3ce + c44057d commit 6f84659

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎Misc/NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 3.3.1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
16+
1517
- Issue #16455: On FreeBSD and Solaris, if the locale is C, the
1618
ASCII/surrogateescape codec is now used, instead of the locale encoding, to
1719
decode the command line arguments. This change fixes inconsistencies with

‎Modules/_io/fileio.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ fileio_readall(fileio *self)
607607
#endif
608608
PyObject *result;
609609
Py_ssize_t total = 0;
610-
int n;
610+
Py_ssize_t n;
611611
size_t newsize;
612612

613613
if (self->fd < 0)
@@ -656,9 +656,18 @@ fileio_readall(fileio *self)
656656
}
657657
Py_BEGIN_ALLOW_THREADS
658658
errno = 0;
659+
n = newsize - total;
660+
#if defined(MS_WIN64) || defined(MS_WINDOWS)
661+
if (n > INT_MAX)
662+
n = INT_MAX;
663+
n = read(self->fd,
664+
PyBytes_AS_STRING(result) + total,
665+
(int)n);
666+
#else
659667
n = read(self->fd,
660668
PyBytes_AS_STRING(result) + total,
661-
newsize - total);
669+
n);
670+
#endif
662671
Py_END_ALLOW_THREADS
663672
if (n == 0)
664673
break;

0 commit comments

Comments
 (0)