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

Re: [PATCH] grep: disable lookahead on error

From
DGDavid Gstir <david@sigma-star.at>
Date
Oct 22, 2024, 05:58 UTC
Message-ID
<494E7060-B824-4663-B49D-A645A8A67711@sigma-star.at>
In-Reply-To
<7a51a68e-5f9d-4444-a568-9ca180bc4c6b@web.de>
Hi René,
Show 25 quoted lines
> On 20.10.2024, at 13:02, René Scharfe <l.s.r@web.de> wrote:
> 
> regexec(3) can fail.  E.g. on macOS it fails if it is used with an UTF-8
> locale to match a valid regex against a buffer containing invalid UTF-8
> characters.
> 
> git grep has two ways to search for matches in a file: Either it splits
> its contents into lines and matches them separately, or it matches the
> whole content and figures out line boundaries later.  The latter is done
> by look_ahead() and it's quicker in the common case where most files
> don't contain a match.
> 
> Fall back to line-by-line matching if look_ahead() encounters an
> regexec(3) error by propagating errors out of patmatch() and bailing out
> of look_ahead() if there is one.  This way we at least can find matches
> in lines that contain only valid characters.  That matches the behavior
> of grep(1) on macOS.
> 
> pcre2match() dies if pcre2_jit_match() or pcre2_match() fail, but since
> we use the flag PCRE2_MATCH_INVALID_UTF it handles invalid UTF-8
> characters gracefully.  So implement the fall-back only for regexec(3)
> and leave the PCRE2 matching unchanged.
> 
> Reported-by: David Gstir <david@sigma-star.at>
> Signed-off-by: René Scharfe <l.s.r@web.de>
thanks for fixing this! I’ve tested it on my end and your patch works. Feel free to add my Tested-By.

Thanks, David

Previous: Taylor Blau
Message 6 of 6 in “git grep does not find all occurrences on macOS”
  1. David GstirOct 14, 2024
  2. Taylor BlauOct 15, 2024
  3. René ScharfeOct 15, 2024
  4. grep: disable lookahead on errorRené Scharfe, Oct 20, 2024
  5. Taylor BlauOct 21, 2024
  6. David GstirOct 22, 2024

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.