[Python-checkins] bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657)

Miss Islington (bot) webhook-mailer at python.org
Thu Nov 22 09:25:28 EST 2018

commit: 0c15e508baec7e542933db2b31ea950a646cd968
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-11-22T06:25:25-08:00

bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657)

os_read_impl() now also truncates the size to _PY_READ_MAX
on macOS, to avoid to allocate a larger buffer even if _Py_read() is
limited to _PY_READ_MAX bytes (ex: INT_MAX on macOS).
(cherry picked from commit 9a0d7a7648547ffb77144bf2480155f6d7940dea)

Co-authored-by: Victor Stinner <vstinner at redhat.com>

M Modules/posixmodule.c

diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index f5642d267299..b7091ca4c234 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7912,11 +7912,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length)
         return posix_error();
-#ifdef MS_WINDOWS
-    /* On Windows, the count parameter of read() is an int */
-    if (length > INT_MAX)
-        length = INT_MAX;
+    length = Py_MIN(length, _PY_READ_MAX);
     buffer = PyBytes_FromStringAndSize((char *)NULL, length);
     if (buffer == NULL)

More information about the Python-checkins mailing list