Skip to content

Commit 18f3327

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 <[email protected]>
1 parent df6374e commit 18f3327

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
@@ -8021,11 +8021,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length)
80218021
return posix_error();
80228022
}
80238023

8024-
#ifdef MS_WINDOWS
8025-
/* On Windows, the count parameter of read() is an int */
8026-
if (length > INT_MAX)
8027-
length = INT_MAX;
8028-
#endif
8024+
length = Py_MIN(length, _PY_READ_MAX);
80298025

80308026
buffer = PyBytes_FromStringAndSize((char *)NULL, length);
80318027
if (buffer == NULL)

0 commit comments

Comments
 (0)