Skip to content

Commit 9a0d7a7

Browse files
authored
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).
1 parent 4d73ae7 commit 9a0d7a7

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
@@ -8410,11 +8410,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length)
84108410
return posix_error();
84118411
}
84128412

8413-
#ifdef MS_WINDOWS
8414-
/* On Windows, the count parameter of read() is an int */
8415-
if (length > INT_MAX)
8416-
length = INT_MAX;
8417-
#endif
8413+
length = Py_MIN(length, _PY_READ_MAX);
84188414

84198415
buffer = PyBytes_FromStringAndSize((char *)NULL, length);
84208416
if (buffer == NULL)

0 commit comments

Comments
 (0)