Commit 27cef0a5 authored by Tom Lane's avatar Tom Lane

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.
parent 4ebe3519
...@@ -131,9 +131,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno) ...@@ -131,9 +131,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot access temporary tables of other sessions"))); errmsg("cannot access temporary tables of other sessions")));
if (blkno >= RelationGetNumberOfBlocks(rel)) if (blkno >= RelationGetNumberOfBlocksInFork(rel, forknum))
elog(ERROR, "block number %u is out of range for relation \"%s\"", ereport(ERROR,
blkno, RelationGetRelationName(rel)); (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("block number %u is out of range for relation \"%s\"",
blkno, RelationGetRelationName(rel))));
/* Initialize buffer to copy to */ /* Initialize buffer to copy to */
raw_page = (bytea *) palloc(BLCKSZ + VARHDRSZ); raw_page = (bytea *) palloc(BLCKSZ + VARHDRSZ);
......
...@@ -2022,8 +2022,8 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln) ...@@ -2022,8 +2022,8 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
} }
/* /*
* RelationGetNumberOfBlocks * RelationGetNumberOfBlocksInFork
* Determines the current number of pages in the relation. * Determines the current number of pages in the specified relation fork.
*/ */
BlockNumber BlockNumber
RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum) RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment