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_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/395700f48f25c00e1bbce01d3a67be2a28fe7c44

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