Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ppESb-0001mT-6H for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Apr 2023 20:31:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ppESZ-0006AV-Ve for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Apr 2023 20:31:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ppESZ-0006AM-HZ for pgsql-bugs@lists.postgresql.org; Wed, 19 Apr 2023 20:31:23 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ppESW-000kWq-K6 for pgsql-bugs@lists.postgresql.org; Wed, 19 Apr 2023 20:31:22 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-246eebbde1cso136412a91.3 for ; Wed, 19 Apr 2023 13:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20221208.gappssmtp.com; s=20221208; t=1681936279; x=1684528279; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=LeaS4YobmF7YLyZy6eL3tNANHCN+7pJy3toJ1JwCuQU=; b=2MhjioXuFL1WyYgyI7k6FPtx+sVMfSp73BYoN+mnIYE4sN/IBiAbVLclb6Eo7Fb+Wc 8gxhoE61ePuwjC9Kd16x4OBnbtelZBxdx2lYwA7sHMWDFgg3P1K5lB52e2oBsucIhkUq oMOWONXGcYrnL6inoGBhB4yUsEuI4WHLtledVKtvk8zM44QNP3tGqcy8Pxit1Cs6fmAu kqxySi1AYDSQstcLu3UN6uAtN200vKOz2ndquwAFQzro0DvFtTVPSMEDhYiJ5jG0w188 H+3FQt3LkAhNPl/6UY0vcXoxf/ETbe89JwcKNnMMGGcy45tzP5afrkcFx7DLc1HtJF/l 9JJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681936279; x=1684528279; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LeaS4YobmF7YLyZy6eL3tNANHCN+7pJy3toJ1JwCuQU=; b=JCvcxKpTqx2XAc8WTEHzK/LK5KE7tHVMNWkeIn9U48NGmcbpg9qIMlAEMI08EQY024 UnIW3EKnNHChpL4ODGb6hbefzFqOCLhbUpzRJjdyirRMc73mkN2dC8GyWXJgY4QmSUdC NauIGW+uk99wqDmufx5nyCw8pNVdAeL+bU4HHF6Xe1SyccBHSQdDLwERzElYXRL/BYSm yKDvXbA0KYlAuHHiXdceM+pNCGccnH+i3OVFMqu68iOVEHIkABec5PhAbO2Y4civ8GTC DLYfk5frlRCFVTnAlCygx+jEenNZ9naRT9YksQGY89QRwh5LGhDKl2pX+k/me9tp+ELH AsFQ== X-Gm-Message-State: AAQBX9cNbrJ1NiZYbJVmDTzh5PXFMZT4h90RxVgL1XmAfUZmVarUo1ni elONQRQgwI+WUROU9Xd+fzNrrA== X-Google-Smtp-Source: AKy350aRrsTlLQ/+xjDNzSPDF1r15mld3KMiVTu7MRCR1xGd2bj5VScO1EQi3l3cBPVSBprySoO9pw== X-Received: by 2002:a17:90a:ce:b0:24b:347b:2a0f with SMTP id v14-20020a17090a00ce00b0024b347b2a0fmr1047604pjd.40.1681936279443; Wed, 19 Apr 2023 13:31:19 -0700 (PDT) Received: from jeff-laptop.lan (c-73-170-46-202.hsd1.ca.comcast.net. [73.170.46.202]) by smtp.gmail.com with ESMTPSA id k2-20020a17090a658200b0022be36be19asm1761379pjj.53.2023.04.19.13.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 13:31:18 -0700 (PDT) Message-ID: Subject: Re: Assert failure with ICU support From: Jeff Davis To: Richard Guo , PostgreSQL mailing lists Date: Wed, 19 Apr 2023 13:31:17 -0700 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2023-04-19 at 18:30 +0800, Richard Guo wrote: > I happened to run into an assert failure by chance with ICU support. > Here is the query: >=20 > =C2=A0 =C2=A0 SELECT '1' SIMILAR TO '\=E0=B5=A7'; >=20 > The failure happens in lexescape(), >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 default: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 assert(iscalpha(c)); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 FAILW(REG_EESCAPE); /* unknown = alphabetic escape */ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; >=20 > Without ICU support, the same query just gives an error. >=20 > # SELECT '1' SIMILAR TO '\=E0=B5=A7'; > ERROR: =C2=A0invalid regular expression: invalid escape \ sequence >=20 > FWIW, I googled a bit and '=E0=B5=A7' seems to be number 1 in Malayalam. Thank you for the report and analysis! The problem exists all the way back if you do: SELECT '1' COLLATE "en-US-x-icu" SIMILAR TO '\=E0=B5=A7'; The root cause (which you allude to) is that the code makes the assumption that digits only include 0-9, but u_isdigit('=E0=B5=A7') =3D=3D = true, which violates that assumption. For Linux[1] specifically, it seems that the assumption should hold for iswdigit(). But looking here[2], it seems that the behavior of iswdigit() depends on the locale and I don't think it's correct to make that assumption. I did some experimentation on ICU and I found (pseudocode -- the real code needs to create a UChar32 from an encoded string first): char name: MALAYALAM DIGIT ONE u_isalnum('=E0=B5=A7'): true u_isalpha('=E0=B5=A7'): false u_isdigit('=E0=B5=A7'): true u_charType('=E0=B5=A7') =3D=3D U_DECIMAL_DIGIT_NUMBER: true u_hasBinaryProperty('=E0=B5=A7', UCHAR_POSIX_XDIGIT): true u_hasBinaryProperty('=E0=B5=A7', UCHAR_POSIX_ALNUM): true The docs[3] for ICU say: "There are also functions that provide easy migration from C/POSIX functions like isblank(). Their use is generally discouraged because the C/POSIX standards do not define their semantics beyond the ASCII range, which means that different implementations exhibit very different behavior. Instead, Unicode properties should be used directly." We should probably just check that it's plain ASCII. Unfortunately I would not be surprised if there are more bugs similar to this one. Regards, Jeff Davis [1] https://man7.org/linux/man-pages/man3/iswdigit.3.html [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/iswdigit.html [3]=20 https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/uchar_8h.html#detai= ls