Skip to content

Commit 14b9a04

Browse files
minipli-ossgitster
authored andcommitted
grep: work around UTF-8 related JIT bug in PCRE2 <= 10.34
Stephane is reporting[1] a regression introduced in git v2.40.0 that leads to 'git grep' segfaulting in his CI pipeline. It turns out, he's using an older version of libpcre2 that triggers a wild pointer dereference in the generated JIT code that was fixed in PCRE2 10.35. Instead of completely disabling the JIT compiler for the buggy version, just mask out the Unicode property handling as we used to do prior to commit acabd20 ("grep: correctly identify utf-8 characters with \{b,w} in -P"). [1] https://lore.kernel.org/git/[email protected]/ Reported-by: Stephane Odul <[email protected]> Signed-off-by: Mathias Krause <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent acabd20 commit 14b9a04

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

grep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
295295
if (!opt->ignore_locale && is_utf8_locale() && !literal)
296296
options |= (PCRE2_UTF | PCRE2_UCP | PCRE2_MATCH_INVALID_UTF);
297297

298+
#ifndef GIT_PCRE2_VERSION_10_35_OR_HIGHER
299+
/*
300+
* Work around a JIT bug related to invalid Unicode character handling
301+
* fixed in 10.35:
302+
* https://github.com/PCRE2Project/pcre2/commit/c21bd977547d
303+
*/
304+
options &= ~PCRE2_UCP;
305+
#endif
306+
298307
#ifndef GIT_PCRE2_VERSION_10_36_OR_HIGHER
299308
/* Work around https://bugs.exim.org/show_bug.cgi?id=2642 fixed in 10.36 */
300309
if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS))

grep.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11
88
#define GIT_PCRE2_VERSION_10_36_OR_HIGHER
99
#endif
10+
#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 35) || PCRE2_MAJOR >= 11
11+
#define GIT_PCRE2_VERSION_10_35_OR_HIGHER
12+
#endif
1013
#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 34) || PCRE2_MAJOR >= 11
1114
#define GIT_PCRE2_VERSION_10_34_OR_HIGHER
1215
#endif

0 commit comments

Comments
 (0)