[Python-checkins] cpython (merge 3.2 -> default): (merge 3.2) Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on

victor.stinner python-checkins at python.org
Tue Jul 5 11:38:43 CEST 2011


http://hg.python.org/cpython/rev/e8646f120330
changeset:   71225:e8646f120330
parent:      71222:e38bb637328c
parent:      71224:7acdf9f5eb31
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Jul 05 11:34:18 2011 +0200
summary:
  (merge 3.2) Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.

files:
  Misc/NEWS            |  4 +++-
  Modules/_io/fileio.c |  8 ++++++++
  2 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 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 @@
   (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
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -687,6 +687,10 @@
         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 @@
     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;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list