summaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer/bufmgr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-09-09 11:45:48 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-09-09 11:45:48 -0400
commit7430c774209cd98bbc33076cc3c07497c1086d9a (patch)
treea428d21f93020d1332a61ad9e2a819f692d9dc6c /src/backend/storage/buffer/bufmgr.c
parentb5ec22bf5e8f19964f7c7d7ef357ff947a38c7fc (diff)
Check for relation length overrun soon enough.
We don't allow relations to exceed 2^32-1 blocks, because block numbers are 32 bits and the last possible block number is reserved to mean InvalidBlockNumber. There is a check for this in mdextend, but that's really way too late, because the smgr API requires us to create a buffer for the block-to-be-added, and we do not want to have any buffer with blocknum InvalidBlockNumber. (Such a case can trigger assertions in bufmgr.c, plus I think it might confuse ReadBuffer's logic for data-past-EOF later on.) So put the check into ReadBuffer. Per report from Christoph Berg. It's been like this forever, so back-patch to all supported branches. Discussion: https://postgr.es/m/YTn1iTkUYBZfcODk@msg.credativ.de
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r--src/backend/storage/buffer/bufmgr.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 4b296a22c45..ffc6056c60c 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -830,7 +830,16 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
/* Substitute proper block number if caller asked for P_NEW */
if (isExtend)
+ {
blockNum = smgrnblocks(smgr, forkNum);
+ /* Fail if relation is already at maximum possible length */
+ if (blockNum == P_NEW)
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("cannot extend relation %s beyond %u blocks",
+ relpath(smgr->smgr_rnode, forkNum),
+ P_NEW)));
+ }
if (isLocalBuf)
{