aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-07-22 11:45:53 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-07-22 11:45:53 -0400
commitf59c8eff7dd3dea4116a34e1890ee219f6d7f8d5 (patch)
tree1157c5e32d17b8a8bc5a8aab10ea6b05005fff3e
parent07115248fdaf06ba9b4f1a5f557cbf0282d835dd (diff)
downloadpostgresql-f59c8eff7dd3dea4116a34e1890ee219f6d7f8d5.tar.gz
postgresql-f59c8eff7dd3dea4116a34e1890ee219f6d7f8d5.zip
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.
-rw-r--r--contrib/pageinspect/rawpage.c8
-rw-r--r--src/backend/storage/buffer/bufmgr.c4
2 files changed, 7 insertions, 5 deletions
diff --git a/contrib/pageinspect/rawpage.c b/contrib/pageinspect/rawpage.c
index e3ffaf4e4f2..154d68969ee 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -133,9 +133,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot access temporary tables of other sessions")));
- if (blkno >= RelationGetNumberOfBlocks(rel))
- elog(ERROR, "block number %u is out of range for relation \"%s\"",
- blkno, RelationGetRelationName(rel));
+ if (blkno >= RelationGetNumberOfBlocksInFork(rel, forknum))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("block number %u is out of range for relation \"%s\"",
+ blkno, RelationGetRelationName(rel))));
/* Initialize buffer to copy to */
raw_page = (bytea *) palloc(BLCKSZ + VARHDRSZ);
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 0f593b20940..945e9f367c4 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -2033,8 +2033,8 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
}
/*
- * RelationGetNumberOfBlocks
- * Determines the current number of pages in the relation.
+ * RelationGetNumberOfBlocksInFork
+ * Determines the current number of pages in the specified relation fork.
*/
BlockNumber
RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)