From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 22 Nov 2018 14:17:34 +0000 (-0800) Subject: bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657) X-Git-Tag: v3.7.2rc1~113 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=18f3327d9a99163a658697465eb00c31f86535eb;p=thirdparty%2FPython%2Fcpython.git 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 --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8ff487d8cc1f..dbd534cab06a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8021,11 +8021,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)