From 26ee11de195b0c5feb167951ecb0548588db58bd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 22 Nov 2018 13:56:34 +0100 Subject: [PATCH] bpo-24658: os.read() reuses _PY_READ_MAX os_read_impl() now also truncates the size of _PY_READ_MAX (INT_MAX) on macOS, to avoid to allocate a larger buffer even if _Py_read() is limited to _PY_READ_MAX bytes. --- Modules/posixmodule.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index bd97f0abe1b977..44d6009bda713d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8410,11 +8410,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)