From: Carlo Marcelo Arenas Belón Date: Tue, 16 Nov 2021 11:00:35 GMT Subject: [PATCH] grep: avoid setting UTF mode when not needed Message-ID: <20211116110035.22140-1-carenas@gmail.com> In-Reply-To: <87bl2kv309.fsf@igel.home> Since ae39ba431a (grep/pcre2: fix an edge case concerning ascii patterns and UTF-8 data, 2021-10-15), PCRE_UTF mode is enabled in cases where it will fail because of UTF-8 validation, which is needed for versions of PCRE2 older than 10.34. Revert the change on logic to avoid failures that were reported from the test cases, but that should also reflect in normal use when JIT is enabled and could result in crashes (or worse), as UTF-8 validation is skipped. Keeping the tests, as they pass even without the fix as replicated locally in Debian 10 and the CI. Reported-by: Andreas Schwab Signed-off-by: Carlo Marcelo Arenas Belón --- grep.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/grep.c b/grep.c index f6e113e9f0..fe847a0111 100644 --- a/grep.c +++ b/grep.c @@ -382,10 +382,8 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt } options |= PCRE2_CASELESS; } - if ((!opt->ignore_locale && !has_non_ascii(p->pattern)) || - (!opt->ignore_locale && is_utf8_locale() && - has_non_ascii(p->pattern) && !(!opt->ignore_case && - (p->fixed || p->is_fixed)))) + if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern) && + !(!opt->ignore_case && (p->fixed || p->is_fixed))) options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF); #ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER -- 2.34.0.352.g07dee3c5e1