bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657) · python/cpython@0c15e50 (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Commit 0c15e50

miss-islingtonvstinner

and

authored

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 9a0d7a7) Co-authored-by: Victor Stinner vstinner@redhat.com

File tree

1 file changed

lines changed

1 file changed

lines changed

Original file line number Diff line number Diff line change
@@ -7912,11 +7912,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length)
7912 7912 return posix_error();
7913 7913 }
7914 7914
7915 -#ifdef MS_WINDOWS
7916 -/* On Windows, the count parameter of read() is an int */
7917 -if (length > INT_MAX)
7918 -length = INT_MAX;
7919 -#endif
7915 +length = Py_MIN(length, _PY_READ_MAX);
7920 7916
7921 7917 buffer = PyBytes_FromStringAndSize((char *)NULL, length);
7922 7918 if (buffer == NULL)