summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-22 14:03:40 (GMT)
committerGitHub <noreply@github.com>2018-11-22 14:03:40 (GMT)
commit9a0d7a7648547ffb77144bf2480155f6d7940dea (patch)
tree4972ec72abbb88219f7843aab4d050b90b8427c0 /Modules/posixmodule.c
parent4d73ae776140a583fdfe8f016d88cc767791e481 (diff)
downloadcpython-9a0d7a7648547ffb77144bf2480155f6d7940dea.zip
cpython-9a0d7a7648547ffb77144bf2480155f6d7940dea.tar.gz
cpython-9a0d7a7648547ffb77144bf2480155f6d7940dea.tar.bz2
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).
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index bd97f0a..44d6009 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)