Re: off-by-one in pg_repack index loop

From: Xiaopeng Wang <wxp_728(at)163(dot)com>
To: Lakshmi N <lakshmin(dot)jhs(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: off-by-one in pg_repack index loop
Date: 2026-04-15 02:07:51
Message-ID: 51485ded-7191-4b20-b1eb-1aa230174288@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2026-04-15 02:14:45 Re: GetCachedPlan() refactor: move execution lock acquisition out
Previous Message Peter Smith 2026-04-15 02:05:31 Re: Support EXCEPT for TABLES IN SCHEMA publications