> On Jul 14, 2021, at 3:33 AM, Heikki Linnakangas <hlinn...@iki.fi> wrote:
>
>> +/* The largest valid toast va_rawsize */
>> +#define VARLENA_SIZE_LIMIT 0x3FFFFFFF
>> +
>
> Hmm, a toasted datum cannot be larger than MaxAllocSize, because it's
> reconstituted in a palloc'd datum, right?
No datum size exceeds MaxAllocSize, and no datum expands when compressed
(because for those that do expand under any particular compression algorithm,
we opt to instead store the datum uncompressed), so no valid toast pointer
should contain a va_rawsize field greater than MaxAllocSize. Any toast
pointers that have larger va_rawsize fields are therefore corrupt.
VARLENA_SIZE_LIMIT is defined here equal to MaxAllocSize:
src/include/utils/memutils.h:#define MaxAllocSize ((Size) 0x3fffffff)
/* 1 gigabyte - 1 */
Earlier versions of the patch used MaxAllocSize rather than defining
VARLENA_SIZE_LIMIT, but review comments suggested that was less clear.
—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company