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
Reviewed-by: Andrey Borodin
Reported-by: Yuelin Wang <1217816127@qq.com>
Backpatch-through: 14
Bug: #19607
Discussion: https://postgr.es/m/19607-2f256a66481c514b@postgresql.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/346fbdcc2a92e86c7e964d637f8333c7b8197143
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(-)