Commit 94e16509 authored by Giampaolo Rodola's avatar Giampaolo Rodola Committed by GitHub

bpo-38319: Fix shutil._fastcopy_sendfile(): set sendfile() max block size (GH-16491)

parent cf57cabe
...@@ -135,9 +135,13 @@ def _fastcopy_sendfile(fsrc, fdst): ...@@ -135,9 +135,13 @@ def _fastcopy_sendfile(fsrc, fdst):
# should not make any difference, also in case the file content # should not make any difference, also in case the file content
# changes while being copied. # changes while being copied.
try: try:
blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MB blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MiB
except Exception: except OSError:
blocksize = 2 ** 27 # 128MB 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 offset = 0
while True: while True:
......
...@@ -356,8 +356,8 @@ class socket(_socket.socket): ...@@ -356,8 +356,8 @@ class socket(_socket.socket):
raise _GiveupOnSendfile(err) # not a regular file raise _GiveupOnSendfile(err) # not a regular file
if not fsize: if not fsize:
return 0 # empty file 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() timeout = self.gettimeout()
if timeout == 0: if timeout == 0:
raise ValueError("non-blocking sockets are not supported") raise ValueError("non-blocking sockets are not supported")
......
sendfile() used in socket and shutil modules was raising OverflowError for
files >= 2GiB on 32-bit architectures. (patch by Giampaolo Rodola)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment