Check for relation length overrun soon enough.
authorTom Lane <[email protected]>
Thu, 9 Sep 2021 15:45:48 +0000 (11:45 -0400)
committerTom Lane <[email protected]>
Thu, 9 Sep 2021 15:45:48 +0000 (11:45 -0400)
commitcc4de2bba02ffcd11caf980fb4c1a500f64bf137
tree08bbe0f2499e44ef5001d1b652bf54f2fe0cad6c
parent61e2aa2dbe55f138b6eea922687747416a4b4f67
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/[email protected]
src/backend/storage/buffer/bufmgr.c
src/backend/storage/smgr/md.c