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.98.2) (envelope-from ) id 1xOHWk-000000003jk-0TGy for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Nov 2026 16:38:27 +0000 Received: from localhost ([127.0.0.1]:50878 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xOHWj-00000002171-3RoO for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Nov 2026 16:38:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:44374) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xO9Ea-00000008Nkg-0O5w for pgsql-bugs@lists.postgresql.org; Tue, 03 Nov 2026 07:47:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xO9EX-00000002NGE-46BK for pgsql-bugs@lists.postgresql.org; Tue, 03 Nov 2026 07:47:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=vVmCvR4adkIAdATp/4XV3KunexweyG9qCNbjJ8Ddylo=; b=Zz1ODAOq8Qx3OoA4Vg8ZTUiUpg PDk49OsmFRlcvHZMchO6it3uHvQNT4gsQwOaNutyP/IpHB3F0mda5Km6X1tqR+M7d4i6dbqExJZQy c62Lx5Ii8H4DzR6KdDwYQA1Vxjo1Key6QNRokGBao9HEsoF6SXkNCGMCod/aPmtxiudymAl9/pMpl n80nwp5/RFCz+qUhEauic9rhZYYxVkdOz3CCnHe1kA8fNoUmFgQk1WTmeMSlee4goFOZasFJ3q4V1 /O75M2pLJW+efRWqoPhXg1UWYk3K04seuF3TNcuuMoJT+TblZU/kVawhHg7gBHlV/oidxxTDdyA53 6IWkkCEQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xO9EW-00000006m3Q-3CTM for pgsql-bugs@lists.postgresql.org; Tue, 03 Nov 2026 07:47:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xO9EU-0000000Cq9u-2EX5 for pgsql-bugs@lists.postgresql.org; Tue, 03 Nov 2026 07:47:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19829: BTREE pivot tuple length overflows t_info when BLCKSZ=32768 To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: wf13934952799@gmail.com Reply-To: wf13934952799@gmail.com, pgsql-bugs@lists.postgresql.org Date: Tue, 03 Nov 2026 07:46:52 +0000 Message-ID: <19829-5d18cdf4d4dd6844@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19829 Logged by: wangfei Email address: wf13934952799@gmail.com PostgreSQL version: 18.6 Operating system: ubuntu-24.04 Description: =20 PostgreSQL version: 19devel (also reproducible on 18.x) Operating system: Linux x86_64 Configure options: --with-blocksize=3D32 With BLCKSZ=3D32768, BTMaxItemSize() evaluates to roughly 10896 bytes, but = the tuple length field reserved by INDEX_SIZE_MASK in IndexTupleData.t_info can only represent 8191 bytes. index_form_tuple() enforces the 8191 limit, so a leaf tuple is at most 8184 bytes after MAXALIGN. _bt_truncate() may then need to append a tiebreaker heap TID: newsize =3D MAXALIGN(IndexTupleSize(pivot)) + MAXALIGN(sizeof(ItemPointerData)); ... tidpivot->t_info &=3D ~INDEX_SIZE_MASK; tidpivot->t_info |=3D newsize; For a maximally sized leaf tuple this is 8184 + 8 =3D 8192, i.e. exactly INDEX_SIZE_MASK + 1, so the length field wraps to zero. The result is a zero-length pivot tuple used as a leaf high key; PageAddItem() and XLogRegisterBufData() both accept it without complaint, so the corruption is written out and WAL-logged silently. BTMaxItemSize() is supposed to keep leaf tuples small enough that this cannot happen, but the one-third-of-a-page rule scales with BLCKSZ while INDEX_SIZE_MASK does not, so at BLCKSZ=3D32768 the one-third rule is no lon= ger the binding constraint. Block sizes of 16384 and below are unaffected. Steps to reproduce: < SQL =E8=84=9A=E6=9C=AC> Expected: either the insert is rejected, or the pivot tuple is stored correctly. Actual: high key with length 0 (amcheck reports: <=E5=85=B7=E4=BD=93=E6= =8A=A5=E9=94=99>). A patch against master is attached. It takes Min() of the one-third rule and what t_info can represent in BTMaxItemSize(), and adds a defensive elog(ERROR) in _bt_truncate() so that a future miscalculation cannot corrupt an index silently. Since index_form_tuple() already caps index tuples at 8184 bytes, lowering the BLCKSZ=3D32768 limit cannot invalidate any index that could actually exist on disk, so there is no on-disk compatibility concern.