pgsql: Add checks for cross-rowtype deforming and conversions

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add checks for cross-rowtype deforming and conversions
Date: 2026-11-09 14:22:05
Message-ID: E1xQQG5-000000003r3-1CDh@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add checks for cross-rowtype deforming and conversions

The previously added attribute versioning checks prevent cases of
deforming a datum tuple with an incompatible tuple descriptor for the
same type. However, we have a number of cases where we deform a datum
tuple with a descriptor for a different relation. The additional checks
introduces here add verification for such cases, by checking that the
tuple descriptors are compatible.

The following cases are now checked during deforming:

- Deforming a versioned tuple with a RECORDOID tupledesc

This can happen with triggers and EvalPlanQual rechecks of function
scans.

- Deforming a versioned tuple with a tupledesc for another relation

This happens a bunch for partitioned tables.

Additionally, when changing the type of a tuple, the old and new types
are compared for compatibility. This currently happens in:

- heap_copy_tuple_as_datum() and via that in places like
ExecEvalConvertRowtype(), ExecFetchSlotHeapTupleDatum(), ...

- plpgsql's coerce_function_result_tuple()

In a perfect world these extra checks would not be needed. But...

It is perhaps worth noting that this knowingly emits error messages in
an untranslatable way. That was considered acceptable for now, these
error checks should not normally be hit.

Note that these checks do add nontrivial overhead. This is ameliorated
by the fact that the common ways to reach the checks are part of already
expensive operations (like trigger invocations during DML into a
partitioned table), which are expensive enough to make the added
overhead comparatively small.

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

Branch
------
REL_17_STABLE

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

Modified Files
--------------
src/backend/access/common/heaptuple.c | 296 ++++++++++++++++++++-
.../expected/eval-plan-qual-rowtype-alter.out | 14 +-
src/test/regress/expected/rowtypes_alter.out | 17 +-
3 files changed, 294 insertions(+), 33 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:22:06 pgsql: Allow SET LOGGED/UNLOGGED and changing AM when the rowtype is in
Previous Message Noah Misch 2026-11-09 14:22:04 pgsql: Lock affected rowtype and dependent types on ALTER ATTRIBUTE