From 7bfbfb4a647d5e698b58c15558329b499dc4659e Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Thu, 22 Apr 2021 10:21:04 +0530 Subject: [PATCH v1] MAXALIGN sizeof(BTPageOpaqueData) in PageGetItemIdCareful In the PageGetItemIdCareful() introduced by commit a9ce839a, it seems like btree page pd_special structure BTPageOpaqueData is being used for error case without max aligning it. Looks like this was actually not a problem because the BTPageOpaqueData already has all-aligned members (3 uint32, 2 uint16). But it might be a problem if we add unaligned bytes. PageInit always max aligns this structure, when we initialize the btree page in _bt_pageini and in all other places we max align it before use. Since this is an error throwing path, it should be max aligned here too, just to be on the safer side. While on it, replace BLCKSZ with PageGetPageSize(page) in the same function. --- contrib/amcheck/verify_nbtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c index 3d06be5563..a714f0fdad 100644 --- a/contrib/amcheck/verify_nbtree.c +++ b/contrib/amcheck/verify_nbtree.c @@ -3134,7 +3134,7 @@ PageGetItemIdCareful(BtreeCheckState *state, BlockNumber block, Page page, ItemId itemid = PageGetItemId(page, offset); if (ItemIdGetOffset(itemid) + ItemIdGetLength(itemid) > - BLCKSZ - sizeof(BTPageOpaqueData)) + PageGetPageSize(page) - MAXALIGN(sizeof(BTPageOpaqueData))) ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), errmsg("line pointer points past end of tuple space in index \"%s\"", -- 2.25.1