Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8481f99

Browse files
committed
Check for relation length overrun soon enough.
We don't allow relations to exceed 2^32-1 blocks, because blocknumbers are 32 bits and the last possible block number is reservedto mean InvalidBlockNumber. There is a check for this in mdextend,but that's really way too late, because the smgr API requires us tocreate a buffer for the block-to-be-added, and we do not want tohave any buffer with blocknum InvalidBlockNumber. (Such a casecan trigger assertions in bufmgr.c, plus I think it might confuseReadBuffer's logic for data-past-EOF later on.) So put the checkinto 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
1 parent596ba75 commit8481f99

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,16 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
824824

825825
/* Substitute proper block number if caller asked for P_NEW */
826826
if (isExtend)
827+
{
827828
blockNum=smgrnblocks(smgr,forkNum);
829+
/* Fail if relation is already at maximum possible length */
830+
if (blockNum==P_NEW)
831+
ereport(ERROR,
832+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
833+
errmsg("cannot extend relation %s beyond %u blocks",
834+
relpath(smgr->smgr_rnode,forkNum),
835+
P_NEW)));
836+
}
828837

829838
if (isLocalBuf)
830839
{

‎src/backend/storage/smgr/md.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
426426
/*
427427
* If a relation manages to grow to 2^32-1 blocks, refuse to extend it any
428428
* more --- we mustn't create a block whose number actually is
429-
* InvalidBlockNumber.
429+
* InvalidBlockNumber. (Note that this failure should be unreachable
430+
* because of upstream checks in bufmgr.c.)
430431
*/
431432
if (blocknum==InvalidBlockNumber)
432433
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp