8000 bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657) · python/cpython@0c15e50 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c15e50

Browse files
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 9a0d7a7) Co-authored-by: Victor Stinner <vstinner@redhat.com>
1 parent c487cf9 commit 0c15e50

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Modules/posixmodule.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7912,11 +7912,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length)
79127912
return posix_error();
79137913
}
79147914

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);
79207916

79217917
buffer = PyBytes_FromStringAndSize((char *)NULL, length);
79227918
if (buffer == NULL)

0 commit comments

Comments
 (0)
0