pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: wf13934952799@gmail.com
Subject: BUG #19829: BTREE pivot tuple length overflows t_info when BLCKSZ=32768
Date: Tue, 03 Nov 2026 07:46:52 +0000
Message-ID: <19829-5d18cdf4d4dd6844@postgresql.org> (raw)

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:        

PostgreSQL version: 19devel (also reproducible on 18.x)
Operating system:   Linux x86_64
Configure options:  --with-blocksize=32

With BLCKSZ=32768, 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 = MAXALIGN(IndexTupleSize(pivot)) +
MAXALIGN(sizeof(ItemPointerData));
    ...
    tidpivot->t_info &= ~INDEX_SIZE_MASK;
    tidpivot->t_info |= newsize;

For a maximally sized leaf tuple this is 8184 + 8 = 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=32768 the one-third rule is no longer
the binding constraint.  Block sizes of 16384 and below are unaffected.

Steps to reproduce:
< SQL 脚本>

Expected: either the insert is rejected, or the pivot tuple is stored
correctly.
Actual:   high key with length 0 (amcheck reports: <具体报错>).

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=32768 limit cannot invalidate any index that could
actually exist on disk, so there is no on-disk compatibility concern.







view thread (3+ messages)  latest in thread

Message-ID: <19829-5d18cdf4d4dd6844@postgresql.org>
Permalink:  ../19829-5d18cdf4d4dd6844@postgresql.org/
Also on:    postgresql.org/message-id/19829-5d18cdf4d4dd6844@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, wf13934952799@gmail.com
  Subject: Re: BUG #19829: BTREE pivot tuple length overflows t_info when BLCKSZ=32768
  In-Reply-To: <19829-5d18cdf4d4dd6844@postgresql.org>
  References: <19829-5d18cdf4d4dd6844@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox