pg_surgery: Fix infinite loop on large TID arrays

heap_force_common() tracked the current position in the caller-supplied
tid[] using OffsetNumber, which is only 16 bits wide, so when the array
held more than 65535 entries, the updated index wrapped around and the
outer loop never reached the exit condition.  A SQL call with a
sufficiently large TID array would then run until interrupted.

Fix by tracking the tid[] position using int instead of OffsetNumber.
A regress case based on the report is included.

Author: Andrey Rachitskiy <[email protected]>
Reviewed-by: Andrey Borodin <[email protected]>
Reported-by: Yuelin Wang <[email protected]>
Backpatch-through: 14
Bug: #19607
Discussion: https://postgr.es/m/[email protected]

Branch
------
REL_16_STABLE

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

Modified Files
--------------
contrib/pg_surgery/expected/heap_surgery.out | 17 +++++++++++++++++
contrib/pg_surgery/heap_surgery.c            |  6 +++---
contrib/pg_surgery/sql/heap_surgery.sql      |  8 ++++++++
3 files changed, 28 insertions(+), 3 deletions(-)

Reply via email to