bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657) · python/cpython@9a0d7a7 (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit 9a0d7a7
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).
File tree
1 file changed
lines changed
1 file changed
lines changed
Lines changed: 1 addition & 5 deletions
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8410,11 +8410,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length) | ||
8410 | 8410 | return posix_error(); |
8411 | 8411 | } |
8412 | 8412 | |
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); | |
8418 | 8414 | |
8419 | 8415 | buffer = PyBytes_FromStringAndSize((char *)NULL, length); |
8420 | 8416 | if (buffer == NULL) |