git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: improve performance of PCRE2 bug 2642 bug workaround

From
Paul Eggert <eggert@cs.ucla.edu>
Date
Mar 22, 2022, 21:12 UTC
Message-ID
<325b7ba6-04a8-0010-a288-a118a820f3c3@cs.ucla.edu>
In-Reply-To
<99b0adb6-26ba-293c-3a8f-679f59e7cb4d@web.de>
On 3/22/22 13:26, René Scharfe wrote:
> However, the looser check works around another bug, if only by accident.

Thanks for letting me know. In that case, GNU grep should use a looser check too, like Git grep does. I installed the attached into GNU grep.

From ff2d24b08223e6c7b704a91127bac4391a9b8adb Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 22 Mar 2022 14:09:05 -0700
Subject: [PATCH] grep: work around another potential PCRE2 bug
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Potential problem reported by René Scharfe in:
https://lore.kernel.org/git/99b0adb6-26ba-293c-3a8f-679f59e7cb4d@web.de/T
* src/pcresearch.c (Pcompile): Mimic git grep’s workarounds
for PCRE2 bugs more closely; this is more conservative.
---
 src/pcresearch.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/pcresearch.c b/src/pcresearch.c
index 0cf804d..6947838 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -154,15 +154,16 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact)
 #ifdef PCRE2_MATCH_INVALID_UTF
       /* Consider invalid UTF-8 as a barrier, instead of error.  */
       flags |= PCRE2_MATCH_INVALID_UTF;
-
-# if ! (10 < PCRE2_MAJOR + (36 <= PCRE2_MINOR))
-      /* Work around PCRE2 bug 2642.  */
-      if (flags & PCRE2_CASELESS)
-        flags |= PCRE2_NO_START_OPTIMIZE;
-# endif
 #endif
     }
 
+#if defined PCRE2_MATCH_INVALID_UTF && !(10 < PCRE2_MAJOR + (36 <= PCRE2_MINOR))
+  /* Work around PCRE2 bug 2642, and another bug reportedly fixed in
+     PCRE2 commit e0c6029a62db9c2161941ecdf459205382d4d379.  */
+  if (flags & (PCRE2_UTF | PCRE2_CASELESS))
+    flags |= PCRE2_NO_START_OPTIMIZE;
+#endif
+
   /* FIXME: Remove this restriction.  */
   if (rawmemchr (pattern, '\n') != patlim)
     die (EXIT_TROUBLE, 0, _("the -P option only supports a single pattern"));
-- 
2.32.0
Previous: René ScharfeNext: Carlo Marcelo Arenas Belón
Message 3 of 7 in “improve performance of PCRE2 bug 2642 bug workaround”
  1. Paul EggertMar 22, 2022
  2. René ScharfeMar 22, 2022
  3. Paul EggertMar 22, 2022
  4. Carlo Marcelo Arenas BelónMar 23, 2022
  5. Paul EggertMar 23, 2022
  6. René ScharfeMar 23, 2022
  7. Carlo ArenasMar 23, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.