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 <[email protected]> Reviewed-by: Melanie Plageman <[email protected]> Security: CVE-2026-6460 Backpatch-through: 14 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/86e2e8fbad41226363ef4900c770bb1b4d1eb677 Author: Andres Freund <[email protected]> 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(-)
