[Python-checkins] r87722 - in python/branches/py3k: Misc/NEWS Modules/_io/fileio.c Modules/posixmodule.c

victor.stinner python-checkins at python.org
Tue Jan 4 01:29:35 CET 2011


Author: victor.stinner
Date: Tue Jan  4 01:29:35 2011
New Revision: 87722

Log:
Issue #9015, #9611: FileIO.readinto(), FileIO.write() and os.write() clamp the
length to 2^31-1 on Windows.

Modified:
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_io/fileio.c
   python/branches/py3k/Modules/posixmodule.c

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue Jan  4 01:29:35 2011
@@ -8,6 +8,9 @@
 Core and Builtins
 -----------------
 
+- Issue #9015, #9611: FileIO.readinto(), FileIO.write() and os.write() clamp
+  the length to 2^31-1 on Windows.
+
 - Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime()
   can now handle dates after 2038.
 

Modified: python/branches/py3k/Modules/_io/fileio.c
==============================================================================
--- python/branches/py3k/Modules/_io/fileio.c	(original)
+++ python/branches/py3k/Modules/_io/fileio.c	Tue Jan  4 01:29:35 2011
@@ -506,7 +506,7 @@
 fileio_readinto(fileio *self, PyObject *args)
 {
     Py_buffer pbuf;
-    Py_ssize_t n;
+    Py_ssize_t n, len;
 
     if (self->fd < 0)
         return err_closed();
@@ -517,9 +517,16 @@
         return NULL;
 
     if (_PyVerify_fd(self->fd)) {
+        len = pbuf.len;
         Py_BEGIN_ALLOW_THREADS
         errno = 0;
-        n = read(self->fd, pbuf.buf, pbuf.len);
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+        if (len > INT_MAX)
+            len = INT_MAX;
+        n = read(self->fd, pbuf.buf, (int)len);
+#else
+        n = read(self->fd, pbuf.buf, (size_t)len);
+#endif
         Py_END_ALLOW_THREADS
     } else
         n = -1;
@@ -685,7 +692,7 @@
 fileio_write(fileio *self, PyObject *args)
 {
     Py_buffer pbuf;
-    Py_ssize_t n;
+    Py_ssize_t n, len;
 
     if (self->fd < 0)
         return err_closed();
@@ -698,7 +705,14 @@
     if (_PyVerify_fd(self->fd)) {
         Py_BEGIN_ALLOW_THREADS
         errno = 0;
-        n = write(self->fd, pbuf.buf, pbuf.len);
+        len = pbuf.len;
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+        if (len > INT_MAX)
+            len = INT_MAX;
+        n = write(self->fd, pbuf.buf, (int)len);
+#else
+        n = write(self->fd, pbuf.buf, (size_t)len);
+#endif
         Py_END_ALLOW_THREADS
     } else
         n = -1;

Modified: python/branches/py3k/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k/Modules/posixmodule.c	(original)
+++ python/branches/py3k/Modules/posixmodule.c	Tue Jan  4 01:29:35 2011
@@ -5696,7 +5696,7 @@
 {
     Py_buffer pbuf;
     int fd;
-    Py_ssize_t size;
+    Py_ssize_t size, len;
 
     if (!PyArg_ParseTuple(args, "iy*:write", &fd, &pbuf))
         return NULL;
@@ -5704,8 +5704,15 @@
         PyBuffer_Release(&pbuf);
         return posix_error();
     }
+    len = pbuf.len;
     Py_BEGIN_ALLOW_THREADS
-    size = write(fd, pbuf.buf, (size_t)pbuf.len);
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+    if (len > INT_MAX)
+        len = INT_MAX;
+    size = write(fd, pbuf.buf, (int)len);
+#else
+    size = write(fd, pbuf.buf, (size_t)len);
+#endif
     Py_END_ALLOW_THREADS
     PyBuffer_Release(&pbuf);
     if (size < 0)


More information about the Python-checkins mailing list