summaryrefslogtreecommitdiffstats
path: root/Modules/_io/fileio.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 00:29:35 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 00:29:35 (GMT)
commite6edec23718072ed7903be9dae37ae330a9d81d5 (patch)
treedd43a4d1de61a8b0b49bef7f3fb299638f7aded9 /Modules/_io/fileio.c
parent560f9dab55701654706b0d257d5d8f34f633bb52 (diff)
downloadcpython-e6edec23718072ed7903be9dae37ae330a9d81d5.zip
cpython-e6edec23718072ed7903be9dae37ae330a9d81d5.tar.gz
cpython-e6edec23718072ed7903be9dae37ae330a9d81d5.tar.bz2
Issue #9015, #9611: FileIO.readinto(), FileIO.write() and os.write() clamp the
length to 2^31-1 on Windows.
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r--Modules/_io/fileio.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 96fce15..2361636 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -506,7 +506,7 @@ static PyObject *
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 @@ fileio_readinto(fileio *self, PyObject *args)
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 @@ static PyObject *
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 @@ fileio_write(fileio *self, PyObject *args)
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;