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.
---
 lib/portability.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
From 75ada64ee29738dc6ba9f5156f2e38b2731a9d40 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Wed, 31 Jul 2024 16:00:21 -0400
Subject: [PATCH] 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.
---
 lib/portability.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/portability.c b/lib/portability.c
index abcecc80..b541c5d9 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -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;
-- 
2.46.0.rc1.232.g9752f9e123-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to