summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 13:15:39 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 13:15:39 (GMT)
commitdc5554008f939e719760b490812065456e8313b5 (patch)
treedf01dcc0e335327aa94cb10d944e7af14c93a2e3
parent0fcab4a3ed5e39769609b60d6179c4c801e45985 (diff)
downloadcpython-dc5554008f939e719760b490812065456e8313b5.zip
cpython-dc5554008f939e719760b490812065456e8313b5.tar.gz
cpython-dc5554008f939e719760b490812065456e8313b5.tar.bz2
Issue #9015, #9611: stdprinter.write() clamps the length to 2^31-1 on Windows
-rw-r--r--Misc/NEWS4
-rw-r--r--Objects/fileobject.c10
2 files changed, 10 insertions, 4 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index bebe16b..2c5df9e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,8 +12,8 @@ Core and Builtins
doesn't have PY_SSIZE_T_CLEAN define and the size doesn't fit in an int
(length bigger than 2^31-1 bytes).
-- Issue #9015, #9611: FileIO.readinto(), FileIO.write() and os.write() clamp
- the length to 2^31-1 on Windows.
+- Issue #9015, #9611: FileIO.readinto(), FileIO.write(), os.write() and
+ stdprinter.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.
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 9288e35..d20f196 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -344,7 +344,7 @@ stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
}
static int
-fileio_init(PyObject *self, PyObject *args, PyObject *kwds)
+stdprinter_init(PyObject *self, PyObject *args, PyObject *kwds)
{
PyErr_SetString(PyExc_TypeError,
"cannot create 'stderrprinter' instances");
@@ -390,7 +390,13 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
errno = 0;
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+ if (n > INT_MAX)
+ n = INT_MAX;
+ n = write(self->fd, c, (int)n);
+#else
n = write(self->fd, c, n);
+#endif
Py_END_ALLOW_THREADS
if (n < 0) {
@@ -509,7 +515,7 @@ PyTypeObject PyStdPrinter_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- fileio_init, /* tp_init */
+ stdprinter_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
stdprinter_new, /* tp_new */
PyObject_Del, /* tp_free */