pgsql: Fix potential integer overflow in bringetbitmap()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix potential integer overflow in bringetbitmap()
Date: 2025-01-14 06:13:57
Message-ID: E1tXaBZ-001R8R-HP@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix potential integer overflow in bringetbitmap()

This function expects an "int64" as result and stores the number of
pages to add to the index scan bitmap as an "int", multiplying its final
result by 10. For a relation large enough, this can theoretically
overflow if counting more than (INT32_MAX / 10) pages, knowing that the
number of pages is upper-bounded by MaxBlockNumber.

To avoid the overflow, this commit redefines "totalpages", used to
calculate the result, to be an "int64" rather than an "int".

Reported-by: Evgeniy Gorbanyov
Author: James Hunter
Discussion: https://www.postgresql.org/message-id/07704817-6fa0-460c-b1cf-cd18f7647041@basealt.ru
Backpatch-through: 13

Branch
------
REL_16_STABLE

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

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

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-01-14 06:28:33 pgsql: Bump PGSTAT_FILE_FORMAT_ID
Previous Message Michael Paquier 2025-01-14 03:44:30 pgsql: Move information about pgstats kinds into its own header pgstat_