]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Check block number against the correct fork in get_raw_page().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Jul 2014 15:45:57 +0000 (11:45 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Jul 2014 15:45:57 +0000 (11:45 -0400)
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.

contrib/pageinspect/rawpage.c
src/backend/storage/buffer/bufmgr.c

index f51a4e31f51ae5bd00f31dc4bd3daa5015d5917c..8b1a29f6adcfeaa315c10165d65aca86c820530c 100644 (file)
@@ -132,9 +132,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);
index 46373b6012609ee56066d5a691cf1b3c3985c268..101f1a3ef47856e5d4683c5d2e4d755f0c20f262 100644 (file)
@@ -1974,8 +1974,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)