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
------
master

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

Modified Files
--------------
src/backend/catalog/heap.c              | 22 ++++++++++++++++++++--
src/backend/commands/statscmds.c        | 11 ++++++++++-
src/test/regress/expected/stats_ext.out | 22 ++++++++++++++++++++++
src/test/regress/sql/stats_ext.sql      | 16 ++++++++++++++++
4 files changed, 68 insertions(+), 3 deletions(-)

Reply via email to