From: Paul Eggert Date: Fri, 1 Aug 2025 23:01:13 +0000 (-0700) Subject: copy-file-range: work around glibc bug 33245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=948ba80168293e3d8a905eeffb0ab61424c4c374;p=thirdparty%2Fgnulib.git copy-file-range: work around glibc bug 33245 Problem reported by Leah Neukirchen . * 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. --- diff --git a/ChangeLog b/ChangeLog index b33d7fd00b..e60a387611 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2025-08-01 Paul Eggert + copy-file-range: work around glibc bug 33245 + Problem reported by Leah Neukirchen . + * 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 . Include diff --git a/lib/copy-file-range.c b/lib/copy-file-range.c index 73e02db1c1..5c12f6f715 100644 --- a/lib/copy-file-range.c +++ b/lib/copy-file-range.c @@ -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 + . + 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, diff --git a/m4/copy-file-range.m4 b/m4/copy-file-range.m4 index ec17fc68c7..85cfef71f4 100644 --- a/m4/copy-file-range.m4 +++ b/m4/copy-file-range.m4 @@ -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 diff --git a/modules/copy-file-range b/modules/copy-file-range index 573558a945..e3512eaffa 100644 --- a/modules/copy-file-range +++ b/modules/copy-file-range @@ -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: