From 231b64f41ce6d9d9f0ca3039a045ed20c182798e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Jul 2023 11:42:10 -0500 Subject: [PATCH 1/5] gh-82500: Fix asyncio sendfile overflow on 32bit asyncio has the same issue --- Lib/asyncio/unix_events.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 17fb4d5f7646ce..2881a5c600b0bc 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -394,6 +394,11 @@ 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, + # see bpo-38319/gh-82500. + if sys.maxsize < 2 ** 32: + blocksize = min(blocksize, 2 ** 30) + try: sent = os.sendfile(fd, fileno, offset, blocksize) except (BlockingIOError, InterruptedError): From f02d9404a68cb4effc47d1a152051eb5e573476d Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:44:59 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst 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 00000000000000..58318ebb70c95f --- /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` sendfile implemention. From f25bba15ba9864460f1aae0146e3b86746bac58a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Jul 2023 22:04:30 -0500 Subject: [PATCH 3/5] Update Lib/asyncio/unix_events.py --- Lib/asyncio/unix_events.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 2881a5c600b0bc..7c8e50ea3d44a2 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -394,8 +394,7 @@ 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, - # see bpo-38319/gh-82500. + # On 32-bit architectures truncate to 1GiB to avoid OverflowError if sys.maxsize < 2 ** 32: blocksize = min(blocksize, 2 ** 30) From c83dd4b55e3e60e0aa8348eab9a2b3dbb4906eea Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Jul 2023 22:05:52 -0500 Subject: [PATCH 4/5] Update Misc/NEWS.d/next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst --- .../next/Library/2023-07-22-16-44-58.gh-issue-82500.cQYoPj.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 58318ebb70c95f..065394fd6ee712 100644 --- 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 @@ -1 +1 @@ -Fix overflow on 32-bit systems with :mod:`asyncio` sendfile implemention. +Fix overflow on 32-bit systems with :mod:`asyncio` :func:`os.sendfile` implemention. From bde4502f12fe3dfff4c230da73cd67bfe7b9e981 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Jul 2023 22:19:22 -0500 Subject: [PATCH 5/5] use suggested min expression --- Lib/asyncio/unix_events.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 7c8e50ea3d44a2..a2680865ed968f 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -395,8 +395,7 @@ def _sock_sendfile_native_impl(self, fut, registered_fd, sock, fileno, return # On 32-bit architectures truncate to 1GiB to avoid OverflowError - if sys.maxsize < 2 ** 32: - blocksize = min(blocksize, 2 ** 30) + blocksize = min(blocksize, sys.maxsize//2 + 1) try: sent = os.sendfile(fd, fileno, offset, blocksize)