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

Re: [PATCH v2 2/4] diff.c: implement a sanity check for word regexes

From
Thomas Rast <trast@student.ethz.ch>
Date
Dec 19, 2010, 01:59 UTC
Message-ID
<201012190259.45301.trast@student.ethz.ch>
In-Reply-To
<7vvd2qg5jj.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 10 quoted lines
> Thomas Rast <trast@student.ethz.ch> writes:
> 
> > * The word regex matches anything that is !isspace().
> >
> > * The word regex does not match '\n'.  (This case is not very harmful,
> >   but we used to silently cut off at the '\n' which may go against
> >   user expectations.)
> 
> How expensive to run this check twice, every time word_regex finds a
> match?

It runs the first bullet point for every non-match, and the second bullet point for every match. So it looks at every input character exactly once.

Show 5 quoted lines
> As this is about making sure that we got a sane regex from the user (or a
> builtin pattern), I wonder if we can make it not depend on the payload we
> are matching the regex against.  Then before using a word_regex that we
> have not checked, we check if that regex is sane, mark it checked, and do
> not have to do the check over and over again.

Algorithmically it should be easy once you have the finite state automaton corresponding to the regex: just verify that for every possible non-terminal state, there is a transition for every !isspace() character to a state other than "fail to match" or "match the empty string".

In the implementation, it might be doable if we switch to compat/regex on all platforms, since we then have ready access to all internal structures regcomp() creates, including the DFA.

I'll think about at least using compat/regex for a static check of all *builtin* patterns, which would be superior to the brute force approach in 4/4.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Junio C HamanoNext: Thomas Rast
Message 12 of 23 in “--word-regex sanity checking and such”
  1. 0/4 --word-regex sanity checking and suchThomas Rast, Dec 15, 2010
  2. 1/4 diff.c: pass struct diff_words into find_word_boundariesThomas Rast, Dec 15, 2010
  3. 2/4 diff.c: implement a sanity check for word regexesThomas Rast, Dec 15, 2010
  4. 3/4 userdiff: fix typo in ruby word regexThomas Rast, Dec 15, 2010
  5. 4/4 t4034: bulk verify builtin word regex sanityThomas Rast, Dec 15, 2010
  6. Thomas RastDec 15, 2010
  7. Scott JohnsonDec 15, 2010
  8. 0/4 --word-regex sanity checking and suchThomas Rast, Dec 18, 2010
  9. 1/4 diff.c: pass struct diff_words into find_word_boundariesThomas Rast, Dec 18, 2010
  10. 2/4 diff.c: implement a sanity check for word regexesThomas Rast, Dec 18, 2010
  11. Junio C HamanoDec 18, 2010
  12. Thomas RastDec 19, 2010
  13. 3/4 userdiff: fix typo in ruby and python word regexesThomas Rast, Dec 18, 2010
  14. Junio C HamanoDec 18, 2010
  15. Thomas RastDec 19, 2010
  16. 4/4 t4034: bulk verify builtin word regex sanityThomas Rast, Dec 18, 2010
  17. 0/3 Re: t4034: bulk verify builtin word regex sanityJonathan Nieder, Jan 11, 2011
  18. 1/3 t4034: bulk verify builtin word regex sanityJonathan Nieder, Jan 11, 2011
  19. Re*: [PATCH 1/3] t4034: bulk verify builtin word regex sanityJunio C Hamano, Jan 18, 2011
  20. 2/3 userdiff: simplify word-diff safeguardJonathan Nieder, Jan 11, 2011
  21. 3/3 t4034 (diff --word-diff): style suggestionsJonathan Nieder, Jan 11, 2011
  22. Thomas RastDec 18, 2010
  23. Junio C HamanoDec 18, 2010

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.