Re: BUG #18135: Incorrect memory access occurs when attaching a partition with an index

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2023-09-28T17:31:39Z
Lists: pgsql-bugs

Attachments

PG Bug reporting form <noreply@postgresql.org> writes:
> The function CompareIndexInfo() contains the code:
> 		/* ignore expressions at this stage */
> 		if ((info1->ii_IndexAttrNumbers[i] != InvalidAttrNumber) &&
> 			(attmap->attnums[info2->ii_IndexAttrNumbers[i] - 1] !=
> 			 info1->ii_IndexAttrNumbers[i]))
> 			return false;

> where info1->ii_IndexAttrNumbers[i] is checked for InvalidAttrNumber
> (i. e. it's not an expression), but info2->ii_IndexAttrNumbers[i] is not.

Agreed, that's pretty broken, and it's not just that it risks an
invalid access.  I don't think this reliably rejects cases where
one index has an expression and the other doesn't.  Even if it does
work, it's way too complicated to convince oneself that that's
rejected.  I think for clarity we should code it as attached.

			regards, tom lane

Commits

  1. Fix checking of index expressions in CompareIndexInfo().