Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vUYxE-00GOSF-0I for pgsql-hackers@arkaria.postgresql.org; Sat, 13 Dec 2025 23:23:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vUYxC-00Bu1L-07 for pgsql-hackers@arkaria.postgresql.org; Sat, 13 Dec 2025 23:23:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vUYxB-00Bu1D-2O for pgsql-hackers@lists.postgresql.org; Sat, 13 Dec 2025 23:23:10 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vUYxA-000XPi-2A for pgsql-hackers@postgresql.org; Sat, 13 Dec 2025 23:23:09 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7b7828bf7bcso2502467b3a.2 for ; Sat, 13 Dec 2025 15:23:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765668187; x=1766272987; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CSjdkriB+bt4t57iI862Dg5FchXvF1Lb88/c3d04j1Y=; b=E//cSyN0/X2bSKcJ0CIfERMHxIl+L4u8RKCzWK8f0BO/IDn6yIXZeZC2Hk38oj1J0H RAfcHB4N9nQcI/QNDM+D0xxtXc8UFmtSdtxLICnUhlK3FjTSkr12eLhD3DlbpATpUjJ3 3qW+8GQeGv8xGDftYXElv1rh6L1oL5WV1+f0MI/3T+bTvrGsakymVOPhzrMHPS1+bNvC bq2kox2NgNVBwtBomtkJgH6EkIADlR0ExK6qsuFpBuYgikF2d+gt8PeytDreMBvx+MZM qZ/Z5yQTDm8AEYZ6f5w8xMdwWIBr5TgoLstMXBycRoSgoLzXotgCBlIfJWncFxucm53A eBbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765668187; x=1766272987; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CSjdkriB+bt4t57iI862Dg5FchXvF1Lb88/c3d04j1Y=; b=cJZGFOzg7EgasN42TVU1YC68/epPsia/fwwDYq4e9juhoR90gPymWBHHuyysflDCag 8iHzNSbFu/sGDGnl/Xw47+dSSRHPicIOISRsOC/Hynx2LkpOH3zjutmZxpsrBcb3s2sc rLXY96OgK2aqGJponyYcPl7lLYAqBRBaNhVUXRhFNbs01bWDfXTH5BgA+S86EeCqiJox oEdvEn3Icv92cZzc9xAI/R2zSM2+H1KR+oE156s+3oVVGYrcb6vmldRuEzAYlgAITqOB 3s8w4GGQYH5fFUZR3HQCUEyZcN28MUIYVYVMVVAUYY5Q0uP2ehAsY2QI5iH8MQ+mMRah TuWA== X-Gm-Message-State: AOJu0YyZRhknpBhvl/nSHC72zn4bQy3F/asL5KNKgbCz4X0XeYYLbcna SUfvMrMtH/m8yUrqnzoPqywhRfJzsSkmQr9NpHdRFxOTIYeY+jtsu6ch X-Gm-Gg: AY/fxX4ZrrGcbUw3PiLoethClmUulGCxis8i/ze6+V1rboIx/1qGSwRYORaGhz2XDvE W3uMVjpQanXQj5/K8KUR+BbnWBZ2DgSq/nEiq0JbOlxvKZuyfwlwDA9jOc/s9uSQKo4w77ScNLl vrmlPDYsVIjRZ2IDe2juQLeBYaW6Sn+vav/AFo+O5T877kVlJhpVIBC5i8h6vTdC6XUJ3EDjtoS QNVE2JguKQmVx36sh2d3jgRGw+YZwmne0x4srh3rOuIW/slBBquOMdAQVgjwVpyseonovRYNYSO mcpuDplPZkpLS5AXIUkPKl/AhyYKy9adcUNs3fMav5wpdWNWmd9mxc+7xKcClx53D/oAlLrLNzn XmaSbO9MQ4WEQf/TOnFtdF4RupDdRMPcSjlgCwrenXfBhzJ1XgiJSmsnHz7Q8qIzeyMSP0KcsA0 ouOeQyNrKiVUiPTA3wrho= X-Google-Smtp-Source: AGHT+IHM9xLHrhro5SBZXNaZcTi3gKAgj74cb8nETDly9lOFTnU92ZeEJE9RuwK1mdmj/mjt310qwg== X-Received: by 2002:a05:6a00:1ca3:b0:7e8:4398:b35b with SMTP id d2e1a72fcca58-7f66969e4edmr5263490b3a.46.1765668187147; Sat, 13 Dec 2025 15:23:07 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7f4c5093a4bsm8718543b3a.50.2025.12.13.15.23.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2025 15:23:06 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Small patch to improve safety of utf8_to_unicode(). From: Chao Li In-Reply-To: Date: Sun, 14 Dec 2025 07:22:28 +0800 Cc: pgsql-hackers@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <541F240E-94AD-4D65-9794-7D6C316BC3FF@gmail.com> References: To: Jeff Davis X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 13, 2025, at 07:24, Jeff Davis wrote: >=20 > Attached. >=20 >=20 > This patch adds a length check to utf8_to_unicode(), I think which is = where =E2=80=9Csafety=E2=80=9D comes from. Can you please add an a = little bit more to the commit message instead of only saying =E2=80=9Cimpr= ove safety=E2=80=9D. It also deleted two redundant function declarations = from pg_wchar.h, which may also worth a quick note in the commit = message. The code changes all look good to me. Only nitpicks are: 1 ``` diff --git a/contrib/fuzzystrmatch/daitch_mokotoff.c = b/contrib/fuzzystrmatch/daitch_mokotoff.c index 07f895ae2bf..47bd2814460 100644 --- a/contrib/fuzzystrmatch/daitch_mokotoff.c +++ b/contrib/fuzzystrmatch/daitch_mokotoff.c @@ -401,7 +401,8 @@ read_char(const unsigned char *str, int *ix) =20 /* Decode UTF-8 character to ISO 10646 code point. */ str +=3D *ix; - c =3D utf8_to_unicode(str); + /* Assume byte sequence has not been broken. */ + c =3D utf8_to_unicode(str, MAX_MULTIBYTE_CHAR_LEN); ``` Here we need an empty line above the new comment. 2 ``` diff --git a/src/common/wchar.c b/src/common/wchar.c index a4bc29921de..c113cadf815 100644 --- a/src/common/wchar.c +++ b/src/common/wchar.c @@ -661,7 +661,8 @@ ucs_wcwidth(pg_wchar ucs) static int pg_utf_dsplen(const unsigned char *s) { - return ucs_wcwidth(utf8_to_unicode(s)); + /* trust that input is not a truncated byte sequence */ + return ucs_wcwidth(utf8_to_unicode(s, MAX_MULTIBYTE_CHAR_LEN)); } ``` For the new comment, as a code reader, I wonder why we =E2=80=9Ctrust=E2=80= =9D that? To me, it more feels like because of lacking length = information, we have to trust. I would like this comment to be enhanced = a little bit with more information. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/