bpo-38319: Fix shutil._fastcopy_sendfile(): set sendfile() max block size (GH-16491) (#16506)
(cherry picked from commit 94e165096fd65e8237e60de570fb609604ab94c9)
Co-authored-by: Giampaolo Rodola <g.rodola@gmail.com>
diff --git a/Lib/socket.py b/Lib/socket.py
index af2ed0e..813f4ef 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -355,8 +355,8 @@
raise _GiveupOnSendfile(err) # not a regular file
if not fsize:
return 0 # empty file
- blocksize = fsize if not count else count
-
+ # Truncate to 1GiB to avoid OverflowError, see bpo-38319.
+ blocksize = min(count or fsize, 2 ** 30)
timeout = self.gettimeout()
if timeout == 0:
raise ValueError("non-blocking sockets are not supported")