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

Victor Stinner webhook-mailer at python.org
Thu Nov 22 09:03:45 EST 2018


https://github.com/python/cpython/commit/9a0d7a7648547ffb77144bf2480155f6d7940dea
commit: 9a0d7a7648547ffb77144bf2480155f6d7940dea
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-22T15:03:40+01:00
summary:

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).

files:
M Modules/posixmodule.c

diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index bd97f0abe1b9..44d6009bda71 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -8410,11 +8410,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;
-#endif
+    length = Py_MIN(length, _PY_READ_MAX);
 
     buffer = PyBytes_FromStringAndSize((char *)NULL, length);
     if (buffer == NULL)



More information about the Python-checkins mailing list