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

Skip to content

Commit c655a72

Browse files
author
Victor Stinner
committed
Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
1 parent bb4a747 commit c655a72

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.2.2?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
14+
1315
- When a generator yields, do not retain the caller's exception state on the
1416
generator.
1517

@@ -908,7 +910,7 @@ Core and Builtins
908910
(length bigger than 2^31-1 bytes).
909911

910912
- Issue #9015, #9611: FileIO.readinto(), FileIO.write(), os.write() and
911-
stdprinter.write() clamp the length to 2^31-1 on Windows.
913+
stdprinter.write() clamp the length to INT_MAX on Windows.
912914

913915
- Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime()
914916
can now handle dates after 2038.

Modules/_io/fileio.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@ fileio_read(fileio *self, PyObject *args)
664664
return fileio_readall(self);
665665
}
666666

667+
#if defined(MS_WIN64) || defined(MS_WINDOWS)
668+
if (size > INT_MAX)
669+
size = INT_MAX;
670+
#endif
667671
bytes = PyBytes_FromStringAndSize(NULL, size);
668672
if (bytes == NULL)
669673
return NULL;
@@ -672,7 +676,11 @@ fileio_read(fileio *self, PyObject *args)
672676
if (_PyVerify_fd(self->fd)) {
673677
Py_BEGIN_ALLOW_THREADS
674678
errno = 0;
679+
#if defined(MS_WIN64) || defined(MS_WINDOWS)
680+
n = read(self->fd, ptr, (int)size);
681+
#else
675682
n = read(self->fd, ptr, size);
683+
#endif
676684
Py_END_ALLOW_THREADS
677685
} else
678686
n = -1;

0 commit comments

Comments
 (0)