summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-07-05 11:34:18 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-07-05 11:34:18 +0200
commitd9fc85db7f644c36d8709af49c97bed62451e59a (patch)
tree9299bedf9eff79d445e85096ab9d5729fc166546
parent9797e29f86eac1504a518ee5a4bf5b3b53c24c63 (diff)
parentc655a726dba5799e3c221b6c95fee72516d3d7cf (diff)
downloadcpython-git-d9fc85db7f644c36d8709af49c97bed62451e59a.tar.gz
(merge 3.2) Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
-rw-r--r--Misc/NEWS4
-rw-r--r--Modules/_io/fileio.c8
2 files changed, 11 insertions, 1 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index d4c92581ed..e5e188ed4f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
+- Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
+
- Issue #9642: Uniformize the tests on the availability of the mbcs codec, add
a new HAVE_MBCS define.
@@ -1327,7 +1329,7 @@ Core and Builtins
(length bigger than 2^31-1 bytes).
- Issue #9015, #9611: FileIO.readinto(), FileIO.write(), os.write() and
- stdprinter.write() clamp the length to 2^31-1 on Windows.
+ stdprinter.write() clamp the length to INT_MAX on Windows.
- Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime()
can now handle dates after 2038.
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index b3b9e44c29..3de1ff5b2d 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -687,6 +687,10 @@ fileio_read(fileio *self, PyObject *args)
return fileio_readall(self);
}
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+ if (size > INT_MAX)
+ size = INT_MAX;
+#endif
bytes = PyBytes_FromStringAndSize(NULL, size);
if (bytes == NULL)
return NULL;
@@ -695,7 +699,11 @@ fileio_read(fileio *self, PyObject *args)
if (_PyVerify_fd(self->fd)) {
Py_BEGIN_ALLOW_THREADS
errno = 0;
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+ n = read(self->fd, ptr, (int)size);
+#else
n = read(self->fd, ptr, size);
+#endif
Py_END_ALLOW_THREADS
} else
n = -1;