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 1tEAIW-005cBY-0M for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2024 16:44:52 +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 1tEAIU-00HMY1-Hr for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2024 16:44:50 +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 1tEAIU-00HMXt-9F for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2024 16:44:50 +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 1tEAIR-0038PM-Bc for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2024 16:44:49 +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=cISPV/Xok8pZkAsh+tPUAMWceg2JRy/Ljs3muUwrJ2Y=; b=WWs9h CVWrXOr2eiX5C/jiMij+DB4KSBO9xKksUI7hPGAaXJLFA17e6zVaXkJQUQKamzul8nb/dqV2Yjv0p /p/6uG5CxJ0ivOVZjrkiO5MkicD0bgtAYZg7/Ivsu09zh/AT8I8Xrs1fzAmCJYI3jOiMwTJZCXlH/ +q/WHAw+/jS1ivQcONgKEq22gYx6WyaVil6BUftgsBWw2wTc3OoIM+1hVmQUj5JCDmOQlmmr/PB6c 5+JJxdUXW1NW6NMHGp/MQdm2XwkIVSXUXQZYHoDRE4BL6w3FrTs2tUkos/1kE23rPAXZTleeeISWq dZhXbHhKqftNmrk6Jetij9upMNjdQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1tEAIO-000FiY-1L; Thu, 21 Nov 2024 11:44:44 -0500 Date: Thu, 21 Nov 2024 11:44:44 -0500 From: Bruce Momjian To: Nathan Bossart Cc: Bertrand Drouvot , 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: <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 09:14:23AM -0600, Nathan Bossart wrote: > On Thu, Nov 21, 2024 at 09:47:56AM -0500, Bruce Momjian wrote: > > On Thu, Nov 21, 2024 at 02:35:50PM +0000, Bertrand Drouvot wrote: > >> On Thu, Nov 21, 2024 at 09:21:16AM -0500, Bruce Momjian wrote: > >> > 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. > >> > >> I think this is because this is a reliable way to detect if the truncation happened > >> in the middle of a character, without needing to know the specifics of the encoding. > >> > >> My understanding is that the key insight is that in any multibyte encoding, all > >> bytes within a multibyte character will have their high bits set. > >> > >> That's just my understanding from the code and Tom's previous explanations: I > >> might be wrong as not an expert in this area. > > > > But the logic doesn't make sense. Why would two bytes be any different > > than one? > > Tom provided a concise explanation upthread [0]. My understanding is the > same as Bertrand's, i.e., this is an easy way to rule out a bunch of cases > where we know that we couldn't possibly have truncated in the middle of a > multi-byte character. This allows us to avoid doing multiple pg_database > lookups. Where does Tom mention anything about checking two bytes? He is basically saying remove all trailing high-bit characters until you get a match, because once you get a match, you are have found the point of valid truncation for the encoding. In fact, here, he specifically talks about MAX_MULTIBYTE_CHAR_LEN-1: https://www.postgresql.org/message-id/3796535.1732044807%40sss.pgh.pa.us This text: * 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. needs to be fixed, at a minimum, specifically, "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." > > I assumed you would just remove all trailing high-bit bytes > > and stop and the first non-high-bit byte. > > I think this risks truncating more than one multi-byte character, which > would cause the login path to truncate differently than the CREATE/ALTER > DATABASE path (which is encoding-aware). True, we can stop at MAX_MULTIBYTE_CHAR_LEN-1, and know there is no match. > * Try to do multibyte-aware truncation (the patch at hand). Yes, I am fine with that, but we need to do more than the patch does to accomplish this, unless I am totally confused. -- 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?"