From e27b01eacc35fef891593d9e990b3b9c72dfd943 Mon Sep 17 00:00:00 2001 From: Baji Shaik Date: Wed, 25 Nov 2026 22:37:02 -0600 Subject: [PATCH v4] pageinspect: check line pointers in bt_page_stats() and bt_multi_page_stats() GetBTPageStatistics() follows every line pointer on the page to add up IndexTupleSize(), without checking that the line pointer has storage or that the tuple lies within the page. On a page with a damaged line pointer this reads past the page, and on an assert-enabled build it fails Assert(ItemIdHasStorage()) in PageGetItem(). The pages come from shared buffers, so this needs checksums off or ignore_checksum_failure on to be reached. Apply the same line pointer check that bt_page_print_tuples() uses. --- contrib/pageinspect/btreefuncs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c index ee98629602..60d36ff229 100644 --- a/contrib/pageinspect/btreefuncs.c +++ b/contrib/pageinspect/btreefuncs.c @@ -177,6 +177,16 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat) ItemId id = PageGetItemId(page, off); + /* Check that the line pointer and tuple lie within the page. */ + if (!ItemIdHasStorage(id) || + ItemIdGetOffset(id) != MAXALIGN(ItemIdGetOffset(id)) || + ItemIdGetLength(id) < sizeof(IndexTupleData) || + ItemIdGetOffset(id) + ItemIdGetLength(id) > BLCKSZ) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid line pointer at offset %u in btree page", + off))); + itup = (IndexTuple) PageGetItem(page, id); item_size += IndexTupleSize(itup); -- 2.54.0 (Apple Git-157)