]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-82500: Fix asyncio sendfile overflow on 32bit (#107056)
authorJ. Nick Koston <nick@koston.org>
Sun, 23 Jul 2023 04:07:14 +0000 (23:07 -0500)
committerGitHub <noreply@github.com>
Sun, 23 Jul 2023 04:07:14 +0000 (21:07 -0700)
Lib/asyncio/unix_events.py
Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst [new file with mode: 0644]

index 17fb4d5f7646ced94a1bbf2c4b12025cda3960a8..a2680865ed968fa4b054b4138bdeab4683f3e511 100644 (file)
@@ -394,6 +394,9 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
                 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 (file)
index 0000000..065394f
--- /dev/null
@@ -0,0 +1 @@
+Fix overflow on 32-bit systems with :mod:`asyncio` :func:`os.sendfile` implemention.