]> granicus.if.org Git - python/commitdiff
Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 5 Jul 2011 09:31:49 +0000 (11:31 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 5 Jul 2011 09:31:49 +0000 (11:31 +0200)
Misc/NEWS
Modules/_io/fileio.c

index 43392bcb56efbc66901361f50297c42f241924ee..ba0b55b27f49dc1ddfe1c5d199b26a0e48426cdc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2.2?
 Core and Builtins
 -----------------
 
+- Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
+
 - When a generator yields, do not retain the caller's exception state on the
   generator.
 
@@ -908,7 +910,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.
index 141b6dece1b197962cb7565b2b2f4422b90ce350..b1d492b7a341d96192ecbb090832e028c1548545 100644 (file)
@@ -664,6 +664,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;
@@ -672,7 +676,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;