pgsql: Fix type confusion with materialized set-returning functions

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix type confusion with materialized set-returning functions
Date: 2026-11-09 14:21:51
Message-ID: E1xQQFr-000000003NF-1XRR@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix type confusion with materialized set-returning functions

Set-returning functions in the target list with indeterminate RECORD
return types incorrectly used the same tuple descriptor to read and
return tuples from the tuplestore across invocations.

These types of SRFs resolve their rowtype from the passed in record
argument and it can differ from invocation to invocation. Reading tuples
with the wrong shape of tuple descriptor can lead to incorrect results,
crashes, and security issues. It was reported as a way to read arbitrary
out-of-line values via json_populate_recordset().

To fix this, drop and recreate the slot and its tuple descriptor per SRF
invocation for materialized SRFs in the target list with dynamic RECORD
return types.

Only the target-list path is affected: table functions in FROM validate
every result against the query-supplied descriptor, and value-per-call
SRFs never retain a slot.

Co-authored-by: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Co-authored-by: Robert Haas <rhaas(at)postgresql(dot)org>
Security: CVE-2026-120141
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6f6e4a955cdbef6b08e99dac1cb11d2405709c17
Author: Robert Haas <rhaas(at)postgresql(dot)org>

Modified Files
--------------
src/backend/executor/execSRF.c | 59 ++++++++++++++++++++++++++++++++------
src/test/regress/expected/json.out | 11 +++++++
src/test/regress/sql/json.sql | 5 ++++
3 files changed, 67 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:21:52 pgsql: Avoid use-after-free hazards in re-entrant use of pltcl.
Previous Message Noah Misch 2026-11-09 14:21:50 pgsql: Teach equalRowTypes() to safely handle dropped columns.