# 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:
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")