From 26ccabcab9e1e7e455d8be906dc88c9c8936768e Mon Sep 17 00:00:00 2001 From: Linux_zhang Date: Thu, 13 Mar 2025 11:02:54 +0800 Subject: [PATCH 1/3] sync patches from upstream to fix a bug in pcre2grep --- ...ersight-in-adding-new-pcre2grep-test.patch | 49 ++++ ...re2grep-that-caused-separator-lines-.patch | 220 ++++++++++++++++++ pcre2.spec | 7 +- 3 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-oversight-in-adding-new-pcre2grep-test.patch create mode 100644 backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch diff --git a/backport-Fix-oversight-in-adding-new-pcre2grep-test.patch b/backport-Fix-oversight-in-adding-new-pcre2grep-test.patch new file mode 100644 index 0000000..fdc62f2 --- /dev/null +++ b/backport-Fix-oversight-in-adding-new-pcre2grep-test.patch @@ -0,0 +1,49 @@ +From ace78dc460e7e80592d86216cfdd36a62b083bb3 Mon Sep 17 00:00:00 2001 +From: Philip Hazel +Date: Wed, 27 Nov 2024 15:50:34 +0000 +Subject: [PATCH] Fix oversight in adding new pcre2grep test + +Conflict:NA +Reference:https://github.com/PCRE2Project/pcre2/commit/ace78dc460e7e80592d86216cfdd36a62b083bb3 + +--- + testdata/grepinput | 2 +- + testdata/grepoutput | 3 +-- + 2 files changed, 2 insertions(+), 3 deletions(-) + +diff --git a/testdata/grepinput b/testdata/grepinput +index 91d3db88..1a0a9c0f 100644 +--- a/testdata/grepinput ++++ b/testdata/grepinput +@@ -630,7 +630,7 @@ asd + dfg + ghj + jkl +-abc ++abx + def + ghi + xyz +diff --git a/testdata/grepoutput b/testdata/grepoutput +index 58ea858d..abfabe15 100644 +--- a/testdata/grepoutput ++++ b/testdata/grepoutput +@@ -104,7 +104,6 @@ pcre2grep: Error in command-line regex at offset 4: quantifier does not follow a + RC=2 + ---------------------------- Test 16 ----------------------------- + pcre2grep: Failed to open ./testdata/nonexistfile: No such file or directory +-./testdata/grepinput:abc + RC=2 + ---------------------------- Test 17 ----------------------------- + features should be added at the end, because some of the tests involve the +@@ -1306,7 +1305,7 @@ RC=0 + 630-dfg + 631-ghj + 632:jkl +-633-abc ++633-abx + 634-def + 635-ghi + RC=0 +-- +2.23.0 \ No newline at end of file diff --git a/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch b/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch new file mode 100644 index 0000000..6d3bc07 --- /dev/null +++ b/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch @@ -0,0 +1,220 @@ +From 7a7b2ba4a474c701530e39eba9be87faff9a382a Mon Sep 17 00:00:00 2001 +From: Philip Hazel +Date: Wed, 27 Nov 2024 15:15:45 +0000 +Subject: [PATCH] Mend a bug in pcre2grep that caused separator lines to be + incorrectly inserted in some cases when above/below context lines are + contiguous. Reported by Alejandro Colomar . Fixes GitHub + issue #577. + +Conflict:adapt context; don't modify ChangeLog; don't use group_separator +because e179a4b8c is not merged +Reference:https://github.com/PCRE2Project/pcre2/commit/f34fc0a34ab18d7cb0ff27eacaea43912d797a27 +--- + RunGrepTest | 7 +++++++ + src/pcre2grep.c | 19 ++++++++++++++++-- + testdata/grepinput | 19 ++++++++++++++++++ + testdata/grepoutput | 48 ++++++++++++++++++++++++++++++++++++--------- + 4 files changed, 82 insertions(+), 11 deletions(-) + +diff --git a/RunGrepTest b/RunGrepTest +index 9682c5f..e8ab6e5 100755 +--- a/RunGrepTest ++++ b/RunGrepTest +@@ -685,6 +685,13 @@ echo "---------------------------- Test 134 -----------------------------" >>tes + (cd $srcdir; $valgrind $vjs $pcre2grep -m1 -O '=$x{41}$x423$o{103}$o1045=' 'fox') <$srcdir/testdata/grepinputv >>testtrygrep 2>&1 + echo "RC=$?" >>testtrygrep + ++echo "---------------------------- Test 160 -----------------------------" >>testtrygrep ++(cd $srcdir; $valgrind $vjs $pcre2grep -nC3 '^(ert|jkl)' ./testdata/grepinput) >>testtrygrep ++echo "RC=$?" >>testtrygrep ++(cd $srcdir; $valgrind $vjs $pcre2grep -n -B4 -A2 '^(ert|dfg)' ./testdata/grepinput) >>testtrygrep ++echo "RC=$?" >>testtrygrep ++ ++ + # Now compare the results. + + $cf $srcdir/testdata/grepoutput testtrygrep +diff --git a/src/pcre2grep.c b/src/pcre2grep.c +index 72c11bc..7f92f7d 100644 +--- a/src/pcre2grep.c ++++ b/src/pcre2grep.c +@@ -2934,12 +2934,15 @@ while (ptr < endptr) + FWRITE_IGNORE(lastmatchrestart, 1, pp - lastmatchrestart, stdout); + lastmatchrestart = pp; + } ++ + if (lastmatchrestart != ptr) hyphenpending = TRUE; + } + +- /* If there were non-contiguous lines printed above, insert hyphens. */ ++ /* If hyphenpending is TRUE when there is no "after" context, it means we ++ are at the start of a new file, having output something from the previous ++ file. Output a separator if enabled.*/ + +- if (hyphenpending) ++ else if (hyphenpending) + { + fprintf(stdout, "--" STDOUT_NL); + hyphenpending = FALSE; +@@ -2964,6 +2967,7 @@ while (ptr < endptr) + + if (lastmatchnumber > 0 && p > lastmatchrestart && !hyphenprinted) + fprintf(stdout, "--" STDOUT_NL); ++ hyphenpending = FALSE; + + while (p < ptr) + { +@@ -2977,12 +2981,23 @@ while (ptr < endptr) + } + } + ++ /* If hyphenpending is TRUE here, it was set after outputting some ++ "after" lines (and there are no "before" lines). */ ++ ++ else if (hyphenpending) ++ { ++ fprintf(stdout, "--" STDOUT_NL); ++ hyphenpending = FALSE; ++ hyphenprinted = TRUE; ++ } ++ + /* Now print the matching line(s); ensure we set hyphenpending at the end + of the file if any context lines are being output. */ + + if (after_context > 0 || before_context > 0) + endhyphenpending = TRUE; + ++ + if (printname != NULL) fprintf(stdout, "%s:", printname); + if (number) fprintf(stdout, "%lu:", linenumber); + +diff --git a/testdata/grepinput b/testdata/grepinput +index 1e2ceb4..91d3db8 100644 +--- a/testdata/grepinput ++++ b/testdata/grepinput +@@ -617,6 +617,25 @@ match 5: + Rhubarb + Custard Tart + ++zxc ++cvb ++bnm ++asd ++qwe ++ert ++tyu ++uio ++ggg ++asd ++dfg ++ghj ++jkl ++abc ++def ++ghi ++xyz ++ ++ + PUT NEW DATA ABOVE THIS LINE. + ============================= + +diff --git a/testdata/grepoutput b/testdata/grepoutput +index 66af4cf..ca52d8b 100644 +--- a/testdata/grepoutput ++++ b/testdata/grepoutput +@@ -10,7 +10,7 @@ RC=0 + 7:PATTERN at the start of a line. + 8:In the middle of a line, PATTERN appears. + 10:This pattern is in lower case. +-623:Check up on PATTERN near the end. ++642:Check up on PATTERN near the end. + RC=0 + ---------------------------- Test 4 ------------------------------ + 4 +@@ -19,7 +19,7 @@ RC=0 + ./testdata/grepinput:7:PATTERN at the start of a line. + ./testdata/grepinput:8:In the middle of a line, PATTERN appears. + ./testdata/grepinput:10:This pattern is in lower case. +-./testdata/grepinput:623:Check up on PATTERN near the end. ++./testdata/grepinput:642:Check up on PATTERN near the end. + ./testdata/grepinputx:3:Here is the pattern again. + ./testdata/grepinputx:5:Pattern + ./testdata/grepinputx:42:This line contains pattern not on a line by itself. +@@ -28,7 +28,7 @@ RC=0 + 7:PATTERN at the start of a line. + 8:In the middle of a line, PATTERN appears. + 10:This pattern is in lower case. +-623:Check up on PATTERN near the end. ++642:Check up on PATTERN near the end. + 3:Here is the pattern again. + 5:Pattern + 42:This line contains pattern not on a line by itself. +@@ -104,6 +104,7 @@ pcre2grep: Error in command-line regex at offset 4: quantifier does not follow a + RC=2 + ---------------------------- Test 16 ----------------------------- + pcre2grep: Failed to open ./testdata/nonexistfile: No such file or directory ++./testdata/grepinput:abc + RC=2 + ---------------------------- Test 17 ----------------------------- + features should be added at the end, because some of the tests involve the +@@ -324,10 +325,10 @@ RC=0 + ./testdata/grepinput-9- + ./testdata/grepinput:10:This pattern is in lower case. + -- +-./testdata/grepinput-620-PUT NEW DATA ABOVE THIS LINE. +-./testdata/grepinput-621-============================= +-./testdata/grepinput-622- +-./testdata/grepinput:623:Check up on PATTERN near the end. ++./testdata/grepinput-639-PUT NEW DATA ABOVE THIS LINE. ++./testdata/grepinput-640-============================= ++./testdata/grepinput-641- ++./testdata/grepinput:642:Check up on PATTERN near the end. + -- + ./testdata/grepinputx-1-This is a second file of input for the pcregrep tests. + ./testdata/grepinputx-2- +@@ -349,8 +350,8 @@ RC=0 + ./testdata/grepinput-12-Here follows a whole lot of stuff that makes the file over 24KiB long. + ./testdata/grepinput-13- + -- +-./testdata/grepinput:623:Check up on PATTERN near the end. +-./testdata/grepinput-624-This is the last line of this file. ++./testdata/grepinput:642:Check up on PATTERN near the end. ++./testdata/grepinput-643-This is the last line of this file. + -- + ./testdata/grepinputx:3:Here is the pattern again. + ./testdata/grepinputx-4- +@@ -991,3 +992,32 @@ RC=0 + ---------------------------- Test 134 ----------------------------- + =AB3CD5= + RC=0 ++---------------------------- Test 160 ----------------------------- ++622-bnm ++623-asd ++624-qwe ++625:ert ++626-tyu ++627-uio ++628-ggg ++629-asd ++630-dfg ++631-ghj ++632:jkl ++633-abc ++634-def ++635-ghi ++RC=0 ++621-cvb ++622-bnm ++623-asd ++624-qwe ++625:ert ++626-tyu ++627-uio ++628-ggg ++629-asd ++630:dfg ++631-ghj ++632-jkl ++RC=0 +-- +2.23.0 \ No newline at end of file diff --git a/pcre2.spec b/pcre2.spec index f910324..cc7cade 100644 --- a/pcre2.spec +++ b/pcre2.spec @@ -1,6 +1,6 @@ Name: pcre2 Version: 10.42 -Release: 12 +Release: 13 Summary: Perl Compatible Regular Expressions License: BSD URL: http://www.pcre.org/ @@ -44,6 +44,8 @@ Patch6032: backport-avoid-inconsistency-between-d-and-digit-when-using-a.pat Patch6033: backport-Fix-the-lookahead-after-d-or-posix-to-skip-whitespac.patch Patch6034: backport-Improve-error-offsets-for-character-classes-548.patch Patch6035: backport-Non-recursive-scan-prefix-in-JIT-560.patch +Patch6036: backport-Fix-oversight-in-adding-new-pcre2grep-test.patch +Patch6037: backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch BuildRequires: autoconf libtool automake coreutils gcc make readline-devel Obsoletes: pcre2-utf16 pcre2-utf32 pcre2-tools @@ -161,6 +163,9 @@ make check %{_pkgdocdir}/html/ %changelog +*Thu Mar 13 2025 Linux_zhang - 10.42-13 +- DESC:sync patches from upstream to fix a bug in pcre2grep + * Tue Dec 10 2024 hugel - 10.42-12 - DESC:sync patches from upstream backport-Further-ASCII-tests-and-minor-bugfix-plus-ChangeLog-.patch -- Gitee From c858307b3bf72c8d625a2ee08866b92de686077f Mon Sep 17 00:00:00 2001 From: Linux_zhang Date: Thu, 13 Mar 2025 06:28:43 +0000 Subject: [PATCH 2/3] update backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch. Signed-off-by: Linux_zhang --- ...re2grep-that-caused-separator-lines-.patch | 79 +++++++++---------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch b/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch index 6d3bc07..c31c9d9 100644 --- a/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch +++ b/backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch @@ -1,74 +1,73 @@ -From 7a7b2ba4a474c701530e39eba9be87faff9a382a Mon Sep 17 00:00:00 2001 +From f34fc0a34ab18d7cb0ff27eacaea43912d797a27 Mon Sep 17 00:00:00 2001 From: Philip Hazel Date: Wed, 27 Nov 2024 15:15:45 +0000 Subject: [PATCH] Mend a bug in pcre2grep that caused separator lines to be incorrectly inserted in some cases when above/below context lines are contiguous. Reported by Alejandro Colomar . Fixes GitHub issue #577. - -Conflict:adapt context; don't modify ChangeLog; don't use group_separator -because e179a4b8c is not merged + +Conflict:adapt context; don't modify ChangeLog; don't use group_separator because e179a4b8c is not merged Reference:https://github.com/PCRE2Project/pcre2/commit/f34fc0a34ab18d7cb0ff27eacaea43912d797a27 + --- - RunGrepTest | 7 +++++++ + RunGrepTest | 6 +++++- src/pcre2grep.c | 19 ++++++++++++++++-- testdata/grepinput | 19 ++++++++++++++++++ testdata/grepoutput | 48 ++++++++++++++++++++++++++++++++++++--------- - 4 files changed, 82 insertions(+), 11 deletions(-) - + 4 files changed, 80 insertions(+), 12 deletions(-) + diff --git a/RunGrepTest b/RunGrepTest -index 9682c5f..e8ab6e5 100755 +index 0a00e82..0d57707 100755 --- a/RunGrepTest +++ b/RunGrepTest -@@ -685,6 +685,13 @@ echo "---------------------------- Test 134 -----------------------------" >>tes - (cd $srcdir; $valgrind $vjs $pcre2grep -m1 -O '=$x{41}$x423$o{103}$o1045=' 'fox') <$srcdir/testdata/grepinputv >>testtrygrep 2>&1 - echo "RC=$?" >>testtrygrep - +@@ -853,7 +853,11 @@ fi + echo "---------------------------- Test 151 -----------------------------" >>testtrygrep + (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always -e this -e The -e 'The wo' testdata/grepinputv) >>testtrygrep + +- +echo "---------------------------- Test 160 -----------------------------" >>testtrygrep +(cd $srcdir; $valgrind $vjs $pcre2grep -nC3 '^(ert|jkl)' ./testdata/grepinput) >>testtrygrep +echo "RC=$?" >>testtrygrep +(cd $srcdir; $valgrind $vjs $pcre2grep -n -B4 -A2 '^(ert|dfg)' ./testdata/grepinput) >>testtrygrep +echo "RC=$?" >>testtrygrep -+ -+ + + # Now compare the results. - - $cf $srcdir/testdata/grepoutput testtrygrep diff --git a/src/pcre2grep.c b/src/pcre2grep.c -index 72c11bc..7f92f7d 100644 +index 6a5841c..c155c6c 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c -@@ -2934,12 +2934,15 @@ while (ptr < endptr) +@@ -2940,12 +2940,15 @@ while (ptr < endptr) FWRITE_IGNORE(lastmatchrestart, 1, pp - lastmatchrestart, stdout); lastmatchrestart = pp; } + if (lastmatchrestart != ptr) hyphenpending = TRUE; } - + - /* If there were non-contiguous lines printed above, insert hyphens. */ -+ /* If hyphenpending is TRUE when there is no "after" context, it means we -+ are at the start of a new file, having output something from the previous ++ /* If hyphenpending is TRUE when there is no "after" context, it means we ++ are at the start of a new file, having output something from the previous + file. Output a separator if enabled.*/ - + - if (hyphenpending) + else if (hyphenpending) { fprintf(stdout, "--" STDOUT_NL); hyphenpending = FALSE; -@@ -2964,6 +2967,7 @@ while (ptr < endptr) - +@@ -2970,6 +2973,7 @@ while (ptr < endptr) + if (lastmatchnumber > 0 && p > lastmatchrestart && !hyphenprinted) fprintf(stdout, "--" STDOUT_NL); + hyphenpending = FALSE; - + while (p < ptr) { -@@ -2977,12 +2981,23 @@ while (ptr < endptr) +@@ -2984,12 +2988,23 @@ while (ptr < endptr) } } - -+ /* If hyphenpending is TRUE here, it was set after outputting some + ++ /* If hyphenpending is TRUE here, it was set after outputting some + "after" lines (and there are no "before" lines). */ + + else if (hyphenpending) @@ -80,14 +79,14 @@ index 72c11bc..7f92f7d 100644 + /* Now print the matching line(s); ensure we set hyphenpending at the end of the file if any context lines are being output. */ - + if (after_context > 0 || before_context > 0) endhyphenpending = TRUE; - + + - if (printname != NULL) fprintf(stdout, "%s:", printname); + if (printname != NULL) fprintf(stdout, "%s%c", printname, + printname_colon); if (number) fprintf(stdout, "%lu:", linenumber); - diff --git a/testdata/grepinput b/testdata/grepinput index 1e2ceb4..91d3db8 100644 --- a/testdata/grepinput @@ -95,7 +94,7 @@ index 1e2ceb4..91d3db8 100644 @@ -617,6 +617,25 @@ match 5: Rhubarb Custard Tart - + +zxc +cvb +bnm @@ -117,9 +116,9 @@ index 1e2ceb4..91d3db8 100644 + PUT NEW DATA ABOVE THIS LINE. ============================= - + diff --git a/testdata/grepoutput b/testdata/grepoutput -index 66af4cf..ca52d8b 100644 +index aa53aab..df658ed 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -10,7 +10,7 @@ RC=0 @@ -183,10 +182,10 @@ index 66af4cf..ca52d8b 100644 -- ./testdata/grepinputx:3:Here is the pattern again. ./testdata/grepinputx-4- -@@ -991,3 +992,32 @@ RC=0 - ---------------------------- Test 134 ----------------------------- - =AB3CD5= - RC=0 +@@ -1232,3 +1233,32 @@ RC=2 + The word is cat in this line + The caterpillar sat on the mat + The snowcat is not an animal +---------------------------- Test 160 ----------------------------- +622-bnm +623-asd @@ -217,4 +216,4 @@ index 66af4cf..ca52d8b 100644 +632-jkl +RC=0 -- -2.23.0 \ No newline at end of file +2.23.0 -- Gitee From 1d7c11a4277629b71e91d3c6ff402b0217ed819b Mon Sep 17 00:00:00 2001 From: Linux_zhang Date: Thu, 13 Mar 2025 14:32:03 +0800 Subject: [PATCH 3/3] sync patches from upstream to fix a bug in pcre2grep --- pcre2.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcre2.spec b/pcre2.spec index cc7cade..ae2da0c 100644 --- a/pcre2.spec +++ b/pcre2.spec @@ -44,8 +44,8 @@ Patch6032: backport-avoid-inconsistency-between-d-and-digit-when-using-a.pat Patch6033: backport-Fix-the-lookahead-after-d-or-posix-to-skip-whitespac.patch Patch6034: backport-Improve-error-offsets-for-character-classes-548.patch Patch6035: backport-Non-recursive-scan-prefix-in-JIT-560.patch -Patch6036: backport-Fix-oversight-in-adding-new-pcre2grep-test.patch -Patch6037: backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch +Patch6036: backport-Mend-a-bug-in-pcre2grep-that-caused-separator-lines-.patch +Patch6037: backport-Fix-oversight-in-adding-new-pcre2grep-test.patch BuildRequires: autoconf libtool automake coreutils gcc make readline-devel Obsoletes: pcre2-utf16 pcre2-utf32 pcre2-tools -- Gitee