[Python-checkins] gh-82500: Fix asyncio sendfile overflow on 32bit (#107056)

gvanrossum webhook-mailer at python.org
Sun Jul 23 00:07:18 EDT 2023


https://github.com/python/cpython/commit/9eeb4b485f4f9e13e5cb638e43a0baecb3ff4e86
commit: 9eeb4b485f4f9e13e5cb638e43a0baecb3ff4e86
branch: main
author: J. Nick Koston <nick at koston.org>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2023-07-22T21:07:14-07:00
summary:

gh-82500: Fix asyncio sendfile overflow on 32bit (#107056)

files:
A Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst
M Lib/asyncio/unix_events.py

diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 17fb4d5f7646c..a2680865ed968 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -394,6 +394,9 @@ def _sock_sendfile_native_impl(self, fut, registered_fd, sock, fileno,
                 fut.set_result(total_sent)
                 return
 
+        # On 32-bit architectures truncate to 1GiB to avoid OverflowError
+        blocksize = min(blocksize, sys.maxsize//2 + 1)
+
         try:
             sent = os.sendfile(fd, fileno, offset, blocksize)
         except (BlockingIOError, InterruptedError):
diff --git a/Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst b/Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst
new file mode 100644
index 0000000000000..065394fd6ee71
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst
@@ -0,0 +1 @@
+Fix overflow on 32-bit systems with :mod:`asyncio` :func:`os.sendfile` implemention.



More information about the Python-checkins mailing list