From 389e7964fedd4cf632d76116a565f33fc11f5173 Mon Sep 17 00:00:00 2001 From: jcg Date: Fri, 1 Dec 2023 15:13:28 +0800 Subject: [PATCH] coreutils: sync patches from community --- ...ix-infinite-loop-when-double-spacing.patch | 64 ++++++++++++++++ ...port-wc-ensure-we-update-file-offset.patch | 74 +++++++++++++++++++ coreutils.spec | 9 ++- 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 backport-pr-fix-infinite-loop-when-double-spacing.patch create mode 100644 backport-wc-ensure-we-update-file-offset.patch diff --git a/backport-pr-fix-infinite-loop-when-double-spacing.patch b/backport-pr-fix-infinite-loop-when-double-spacing.patch new file mode 100644 index 0000000..51b4e92 --- /dev/null +++ b/backport-pr-fix-infinite-loop-when-double-spacing.patch @@ -0,0 +1,64 @@ +From 3fb0cc80fa5e1cede9ec05303a70c26d0d23ca1d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?P=C3=A1draig=20Brady?= +Date: Tue, 25 Apr 2023 14:07:03 +0100 +Subject: [PATCH] pr: fix infinite loop when double spacing + +* src/pr.c (init_parameters): Ensure we avoid a 0 lines_per_body +which was possible when adjusting for double spacing. +That caused print_page() to always return true, +causing an infinite loop. +* tests/pr/pr-tests.pl: Add a test case. +* NEWS: Mention the fix. +Fixes https://bugs.debian.org/1034808 + +Conflict:NEWS context adaption +Reference:https://github.com/coreutils/coreutils/commit/3fb0cc80fa5e1cede9ec05303a70c26d0d23ca1d + +--- + NEWS | 3 +++ + src/pr.c | 2 +- + tests/pr/pr-tests.pl | 3 +++ + 3 files changed, 7 insertions(+), 1 deletion(-) + +diff --git a/NEWS b/NEWS +index 81f5cf5..d1d0342 100644 +--- a/NEWS ++++ b/NEWS +@@ -3,6 +3,8 @@ GNU coreutils NEWS -*- outline -*- + * Noteworthy changes in release 8.32 (2020-03-05) [stable] + + ** Bug fixes ++ 'pr --length=1 --double-space' no longer enters an infinite loop. ++ [This bug was present in "the beginning".] + + stat no longer tries to automount files by default, reverting to the + behavior before the statx() call was introduced in coreutils-8.32. +diff --git a/src/pr.c b/src/pr.c +index 2c5cdceb1..14a368b6c 100644 +--- a/src/pr.c ++++ b/src/pr.c +@@ -1209,7 +1209,7 @@ init_parameters (int number_of_files) + lines_per_body = lines_per_page; + + if (double_space) +- lines_per_body = lines_per_body / 2; ++ lines_per_body = MAX (1, lines_per_body / 2); + + /* If input is stdin, cannot print parallel files. BSD dumps core + on this. */ +diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl +index 265e6e108..eafc13d81 100755 +--- a/tests/pr/pr-tests.pl ++++ b/tests/pr/pr-tests.pl +@@ -415,6 +415,9 @@ my @tv = ( + ['padding2', '-t -n,64', "1\n", (" "x 63)."1,1\n", 0], + # Ensure we handle buffer truncation correctly + ['padding3', '-t -N1000000 -n,1', "1\n", "0,1\n", 0], ++ ++# This entered an infinite loop before coreutils-9.4 ++['page-length1', '-dl1', "", "", 0], + ); + + # Convert the above old-style test vectors to the newer +-- +2.36.1 diff --git a/backport-wc-ensure-we-update-file-offset.patch b/backport-wc-ensure-we-update-file-offset.patch new file mode 100644 index 0000000..d1fc46e --- /dev/null +++ b/backport-wc-ensure-we-update-file-offset.patch @@ -0,0 +1,74 @@ +From ce630dfc7ef32ff7e35c627bd061a45ce9053d9d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?P=C3=A1draig=20Brady?= +Date: Sun, 5 Feb 2023 19:52:31 +0000 +Subject: [PATCH] wc: ensure we update file offset + +* src/wc.c (wc): Update the offset when not reading, +and do read if we can't update the offset. +* tests/misc/wc-proc.sh: Add a test case. +* NEWS: Mention the bug fix. +Fixes https://bugs.gnu.org/61300 + +Conflict:NEWS and tests/misc/wc-proc.sh context adaption +Reference:https://github.com/coreutils/coreutils/commit/ce630dfc7ef32ff7e35c627bd061a45ce9053d9d + +--- + NEWS | 4 ++++ + src/wc.c | 5 ++++- + tests/misc/wc-proc.sh | 12 ++++++++++++ + 3 files changed, 20 insertions(+), 1 deletion(-) + +diff --git a/NEWS b/NEWS +index d1d0342..7f92559 100644 +--- a/NEWS ++++ b/NEWS +@@ -3,6 +3,10 @@ GNU coreutils NEWS -*- outline -*- + * Noteworthy changes in release 8.32 (2020-03-05) [stable] + + ** Bug fixes ++ `wc -c` will again correctly update the read offset of inputs. ++ Previously it deduced the size of inputs while leaving the offset unchanged. ++ [bug introduced in coreutils-8.27] ++ + 'pr --length=1 --double-space' no longer enters an infinite loop. + [This bug was present in "the beginning".] + +diff --git a/src/wc.c b/src/wc.c +index 801396a15..becceda98 100644 +--- a/src/wc.c ++++ b/src/wc.c +@@ -450,7 +450,10 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos) + beyond the end of the file. As in the example above. */ + + bytes = end_pos < current_pos ? 0 : end_pos - current_pos; +- skip_read = true; ++ if (bytes && 0 <= lseek (fd, bytes, SEEK_CUR)) ++ skip_read = true; ++ else ++ bytes = 0; + } + else + { +diff --git a/tests/misc/wc-proc.sh b/tests/misc/wc-proc.sh +index 5eb43b982..2307f2c38 100755 +--- a/tests/misc/wc-proc.sh ++++ b/tests/misc/wc-proc.sh +@@ -42,4 +42,16 @@ cat <<\EOF > exp + EOF + compare exp out || fail=1 + ++# Ensure we update the offset even when not reading, ++# which wasn't the case from coreutils-8.27 to coreutils-9.2 ++{ wc -c; wc -c; } < no_read > out || fail=1 ++{ wc -c; wc -c; } < do_read >> out || fail=1 ++cat <<\EOF > exp ++2 ++0 ++1048576 ++0 ++EOF ++compare exp out || fail=1 ++ + Exit $fail +-- +2.36.1 diff --git a/coreutils.spec b/coreutils.spec index 1f234ee..7dc7991 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,6 +1,6 @@ Name: coreutils Version: 8.32 -Release: 8 +Release: 9 License: GPLv3+ Summary: A set of basic GNU tools commonly used in shell scripts Url: https://www.gnu.org/software/coreutils/ @@ -40,6 +40,8 @@ Patch22: backport-stat-only-automount-with-cached-never.patch Patch23: test-skip-overlay-filesystem-because-of-no-inotify_add_watch.patch Patch24: 0001-basenc-fix-bug49741-using-wrong-decoding-buffer-leng.patch Patch25: 0002-cat-with-E-fix-handling-of-r-n-spanning-buffers.patch +Patch26: backport-pr-fix-infinite-loop-when-double-spacing.patch +Patch27: backport-wc-ensure-we-update-file-offset.patch Conflicts: filesystem < 3 # To avoid clobbering installs @@ -158,6 +160,11 @@ fi %{_mandir}/man*/* %changelog +* Fri Dec 1 2023 jiangchuangang - 8.32-9 +- sync patches from community +- add backport-pr-fix-infinite-loop-when-double-spacing.patch + backport-wc-ensure-we-update-file-offset.patch + * Tue Nov 28 2023 liningjie - 8.32-8 - cat: with -E fix handling of \r\n spanning buffers -- Gitee