Skip to content

Commit 3c5232a

Browse files
committed
Check block number against the correct fork in get_raw_page().
get_raw_page tried to validate the supplied block number against RelationGetNumberOfBlocks(), which of course is only right when accessing the main fork. In most cases, the main fork is longer than the others, so that the check was too weak (allowing a lower-level error to be reported, but no real harm to be done). However, very small tables could have an FSM larger than their heap, in which case the mistake prevented access to some FSM pages. Per report from Torsten Foertsch. In passing, make the bad-block-number error into an ereport not elog (since it's certainly not an internal error); and fix sloppily maintained comment for RelationGetNumberOfBlocksInFork. This has been wrong since we invented relation forks, so back-patch to all supported branches.
1 parent 81af418 commit 3c5232a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

contrib/pageinspect/rawpage.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
135135
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
136136
errmsg("cannot access temporary tables of other sessions")));
137137

138-
if (blkno >= RelationGetNumberOfBlocks(rel))
139-
elog(ERROR, "block number %u is out of range for relation \"%s\"",
140-
blkno, RelationGetRelationName(rel));
138+
if (blkno >= RelationGetNumberOfBlocksInFork(rel, forknum))
139+
ereport(ERROR,
140+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
141+
errmsg("block number %u is out of range for relation \"%s\"",
142+
blkno, RelationGetRelationName(rel))));
141143

142144
/* Initialize buffer to copy to */
143145
raw_page = (bytea *) palloc(BLCKSZ + VARHDRSZ);

src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,8 +1926,8 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
19261926
}
19271927

19281928
/*
1929-
* RelationGetNumberOfBlocks
1930-
* Determines the current number of pages in the relation.
1929+
* RelationGetNumberOfBlocksInFork
1930+
* Determines the current number of pages in the specified relation fork.
19311931
*/
19321932
BlockNumber
19331933
RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy