sendfile_len: fix bounds check.

We want to check whether the next call we make will try to send more
than 1<<30 bytes, not whether the total number of bytes to transfer is
more than that.

Interestingly, the read() fallback implementation already has the right
check, presumably because files larger than libbuf are commonplace,
whereas files larger than 1<<30 bytes are not.

Tested locally using truncate to create a 2GiB file (which works) and a
2.5GiB file (which does not work), tar to create the tarfile, and then
tar to extract them.
This commit is contained in:
Elliott Hughes 2024-07-31 16:00:21 -04:00 committed by Rob Landley
parent f4ab441ca3
commit 5feaacbab8

View File

@ -658,7 +658,7 @@ long long sendfile_len(int in, int out, long long bytes, long long *consumed)
errno = 0;
if (try_cfr) {
if (bytes<0 || bytes>(1<<30)) len = (1<<30);
if (bytes<0 || len>(1<<30)) len = (1<<30);
len = syscall(try_cfr, in, 0, out, 0, len, 0);
if (len < 0) {
try_cfr = 0;