Skip to content

[3.8] bpo-38319: Fix shutil._fastcopy_sendfile(): set sendfile() max block size (GH-16491) #16506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ def _fastcopy_sendfile(fsrc, fdst):
# should not make any difference, also in case the file content
# changes while being copied.
try:
blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MB
except Exception:
blocksize = 2 ** 27 # 128MB
blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MiB
except OSError:
blocksize = 2 ** 27 # 128MiB
# On 32-bit architectures truncate to 1GiB to avoid OverflowError,
# see bpo-38319.
if sys.maxsize < 2 ** 32:
blocksize = min(blocksize, 2 ** 30)

offset = 0
while True:
Expand Down
4 changes: 2 additions & 2 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def _sendfile_use_sendfile(self, file, offset=0, count=None):
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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sendfile() used in socket and shutil modules was raising OverflowError for
files >= 2GiB on 32-bit architectures. (patch by Giampaolo Rodola)