Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 27cef0a

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 4ebe351 commit 27cef0a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

contrib/pageinspect/rawpage.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
131131
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
132132
errmsg("cannot access temporary tables of other sessions")));
133133

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

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

src/backend/storage/buffer/bufmgr.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,8 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
20222022
}
20232023

20242024
/*
2025-
* RelationGetNumberOfBlocks
2026-
* Determines the current number of pages in the relation.
2025+
* RelationGetNumberOfBlocksInFork
2026+
* Determines the current number of pages in the specified relation fork.
20272027
*/
20282028
BlockNumber
20292029
RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)

0 commit comments

Comments
 (0)