bpo-38319: Fix shutil._fastcopy_sendfile(): set sendfile() max block … · python/cpython@938c00c · GitHub
Skip to content

Commit 938c00c

Browse files
miss-islingtongiampaolo
authored andcommitted
bpo-38319: Fix shutil._fastcopy_sendfile(): set sendfile() max block size (GH-16491) (#16506)
(cherry picked from commit 94e1650) Co-authored-by: Giampaolo Rodola <g.rodola@gmail.com>
1 parent b361207 commit 938c00c

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/shutil.py

Lines changed: 7 additions & 3 deletions

Lib/socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ def _sendfile_use_sendfile(self, file, offset=0, count=None):
355355
raise _GiveupOnSendfile(err) # not a regular file
356356
if not fsize:
357357
return 0 # empty file
358-
blocksize = fsize if not count else count
359-
358+
# Truncate to 1GiB to avoid OverflowError, see bpo-38319.
359+
blocksize = min(count or fsize, 2 ** 30)
360360
timeout = self.gettimeout()
361361
if timeout == 0:
362362
raise ValueError("non-blocking sockets are not supported")
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)