]> granicus.if.org Git - python/commitdiff
bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657)
authorVictor Stinner <vstinner@redhat.com>
Thu, 22 Nov 2018 14:03:40 +0000 (15:03 +0100)
committerGitHub <noreply@github.com>
Thu, 22 Nov 2018 14:03:40 +0000 (15:03 +0100)
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).

Modules/posixmodule.c

index bd97f0abe1b977bb291a840b9717f3caaff2b4eb..44d6009bda713d14c12843e02d94194b8c829a3a 100644 (file)
@@ -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)