]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
copy-file-range: work around glibc bug 33245
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Aug 2025 23:01:13 +0000 (16:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Aug 2025 23:54:42 +0000 (16:54 -0700)
Problem reported by Leah Neukirchen <https://bugs.gnu.org/79139>.
* lib/copy-file-range.c: Include sys-limits.h.
(copy_file_range) [glibc 2.42 and earlier]:
Copy at most SYS_BUFSIZE_MAX bytes.
* m4/copy-file-range.m4 (gl_FUNC_COPY_FILE_RANGE):
Replace on glibc platforms, as well as on Linux platforms.
* modules/copy-file-range (Files): Add lib/sys-limits.h.

ChangeLog
lib/copy-file-range.c
m4/copy-file-range.m4
modules/copy-file-range

index b33d7fd00b426abc527ffe817a1e54eb0d15cd01..e60a387611c1eb09f284a0cc191c1cdb48bfe2e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2025-08-01  Paul Eggert  <eggert@cs.ucla.edu>
 
+       copy-file-range: work around glibc bug 33245
+       Problem reported by Leah Neukirchen <https://bugs.gnu.org/79139>.
+       * lib/copy-file-range.c: Include sys-limits.h.
+       (copy_file_range) [glibc 2.42 and earlier]:
+       Copy at most SYS_BUFSIZE_MAX bytes.
+       * m4/copy-file-range.m4 (gl_FUNC_COPY_FILE_RANGE):
+       Replace on glibc platforms, as well as on Linux platforms.
+       * modules/copy-file-range (Files): Add lib/sys-limits.h.
+
        copy-file-range: tune for more-modern kernels
        * lib/copy-file-range.c [__linux__ && HAVE_COPY_FILE_RANGE]:
        Include <linux/version.h>.  Include <sys/utsname.h>
index 73e02db1c18d552197aebcabe32bcc5ac5143103..5c12f6f715cf9fe69c167fdb55dfec59f504671c 100644 (file)
@@ -30,6 +30,8 @@
 # endif
 #endif
 
+#include "sys-limits.h"
+
 ssize_t
 copy_file_range (int infd, off_t *pinoff,
                  int outfd, off_t *poutoff,
@@ -68,7 +70,20 @@ copy_file_range (int infd, off_t *pinoff,
 # endif
 
   if (ok)
-    return copy_file_range (infd, pinoff, outfd, poutoff, length, flags);
+    {
+#   if defined __GLIBC__ && ! (2 < __GLIBC__ + (43 <= __GLIBC_MINOR__))
+      /* Work around glibc bug 33245
+         <https://sourceware.org/bugzilla/show_bug.cgi?id=33245>.
+         This bug is present in glibc 2.42 (2025) and fixed in 2.43,
+         so this workaround, and the configure-time check for glibc,
+         can be removed once glibc 2.42 and earlier is no longer a
+         consideration.  Perhaps in 2040.  */
+      if (SYS_BUFSIZE_MAX < length)
+        length = SYS_BUFSIZE_MAX;
+# endif
+
+      return copy_file_range (infd, pinoff, outfd, poutoff, length, flags);
+    }
 #endif
 
   /* There is little need to emulate copy_file_range with read+write,
index ec17fc68c72b2bd781b79a9bf39c12827847913d..85cfef71f445b47b6fd186e4a5dee19531dd5ba2 100644 (file)
@@ -51,8 +51,8 @@ AC_DEFUN([gl_FUNC_COPY_FILE_RANGE],
       [Define to 1 if the function copy_file_range exists.])
 
     case $host_os in
-      linux*)
-        # See copy-file-range.c comment re Linux kernel bugs.
+      *-gnu* | gnu* | linux*)
+        # See copy-file-range.c comment re glibc and Linux kernel bugs.
         REPLACE_COPY_FILE_RANGE=1;;
     esac
   fi
index 573558a9456e2bb2ffabfca1d1a87ef50d1cb487..e3512eaffafd3d7ca580fd834891df1c12ed885d 100644 (file)
@@ -3,6 +3,7 @@ Copy parts of files
 
 Files:
 lib/copy-file-range.c
+lib/sys-limits.h
 m4/copy-file-range.m4
 
 Depends-on: