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 1whVRx-000GgG-2j for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jul 2026 16:48:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whVRw-00891A-0U for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jul 2026 16:48:40 +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 1whVRv-00890p-2d for pgsql-hackers@lists.postgresql.org; Wed, 08 Jul 2026 16:48:40 +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.98.2) (envelope-from ) id 1whVRs-00000000BMX-1Q9s for pgsql-hackers@postgresql.org; Wed, 08 Jul 2026 16:48:39 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-381018b9375so1030853a91.0 for ; Wed, 08 Jul 2026 09:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783529316; x=1784134116; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=T+4cFlnvGfgH4jepyjaIDLHAVMQpEnUyn9OuhuMYqLk=; b=UuPw5cdop1KHxx/ZBQwID7z9BRaHbXEPO5nQgfKdExklHjahOVtIgz2kbKpL3W4Ejy TKuIbRma0B6bRrkxI/4ip6fIGKa/pF764U2NiogXtTssz3vpNwEo2LJlRVinucIn8c+5 /n7U8F0q73ORWFOVWMRtV0SdT3ghxnZvv5QH6x85JZnqezzfFgxtAvqt/zEgghq5eKRh D1XYnIQri62Bh3lR0sENQbYJJKi+eDWSIKWPcaTM1BbLzmpMOi1m8RkCh7/CRtv91HyP L8PRTEO0b/RFkJm54psDycP5AfK+jZUNn7GJI/opP5EmvAFNJQf912SKOcUbUCdfP/ce Om5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783529316; x=1784134116; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=T+4cFlnvGfgH4jepyjaIDLHAVMQpEnUyn9OuhuMYqLk=; b=VfQxaoVQzuEUBBpmlE5Y2q4chUYBaLQBp384DJtdG/B7bdtkNxkyv/gMK6ZWmAEqM6 1n3cJ3WLwWtYAmpPBTwOW66Vio28+DfPVxSSuAUswWTIrS6VFT9T7xIozP8MA1Rk8vbR IYoQ0KTsawmZXZgUdrWQoDde7wxM9UznpSYxYNtZ+n857Rea8Uk3B/Ae85g3SBHLq61d SlTUNUkG07cFzNt/CiZ4gYv9vmYXhjVIWbX4hIjCLAJLHO+SHxAsklk+6h1W9OR8kmRJ wVpSDc9YjHPJOgKjqFLShsEuH3yTYnaDh0zNXikpqE9N8ikOVVS9vmtOIbWsLLJMs9fo BRfA== X-Gm-Message-State: AOJu0YwWoWjK5UJxFhmQxwb2jcb72v/iMwtfbcvYs21/Qxqe2vjuIfEf wo2/f+dEEjeJZhB9EMXu12b5RtPCVtxSx3nQ9MRhqxTUeZKmYn6Eth2N X-Gm-Gg: AfdE7cl92YyY55eZ1O5DIJ/SoLQAfmBgraEr8hEhxz7A4nsBqhSoqQpsIKAz0FG9Bay IeInZFfbMvIK9ZgehGXidiC4refFDNx5QsZ5wZ+M3MgSwQ0W9AwvfbbxKpiMI9qMDqqiEP36pjx yOMra8c71pCVCXyV56zZgvbdKNaYweHIypL3NcprVt5zJAJr0S0RJ0xxGzNQL0WjXZO5xRCgjNb d/nrlNxg978YjSNbIOT4q/+8GHZjEE8QPTjPApvQILebRqI9kUbcSduTLZ3tq89DhjMaoTaNHV/ 2c6tNnJOEx6At2cgscP0eQ+wVW8faixM/fPvx3qNE2vp7jJW9MMxJkX1qXOfrVBuEhS/4pEbfWP Ws3VDiqkeskXvtd+pHA/wsJep6QXWFUOYotQZrtdL5tpfe5T15GUVZxAx0e2PsjDsvqUTjU0Hiu x30KoGUIm9pOoi227/U9XP6WRRgE726gN/ndFjcLCSWmSZQMc= X-Received: by 2002:a17:90b:2641:b0:36b:a2cc:485b with SMTP id 98e67ed59e1d1-389421ae149mr3695665a91.21.1783529314330; Wed, 08 Jul 2026 09:48:34 -0700 (PDT) Received: from smtpclient.apple ([2601:642:4c02:4bf2:c4f1:63dd:7f67:4e39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3118ee6091dsm12842071eec.14.2026.07.08.09.48.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jul 2026 09:48:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Small patch to improve safety of utf8_to_unicode(). From: Chao Li In-Reply-To: Date: Wed, 8 Jul 2026 09:48:02 -0700 Cc: pgsql-hackers@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <541F240E-94AD-4D65-9794-7D6C316BC3FF@gmail.com> <313BCA0E-2E74-4EB6-9AA8-10DB7F439151@gmail.com> <592441c1d871a4ed0ac1708e132f447caa35869c.camel@j-davis.com> <3058CAA1-40E0-4098-893B-615F77CD35E1@gmail.com> <0cedb517aee8b79b8e31a4e42885ed88c2a67c5f.camel@j-davis.com> <16CAD4DB-9D4A-481A-BB4E-78775C4F4B2C@gmail.com> To: Jeff Davis X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jul 7, 2026, at 17:56, Jeff Davis wrote: >=20 > On Fri, 2026-06-26 at 12:38 +0800, Chao Li wrote: >> Sounds like 0001 will be back patched. In that case, the commit >> message "defend against invalid UTF8=E2=80=9D seems too broad. Does = it make >> sense to add some brief description about the defend behavior to the >> function header comment and the commit message? >=20 > Committed 0001 and backported to 17. I think adding too much > explanation about behavior we don't expect to actually see would just > add confusion. >=20 >> Then I continue to review 0002-0005: >>=20 >> 0002 - overall looks good. A small comment is: >> ``` >> + for (int i =3D offset; i > 0;) >>=20 >> + for (int i =3D offset + ulen; i < len;) >> ``` >=20 > Committed 0002 and backported to 18. The 'int' is pre-existing, so I > left it as-is. >=20 >> 0003 - looks good. >=20 > Committed to master only. >=20 >> 0004 - looks good. This commit introduces a new helper utf8decode() >> that will resolve my previous concern on 0001. >>=20 >> 0005 - Mostly looks good. This commit applies the new help and my >> previous concern is resolved. But from what you talked, I guess 0004 >> and 0005 will only be pushed to HEAD. >>=20 >> Just one tiny comment on 0005: >> ``` >> + /* invalid UTF8: surrogates */ >> + needed =3D unicode_strfold(NULL, 0, "abc\xED\xA0\x81xyz", 7, >> &consumed, false); >> + Assert(needed =3D=3D 3 && consumed =3D=3D 3); >> ``` >>=20 >> This test passes a 10-char string but uses 7 as srclen. I know that >> doesn=E2=80=99t affect the test result, but it just adds unnecessary >> confusion to readers. So maybe change 7 to 10 to reflect to the real >> string length. >=20 > Thank you, attached with fix. >=20 > I'd like to wait for more comments before I commit these last two > patches, to see if the functions are generally useful for other = callers > as well. >=20 > Regards, > Jeff Davis >=20 > = V6 looks good to me. Best regards, =E2=80=94 Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/