Fix potential integer overflow in bringetbitmap()
authorMichael Paquier
Tue, 14 Jan 2025 06:12:56 +0000 (15:12 +0900)
committerMichael Paquier
Tue, 14 Jan 2025 06:12:56 +0000 (15:12 +0900)
commit720e529840d5a1087a34db445f624c5ece46eb38
tree29ee9d6f6fb0f49224c294b0a7d0efdccd28a287
parentd35ea27e51c05cbe3575d50a6b99d64f20a3a742
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
src/backend/access/brin/brin.c