Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
От:
Ewan Young <kdbase.hack@gmail.com>
Дата:
Hi,
I reviewed the v2 patch.
The patch applies cleanly on the current master (4cb2a9863d8). I built with
--enable-cassert and ICU, and confirmed that the three backslash test
cases give wrong results on unpatched master and the expected results
with the patch applied. The full regression suite passes (245/245),
including the updated collate.icu.utf8 test.
Two comments:
1. The commit message describes the symptom as "an incorrect match
failure", but the bug also causes incorrect matches in the other
direction. Since the unescaping logic dropped the literal backslash
from the pattern, a text *without* a backslash could wrongly match a
pattern that requires one:
SELECT 'backslash' COLLATE ignore_accents LIKE 'back\\slash%';
-- unpatched: t (wrong), patched: f (correct)
I think it's worth mentioning this false-positive side of the bug in
the commit message, since silently-too-permissive LIKE filters are
arguably the more dangerous symptom for applications.
2. A small typo in the new comment in like_match.c:
"occurences" should be "occurrences".
Best regards
On Fri, Jun 5, 2026 at 7:21 PM Nitin Motiani wrote:
>
> Hi,
>
> I have created a commitfest entry for this patch here
> https://commitfest.postgresql.org/patch/6844/. Please take a look.
>
> Thanks,
> Nitin Motiani
> Google
>
>
>
>
Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
> I reviewed the v2 patch. > Thanks for the feedback. > > 1. The commit message describes the symptom as "an incorrect match > failure", but the bug also causes incorrect matches in the other > direction. Since the unescaping logic dropped the literal backslash > from the pattern, a text *without* a backslash could wrongly match a > pattern that requires one: > > SELECT 'backslash' COLLATE ignore_accents LIKE 'back\\slash%'; > -- unpatched: t (wrong), patched: f (correct) > > I think it's worth mentioning this false-positive side of the bug in > the commit message, since silently-too-permissive LIKE filters are > arguably the more dangerous symptom for applications. > I have updated the commit message. I also added another test for this scenario in v3. > 2. A small typo in the new comment in like_match.c: > "occurences" should be "occurrences". > Fixed the typo. Thanks, Nitin Motiani Google
Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
От:
Ewan Young <kdbase.hack@gmail.com>
Дата:
Hi Nitin,
Thanks for v3.
I re-applied it on top of current master (4cb2a986) and re-ran the
regression suite: all 245 tests pass, and the collate.icu.utf8 set now
covers both directions of the bug, including the false-positive case
('backslash' LIKE 'back\\slash%' -> f).
LGTM, and changed commitfest status to "Ready for Commiter".
Regards,
Ewan Young
On Sat, Jun 6, 2026 at 8:25 PM Nitin Motiani wrote:
>
> > I reviewed the v2 patch.
> >
>
> Thanks for the feedback.
>
> >
> > 1. The commit message describes the symptom as "an incorrect match
> > failure", but the bug also causes incorrect matches in the other
> > direction. Since the unescaping logic dropped the literal backslash
> > from the pattern, a text *without* a backslash could wrongly match a
> > pattern that requires one:
> >
> > SELECT 'backslash' COLLATE ignore_accents LIKE 'back\\slash%';
> > -- unpatched: t (wrong), patched: f (correct)
> >
> > I think it's worth mentioning this false-positive side of the bug in
> > the commit message, since silently-too-permissive LIKE filters are
> > arguably the more dangerous symptom for applications.
> >
>
> I have updated the commit message. I also added another test for this
> scenario in v3.
>
> > 2. A small typo in the new comment in like_match.c:
> > "occurences" should be "occurrences".
> >
>
> Fixed the typo.
>
> Thanks,
> Nitin Motiani
> Google
Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Nitin Motiani writes: > I have updated the commit message. I also added another test for this > scenario in v3. I don't think this patch is ready. It is wasting code and cycles to fix a nonexistent problem. We are working in a backend-safe encoding, therefore it is not possible for one byte of a multibyte character to match '\' (nor '_' nor '%'). So the existing logic that pays no attention to multibyte boundaries is not wrong, and if it were then the preceding loop that looks for the end of the literal-match substring would also be wrong (as well as some hundreds of other places that make similar assumptions). This code does get consecutive-backslash cases wrong, and we need to fix that, but we don't need to add complexity to fix something that's not broken. regards, tom lane
Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
On Sat, Jul 4, 2026 at 3:03 AM Tom Lane wrote: > > I don't think this patch is ready. It is wasting code and cycles to > fix a nonexistent problem. We are working in a backend-safe encoding, > therefore it is not possible for one byte of a multibyte character to > match '\' (nor '_' nor '%'). So the existing logic that pays no > attention to multibyte boundaries is not wrong, and if it were then > the preceding loop that looks for the end of the literal-match > substring would also be wrong (as well as some hundreds of other > places that make similar assumptions). > > This code does get consecutive-backslash cases wrong, and we need > to fix that, but we don't need to add complexity to fix something > that's not broken. > Thanks for the feedback, Tom. I have removed the logic for the multibyte check and simplified the code. Please take a look at the latest patch. Regards, Nitin Motiani Google
Re: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Nitin Motiani writes: > Thanks for the feedback, Tom. I have removed the logic for the > multibyte check and simplified the code. Please take a look at the > latest patch. Oh ... I simplified the patch and pushed it just moments ago. Should have had a longer timeout, sorry about that. regards, tom lane