Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c44057d

Browse files
committed
Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB
1 parent 549d465 commit c44057d

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
@@ -10,6 +10,8 @@ What's New in Python 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
14+
1315
- Issue #16455: On FreeBSD and Solaris, if the locale is C, the
1416
ASCII/surrogateescape codec is now used, instead of the locale encoding, to
1517
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
@@ -558,7 +558,7 @@ fileio_readall(fileio *self)
558558
{
559559
PyObject *result;
560560
Py_ssize_t total = 0;
561-
int n;
561+
Py_ssize_t n;
562562

563563
if (self->fd < 0)
564564
return err_closed();
@@ -591,9 +591,18 @@ fileio_readall(fileio *self)
591591
}
592592
Py_BEGIN_ALLOW_THREADS
593593
errno = 0;
594+
n = newsize - total;
595+
#if defined(MS_WIN64) || defined(MS_WINDOWS)
596+
if (n > INT_MAX)
597+
n = INT_MAX;
598+
n = read(self->fd,
599+
PyBytes_AS_STRING(result) + total,
600+
(int)n);
601+
#else
594602
n = read(self->fd,
595603
PyBytes_AS_STRING(result) + total,
596-
newsize - total);
604+
n);
605+
#endif
597606
Py_END_ALLOW_THREADS
598607
if (n == 0)
599608
break;

0 commit comments

Comments
 (0)