aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/smgr/md.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
commit04118de78fe9a8a7160775b47e89bf21a5efb620 (patch)
tree6c1687d517a23199e13563635cb66cf32b817dd3 /src/backend/storage/smgr/md.c
parentdd9b3fced83edb51a3e2f44d3d4476a45d0f5a24 (diff)
downloadpostgresql-04118de78fe9a8a7160775b47e89bf21a5efb620.tar.gz
postgresql-04118de78fe9a8a7160775b47e89bf21a5efb620.zip
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/smgr/md.c')
-rw-r--r--src/backend/storage/smgr/md.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 7f1af3ffa0c..51617e17c18 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -437,7 +437,8 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
/*
* If a relation manages to grow to 2^32-1 blocks, refuse to extend it any
* more --- we mustn't create a block whose number actually is
- * InvalidBlockNumber.
+ * InvalidBlockNumber. (Note that this failure should be unreachable
+ * because of upstream checks in bufmgr.c.)
*/
if (blocknum == InvalidBlockNumber)
ereport(ERROR,