Skip to content

Commit f59c8ef

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 0711524 commit f59c8ef

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
@@ -133,9 +133,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
133133
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
134134
errmsg("cannot access temporary tables of other sessions")));
135135

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

140142
/* Initialize buffer to copy to */
141143
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
@@ -2033,8 +2033,8 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
20332033
}
20342034

20352035
/*
2036-
* RelationGetNumberOfBlocks
2037-
* Determines the current number of pages in the relation.
2036+
* RelationGetNumberOfBlocksInFork
2037+
* Determines the current number of pages in the specified relation fork.
20382038
*/
20392039
BlockNumber
20402040
RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)

0 commit comments

Comments
 (0)