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.94.2) (envelope-from ) id 1tE83g-005L9y-AY for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2024 14:21:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tE83e-00GHyC-Gh for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2024 14:21:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tE83e-00GHxz-6w for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2024 14:21:22 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tE83b-0037Ht-ME for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2024 14:21:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=YOgYluXKAiWhm/R9PBwMRT3ABsxVw32wpMnB9p6EBhw=; b=aiduz cF83kGjb2sDgtHJbixPZWNoJ19mMQQcjiJ9X9uwTpNxtAjHXAlMMZouipsYObUt0r496ZW2AzjADw 91eF7BqtjBVK2781w4mG4Myh1heyDn01GL2NwHi8ZthkrJ4NNfuZ0TvXEm0aQE2o19IqNKbwAiCLp gR/vtTpIx68sbDCyqQ2holVNUeiDip/VTJbNDdghncwQweX3QRrcyHZAs5x4paZKcTYE8kqlFs17n gTMADFnG2Om/UJhnBnX6Vllm4SKMIENejbCgnFIkm7Ov9igdSnC9L3f9r4rjCkfiAkkvFb6w8GPpe X70DyPblOsQ0SI4u0m+wumDUpsDdQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1tE83Y-0002et-2t; Thu, 21 Nov 2024 09:21:16 -0500 Date: Thu, 21 Nov 2024 09:21:16 -0500 From: Bruce Momjian To: Bertrand Drouvot Cc: Nathan Bossart , Tom Lane , adam@labkey.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails Message-ID: References: <3976665.1732057784@sss.pgh.pa.us> <75265.1732076593@sss.pgh.pa.us> <154104.1732118090@sss.pgh.pa.us> <158506.1732120196@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Nov 21, 2024 at 07:27:22AM +0000, Bertrand Drouvot wrote: > + /* > + * If the original name is too long and we see two consecutive bytes > + * with their high bits set at the truncation point, we might have > + * truncated in the middle of a multibyte character. In multibyte > + * encodings, every byte of a multibyte character has its high bit > + * set. So if IS_HIGHBIT_SET is true for both NAMEDATALEN-1 and > + * NAMEDATALEN-2, we know we're in the middle of a multibyte > + * character. We need to try truncating one more byte back to find the > + * start of the next character. > + */ ... > + /* > + * If we've hit a byte with high bit clear (an ASCII byte), we > + * know we can't be in the middle of a multibyte character, > + * because all bytes of a multibyte character must have their > + * high bits set. Any following byte must therefore be the > + * start of a new character, so we can stop looking for > + * earlier truncation points. > + */ I don't understand this logic. Why are two bytes important? If we knew it was UTF8 we could check for non-first bytes always starting with bits 10, but we can't know that. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com When a patient asks the doctor, "Am I going to die?", he means "Am I going to die soon?"