On Fri, Jul 26 2019, Carlo Arenas wrote: > On Fri, Jul 26, 2019 at 8:15 AM Ævar Arnfjörð Bjarmason > <avarab@xxxxxxxxx> wrote: >> I'm not sure what a real fix for that is. Part of it is probably 8/8 in >> the series I mention below, but more generally we'd need to be more >> encoding aware at a much higher callsite than "grep". So e.g. we'd know >> that we match "binary" data as not-UTF-8. Now we just throw arbitrary >> bytes around and hope something sticks. > > I haven't look yet at your proposed changes, but my gut feeling is that > the work to support invalid UTF in the yet unreleased PCRE version would > be needed as part of it, and therefore it might be better to keep PCRE > out of the main path until that gets released and can be relied upon. I'm hoping my 8-part series is good enough to move it forward, but as 48de2a768c ("grep: remove the kwset optimization", .2019-07-01) shows we can always just fall back on using regcomp instead. > kwset is not going away with this series anyway, regardless of the no-kwset > name on the branch. The larger context here is that this is the 1st step of a 2-step series to get rid of kwset. If I can pull that off successfully is another matter, but that's the plan. After it's applied we just use it in the pickaxe code, and it's relatively straightforward to convert that. See: https://public-inbox.org/git/87v9x793qi.fsf@xxxxxxxxxxxxxxxxxxx/ >> > If we're already deciding to paper over things, I'd much rather prefer >> > the simpler patch, i.e. Carlo's. >> >> As I noted upthread PCRE's own docs promise undefined behavior and fire >> and brimstone if that patch is applied. Those last two not >> guaranteed. So we need another solution. > > in my original reply I mentioned I explicitly didn't do a test because of this > "undefined behavior", but I think it should be fair to mention that we are > already affected by that because using the JIT fast path does skip any > UTF-8 validations and is currently possible to get git into an infinite loop > or make it segfault when using PCRE. Right, this is a good point that we should take notice of. I.e. this is *not* a new bug per-se, you can do this on master and get a UTF-8 bug from git.git: git grep -P '(*NO_JIT)[æ]' > in that line, I am not sure I understand the pushback against making that > explicit since it only makes both codepaths behave the same (bugs and > risks of burning alike) Because with my kwset series we're getting a lot more users of this until-now obscure code, so we're finding old-but-new-to-us bugs. We've had this bug dating all the way back to Duy's 18547aacf5 ("grep/pcre: support utf-8", 2016-06-25). It was first released with git 2.10. So why are we getting list discussion about it *now*? Because my kwset series got merged to "next", and we apparently have a lot of users who'd use fixed-string git-grep under locales, but never used PCRE via -P explicitly before. So it's worth getting the semantics right. As noted in the E-Mail I linked to earlier my ulterior motive here is to get to a point where we'll funnel all regex matching through PCRE implicitly if it's available. We need to get these UTF-8 edge cases right. I don't know if my recent 8-part series gets us 100% there, but hopefully it at least gets us closer to it.