pgsql: Avoid overflow computing visibility map length

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid overflow computing visibility map length
Date: 2026-11-19 22:18:34
Message-ID: E1xUASf-00000000RFR-3I79@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid overflow computing visibility map length

Computing the number of visibility map blocks used addition-based
ceiling division on a BlockNumber. For heap lengths near MaxBlockNumber
on 32-bit builds, the addition could overflow and produce a much smaller
visibility map length, potentially zero.

Use quotient and remainder instead so the calculation cannot overflow.

Reported-by: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Author: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Reviewed-by: shihao zhong <zhong950419(at)gmail(dot)com>
Backpatch-through: 17

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a20d58b47f18f2085f5fadb553e56a8e9fa3160b

Modified Files
--------------
src/backend/access/heap/visibilitymap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Melanie Plageman 2026-11-19 22:22:18 pgsql: Avoid overflow computing visibility map length
Previous Message Melanie Plageman 2026-11-19 22:17:09 pgsql: Forget invalid VM pages during truncation replay