Re: off-by-one in pg_repack index loop - Mailing list pgsql-hackers

From Xiaopeng Wang
Subject Re: off-by-one in pg_repack index loop
Date
Msg-id 51485ded-7191-4b20-b1eb-1aa230174288@163.com
Whole thread
In response to off-by-one in pg_repack index loop  (Lakshmi N <lakshmin.jhs@gmail.com>)
List pgsql-hackers
在 2026/4/14 15:34, Lakshmi N 写道:
> Hi hackers,
>
> foreach_current_index returns a 0-based index so
> list_length also takes a 0-based index. Perhaps the
> check should be list_length(ind_oids_new) <= pos?
> Please find the attached patch.
>
> int pos = foreach_current_index(ind_old);
>
> if (unlikely(list_length(ind_oids_new) < pos))
>      elog(ERROR, "list of new indexes too short");
> ident_idx_new = list_nth_oid(ind_oids_new, pos);
> break;
>
> Regards,
> Lakshmi

This fix looks correct to me. Both foreach_current_index(), so 0<=pos<list_length is expected.

Regard,
Xiaopeng Wang







pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: Support EXCEPT for TABLES IN SCHEMA publications
Next
From: Amit Langote
Date:
Subject: Re: GetCachedPlan() refactor: move execution lock acquisition out