Reject pseudo-types in extended statistics expressions.

Previously, CREATE STATISTICS accepted an expression of a pseudo-type.
So the statistics were built on a value whose row type is identified
only by a typmod assigned locally in the backend that ran ANALYZE.
Therefore, other sessions could read the statistics as the wrong data
type, which can crash the server or return wrong results.

Reject such expressions at CREATE STATISTICS time, including a type
that contains a pseudo-type, such as a composite type with an anyarray
column. An expression whose collation can't be determined is now
rejected too, but ANALYZE fails on such statistics anyway.

Since a statistics expression has no column name, teach the column type
check to report an error without one.

A statistics object built this way on an older minor release can still
exist on v18 and older, so in those branches also error out when such
statistics are used by the planner, their contents are read, or ANALYZE
builds them. Those objects should be dropped.

Backpatch to 14, where statistics on expressions were introduced.

Reported-by: Mehmet D. INCE <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Backpatch-through: 14
Security: CVE-2026-120148

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/033886653976a2f5055b5441ef8b7a933f7803d2
Author: Masahiko Sawada <[email protected]>

Modified Files
--------------
src/backend/catalog/heap.c              | 21 +++++++++++++++++++--
src/backend/commands/statscmds.c        | 11 ++++++++++-
src/backend/statistics/extended_stats.c | 19 +++++++++++++++++++
src/backend/statistics/mcv.c            | 17 +++++++++++++++++
src/backend/utils/adt/ruleutils.c       | 14 ++++++++++++++
src/backend/utils/adt/selfuncs.c        | 17 +++++++++++++++++
src/test/regress/expected/stats_ext.out | 22 ++++++++++++++++++++++
src/test/regress/sql/stats_ext.sql      | 16 ++++++++++++++++
8 files changed, 134 insertions(+), 3 deletions(-)

Reply via email to