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

Skip to content

Commit d9fc85d

Browse files
author
Victor Stinner
committed
(merge 3.2) Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
2 parents 9797e29 + c655a72 commit d9fc85d

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.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
14+
1315
- Issue #9642: Uniformize the tests on the availability of the mbcs codec, add
1416
a new HAVE_MBCS define.
1517

@@ -1327,7 +1329,7 @@ Core and Builtins
13271329
(length bigger than 2^31-1 bytes).
13281330

13291331
- Issue #9015, #9611: FileIO.readinto(), FileIO.write(), os.write() and
1330-
stdprinter.write() clamp the length to 2^31-1 on Windows.
1332+
stdprinter.write() clamp the length to INT_MAX on Windows.
13311333

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

Modules/_io/fileio.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ fileio_read(fileio *self, PyObject *args)
687687
return fileio_readall(self);
688688
}
689689

690+
#if defined(MS_WIN64) || defined(MS_WINDOWS)
691+
if (size > INT_MAX)
692+
size = INT_MAX;
693+
#endif
690694
bytes = PyBytes_FromStringAndSize(NULL, size);
691695
if (bytes == NULL)
692696
return NULL;
@@ -695,7 +699,11 @@ fileio_read(fileio *self, PyObject *args)
695699
if (_PyVerify_fd(self->fd)) {
696700
Py_BEGIN_ALLOW_THREADS
697701
errno = 0;
702+
#if defined(MS_WIN64) || defined(MS_WINDOWS)
703+
n = read(self->fd, ptr, (int)size);
704+
#else
698705
n = read(self->fd, ptr, size);
706+
#endif
699707
Py_END_ALLOW_THREADS
700708
} else
701709
n = -1;

0 commit comments

Comments
 (0)