Forbid ALTERing column type by default when other objects depend on it

Previously, we'd allow changing the column type of a table or
composite type (ALTER COLUMN / ATTRIBUTE ... TYPE ...) even if there
are objects depending on the row type.  We only made some checks on
dependencies from relation objects, and assumed that dependencies from
other kinds of object were OK.  This commit flips the logic around to
forbid if there are any dependencies, except for relations and a few
other cases that are known to be OK.

This commit is mostly refactoring, but some cases that were previously
broken, like expressions in views, are now forbidden.  Some of the
dependencies that we continue to allow are known to be broken too --
subsequent commits will tighten them up.

The attributions and discussion links are for the whole wider issue
covered by all the related commits, not just the variants fixed by
this one commit.

Reported-by: Andrew Gierth <[email protected]>
Reported-by: Alexander Lakhin <[email protected]>
Reported-by: Francesco Verardi <[email protected]>
Reported-by: Hcamael <[email protected]>
Reported-by: Tomer Fichman <[email protected]>
Reported-by: OpenAI Security Research Team
Reported-by: Peter Geoghegan <[email protected]>
Reported-by: Mehmet Ince @mdisec <[email protected]>
Reported-by: Bryan Green <[email protected]>
Reported-by: Sumedh Pathak <[email protected]>
Reported-by: Nicholas Carlini <[email protected]>
Reported-by: Sergey Shinderuk <[email protected]>
Reported-by: Yuxiao Guo <[email protected]>
Reported-by: Nikhil Sontakke <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Reviewed-by: Amit Langote <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Reviewed-by: Peter Geoghegan <[email protected]>
Discussion: 
https://www.postgresql.org/message-id/CA%2BUBoq0F2ua2fQEAU3-6w0oxOgFc9BgEN4gRcchiUUZ%2BWouVrQ%40mail.gmail.com
Discussion: 
https://www.postgresql.org/message-id/CA%2BbCEdDvsVApd%2BAADX%3D5uyj6Q5C3r5aruWNzOFaYqaFqLwE_5g%40mail.gmail.com
Security: CVE-2026-6460
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/15cf82750d19fe6798278d6e85843d3addeded0d
Author: Heikki Linnakangas <[email protected]>

Modified Files
--------------
src/backend/commands/tablecmds.c                | 100 ++++++++++++++++++++++--
src/test/regress/expected/alter_column_type.out |  48 ++++--------
src/test/regress/expected/alter_table.out       |  18 +++++
src/test/regress/sql/alter_column_type.sql      |  28 ++-----
src/test/regress/sql/alter_table.sql            |  18 +++++
5 files changed, 153 insertions(+), 59 deletions(-)

Reply via email to