Commit 59729ff6 authored by Victor Stinner's avatar Victor Stinner

Issue #9611, #9015: FileIO.read(), FileIO.readinto(), FileIO.write() and

os.write() clamp the length to INT_MAX on Windows.
parent 4833c98f
......@@ -9,6 +9,9 @@ What's New in Python 2.7.3?
Core and Builtins
-----------------
- Issue #9611, #9015: FileIO.read(), FileIO.readinto(), FileIO.write() and
os.write() clamp the length to INT_MAX on Windows.
- Issue #1195: my_fgets() now always clears errors before calling fgets(). Fix
the following case: sys.stdin.read() stopped with CTRL+d (end of file),
raw_input() interrupted by CTRL+c.
......
......@@ -474,7 +474,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();
......@@ -485,9 +485,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, len);
#endif
Py_END_ALLOW_THREADS
} else
n = -1;
......@@ -620,6 +627,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;
......@@ -628,7 +639,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;
......@@ -655,7 +670,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();
......@@ -668,7 +683,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, len);
#endif
Py_END_ALLOW_THREADS
} else
n = -1;
......
......@@ -3903,7 +3903,7 @@ posix_getgroups(PyObject *self, PyObject *noargs)
#endif
gid_t grouplist[MAX_GROUPS];
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results
* This is a helper variable to store the intermediate result when
* that happens.
*
......@@ -6648,7 +6648,7 @@ posix_write(PyObject *self, PyObject *args)
{
Py_buffer pbuf;
int fd;
Py_ssize_t size;
Py_ssize_t size, len;
if (!PyArg_ParseTuple(args, "is*:write", &fd, &pbuf))
return NULL;
......@@ -6656,8 +6656,15 @@ posix_write(PyObject *self, PyObject *args)
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, len);
#endif
Py_END_ALLOW_THREADS
PyBuffer_Release(&pbuf);
if (size < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment