bpo-24658: os.read() reuses _PY_READ_MAX (GH-10657) · python/cpython@18f3327 (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 18f3327
and
authored
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). (cherry picked from commit 9a0d7a7) Co-authored-by: Victor Stinner vstinner@redhat.com
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 |
---|---|---|
@@ -8021,11 +8021,7 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length) | ||
8021 | 8021 | return posix_error(); |
8022 | 8022 | } |
8023 | 8023 | |
8024 | -#ifdef MS_WINDOWS | |
8025 | -/* On Windows, the count parameter of read() is an int */ | |
8026 | -if (length > INT_MAX) | |
8027 | -length = INT_MAX; | |
8028 | -#endif | |
8024 | +length = Py_MIN(length, _PY_READ_MAX); | |
8029 | 8025 | |
8030 | 8026 | buffer = PyBytes_FromStringAndSize((char *)NULL, length); |
8031 | 8027 | if (buffer == NULL) |