pgsql: plpgsql: Check compatibility of source/target ERHs

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: plpgsql: Check compatibility of source/target ERHs
Date: 2026-11-09 14:21:56
Message-ID: E1xQQFw-000000003YK-1YU8@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

plpgsql: Check compatibility of source/target ERHs

Otherwise we can assign tuples not matching the target tupledescriptor,
e.g. because one of the tuple descriptors has been acquired before/after
some DDL.

It may seem tempting to just not enter the surrounding "if" if the
er_tupdesc_id doesn't match (in fact both Heikki and I (Andres) were
previously tempted), but the fieldwise-assignment path differs
behaviorally, due to not copying the ctid along. As the tupdesc_id can
increment due to invalidation processing, that would lead to
unpredictable behavior. Tests were added in previous commits that would
show that behavior.

Note that there are some cases where this will cause failures that are
not required for correctness, when assigning a variable of a changed
type to a previously used variable. It'd add more complexity to make
that work; for a bugfix this seems good enough.

As also noted in a comment, this perhaps should be done in the expanded
record layer. But that'd require a few more changes and would make it
harder to emit a somewhat understandable error message.

Reviewed-by: Tomas Vondra <tomas(at)vondra(dot)me>
Reviewed-by: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Security: CVE-2026-6460
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/86e2e8fbad41226363ef4900c770bb1b4d1eb677
Author: Andres Freund <andres(at)anarazel(dot)de>

Modified Files
--------------
src/pl/plpgsql/src/expected/plpgsql_record.out | 8 +++--
src/pl/plpgsql/src/pl_exec.c | 46 ++++++++++++++++++++++++++
src/test/regress/expected/rowtypes_alter.out | 25 +++++++++-----
3 files changed, 68 insertions(+), 11 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:21:57 pgsql: Fix reusing large allocations in generation memory contexts
Previous Message Noah Misch 2026-11-09 14:21:55 pgsql: Fix type confusion with materialized set-returning functions