Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hx14b-0005Gf-HC for pgsql-committers@arkaria.postgresql.org; Mon, 12 Aug 2019 03:32:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hx14a-0000oD-BA for pgsql-committers@arkaria.postgresql.org; Mon, 12 Aug 2019 03:32:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hx14Z-0000gM-T1 for pgsql-committers@lists.postgresql.org; Mon, 12 Aug 2019 03:32:40 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1hx14W-0005fh-Jt for pgsql-committers@lists.postgresql.org; Mon, 12 Aug 2019 03:32:38 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 5F3DD21C2389 for ; Mon, 12 Aug 2019 06:32:34 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (not verified)) by mail.postgrespro.ru (Postfix) with ESMTPSA id CE78E21C0919 for ; Mon, 12 Aug 2019 06:32:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1565580754; bh=AfhYLZtbru9U1jsT3r+nXkRdTNZODHzBlrlp/7RMtkc=; h=References:In-Reply-To:From:Date:Subject:To:Cc; b=GHxL1rivL4mvvrKsXOyi5t3BqMs0O+dT6AUt5iXpmNOM6r93IPEw/mJmktQ2h3bzk qRmFVp3D5+nDLrrICc6mKkt57lwVNZVhtPDvyyiJby2qtqVSPwfb9B5PqPiw3JGoId Y2sUXM8x7BXJyK5b9pIw1GvFxXfkeq8GCI1NRLR4= Received: by mail-ot1-f54.google.com with SMTP id j7so9291482ota.9 for ; Sun, 11 Aug 2019 20:32:33 -0700 (PDT) X-Gm-Message-State: APjAAAVVofekBGT54s5FD9DnIWK1AITgq5KSSoK8qpCExWyHX5QaUY42 SMGd7kbIs0qzd0/bnjCpp+t6/a8F/zR/v85/NG8= X-Google-Smtp-Source: APXvYqyYhAS43825Y/s95L7Y4rXxfSQrex34oebaP+GLUiZpDpRZnV66ZNO5NBvlIWktlN3gEeGM41an3N1lohh6sf4= X-Received: by 2002:a02:90c8:: with SMTP id c8mr12657892jag.22.1565580752339; Sun, 11 Aug 2019 20:32:32 -0700 (PDT) MIME-Version: 1.0 References: <0ed83a33-d900-466a-880a-70ef456c721f@2ndQuadrant.com> In-Reply-To: From: Alexander Korotkov Date: Mon, 12 Aug 2019 06:32:19 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: pgsql: Adjust string comparison in jsonpath To: Thomas Munro Cc: Andrew Dunstan , Alexander Korotkov , pgsql-committers Content-Type: multipart/alternative; boundary="0000000000009c46c7058fe32c01" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000009c46c7058fe32c01 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =D0=BF=D0=BD, 12 =D0=B0=D0=B2=D0=B3. 2019 =D0=B3., 3:25 Thomas Munro : > On Mon, Aug 12, 2019 at 10:30 AM Alexander Korotkov > wrote: > > > > This appears to have upset prion when testing on en_US.iso885915. > > > > > > Also lapwing's "InstallCheck-fr_FR" stage crashed on this commit, whe= n > > > running JSON queries, on HEAD and REL_12_STABLE: > > > Thank you for pointing! I hope I can investigate this shortly. > > Hi Alexander, > > I can reproduce this by running LANG=3D"fr_FR.ISO8859-1" initdb, then > running installcheck (on some other OSes that might be called just > "fr_FR"). See this comment in mbutils.c: > > * The functions return a palloc'd, null-terminated string if conversion > * is required. However, if no conversion is performed, the given source > * string pointer is returned as-is. > > You call pfree() on the result of pg_server_to_any() without checking > if it just returned in the input pointer (for example, it does that if > you give it an empty string). That triggers an assertion failure > somewhere inside pfree(). The following fixes that for me, and is > based on code I found elsewhere in the tree. > > --- a/src/backend/utils/adt/jsonpath_exec.c > +++ b/src/backend/utils/adt/jsonpath_exec.c > @@ -2028,8 +2028,10 @@ compareStrings(const char *mbstr1, int mblen1, > cmp =3D binaryCompareStrings(utf8str1, strlen(utf8str1), > > utf8str2, strlen(utf8str2)); > > - pfree(utf8str1); > - pfree(utf8str2); > + if (mbstr1 !=3D utf8str1) > + pfree(utf8str1); > + if (mbstr2 !=3D utf8str2) > + pfree(utf8str2); > > With that fixed it no longer crashes, but then the regression test > fails due to differences in the output, which look like locale > ordering differences. > Thank you for the diagnostics. Should be fixed by 251c8e39. BTW, test failures appears to be caused not by locale differences, but by using strlen() on non null-terminated original strings. ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company > --0000000000009c46c7058fe32c01 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
=D0=BF=D0=BD= , 12 =D0=B0=D0=B2=D0=B3. 2019 =D0=B3., 3:25 Thomas Munro <thomas.munro@gmail.com>:
On Mon, Aug 12, 2019 at= 10:30 AM Alexander Korotkov
<a.korotkov@postgrespro.ru> wrote:
> > > This appears to have upset prion when testing on en_US.iso88= 5915.
> >
> > Also lapwing's "InstallCheck-fr_FR" stage crashed o= n this commit, when
> > running JSON queries, on HEAD and REL_12_STABLE:

> Thank you for pointing!=C2=A0 I hope I can investigate this shortly.
Hi Alexander,

I can reproduce this by running LANG=3D"fr_FR.ISO8859-1" initdb, = then
running installcheck (on some other OSes that might be called just
"fr_FR").=C2=A0 See this comment in mbutils.c:

=C2=A0* The functions return a palloc'd, null-terminated string if conv= ersion
=C2=A0* is required.=C2=A0 However, if no conversion is performed, the give= n source
=C2=A0* string pointer is returned as-is.

You call pfree() on the result of pg_server_to_any() without checking
if it just returned in the input pointer (for example, it does that if
you give it an empty string).=C2=A0 That triggers an assertion failure
somewhere inside pfree().=C2=A0 The following fixes that for me, and is
based on code I found elsewhere in the tree.

--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -2028,8 +2028,10 @@ compareStrings(const char *mbstr1, int mblen1,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cmp =3D binaryCompa= reStrings(utf8str1, strlen(utf8str1),

utf8str2, strlen(utf8str2));

-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pfree(utf8str1); -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pfree(utf8str2); +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (mbstr1 !=3D utf= 8str1)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0pfree(utf8str1);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (mbstr2 !=3D utf= 8str2)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0pfree(utf8str2);

With that fixed it no longer crashes, but then the regression test
fails due to differences in the output, which look like locale
ordering differences.

Thank you for the diagnostics.=C2=A0 Should be fixed b= y 251c8e39.

BTW, test fa= ilures appears to be caused not by locale differences, but by using strlen(= ) on non null-terminated original strings.

------
Ale= xander Korotkov
Postgres Professional:=C2=A0http://www.postgrespro.com
The Russian Postgres C= ompany
--0000000000009c46c7058fe32c01--