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 1wfIYc-005Ngo-2b for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Jul 2026 14:38:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfIYb-0020JD-1e for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Jul 2026 14:38:25 +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.96) (envelope-from ) id 1wfIYb-0020J5-0t for pgsql-bugs@lists.postgresql.org; Thu, 02 Jul 2026 14:38:25 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wfIYY-00000001NVl-3cbC for pgsql-bugs@postgresql.org; Thu, 02 Jul 2026 14:38:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 662EcGFf3748109; Thu, 2 Jul 2026 10:38:18 -0400 From: Tom Lane To: =?UTF-8?B?546L6LeD5p6X?= cc: Ayush Tiwari , pgsql-bugs , 3764353996 <3764353996@qq.com> Subject: Re: Fw:Re: Fw: gbt_var_consistent in contrib/btree_gist/btree_utils_var.c has internal-node type confusion on the <> strategy, bypassing exclusion constraints In-reply-to: References: Comments: In-reply-to =?UTF-8?B?546L6LeD5p6X?= message dated "Thu, 18 Jun 2026 13:24:05 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3748107.1783003096.1@sss.pgh.pa.us> Date: Thu, 02 Jul 2026 10:38:16 -0400 Message-ID: <3748108.1783003096@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =?UTF-8?B?546L6LeD5p6X?= writes: > The analysis and fix look correct. The BtreeGistNotEqual branch is > the only strategy that bypasses the is_leaf check and passes > potentially truncated internal-node keys directly to f_eq, which is > unsafe for types like bit and varbit that require a minimum valid > header size. Returning true for internal nodes is the right > conservative choice and is consistent with how the other strategies > handle the internal-node case. None of this passes the smell test for me. If it's unsafe to call the type's f_eq function on a truncated key, how is it any safer to call the f_cmp function? IOW, why aren't *all* the cases in gbt_var_consistent() broken? It looks to me like gbt_var_node_truncate adjusts the length words of the truncated keys so that they are still valid, just shorter. Or at least it's trying to. That works fine for text and bytea, but it's not fine for bit/varbit because (a) it fails to update the "bit_len" field that follows the length word, and (b) the common prefix length selection logic doesn't know that it mustn't truncate away any part of the bit_len field. So my own thought about fixing this is that type bit needs a custom truncation method. It might well be that gbt_var_consistent's not-equal case is broken too, but this discussion hasn't established that IMO. (I continue to regret that we ever accepted such underdocumented code. I think we ought to reverse-engineer a comment explaining what gbt_var_consistent is doing, eg, why are all of the tests seemingly reversed?) regards, tom lane