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 9a0d7a7648)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
This commit is contained in:
Miss Islington (bot) 2018-11-22 06:17:34 -08:00 committed by GitHub
parent df6374e15a
commit 18f3327d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 5 deletions

View File

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