Registry Mirror
Skip to content

Conversation

@reshke

@reshke reshke commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

FigureColnameInternal recursively walks a raw expression while CREATE INDEX derives the preliminary index column name. This happens before transformExpr() applies its stack-depth protection, so a deep cast chain can exhaust the backend stack. Check stack depth on every recursive visit and reject the expression with stack_depth_limit_exceeded.

Add a create_index regression that dynamically builds the deep expression, so the source tree does not contain a megabyte-scale SQL statement.

SQL-reachable SIGSEGV: CREATE INDEX expression cast chain

The query is executable by the ordinary table owner. The test role sqlsmith_probe has rolsuper=false and owns schema index_hunt and table index_hunt.idx_t. It created a short index successfully with the same role.

Setup SQL:
CREATE SCHEMA index_hunt AUTHORIZATION sqlsmith_probe; CREATE TABLE index_hunt.idx_t(a integer) DISTRIBUTED RANDOMLY;

Reproducer SQL: execute as sqlsmith_probe; N=270000: CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::...::int));

Generate the exact SQL with:
python3 - <<'PY'
n = 270000
expr = 'a' + '::int' * n
print('CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((' + expr + '));') PY

The grammar builds a left-deep TypeCast tree. CREATE INDEX reaches FigureIndexColname()/FigureColnameInternal before transformExpr(). The backend SIGSEGVs in FigureColnameInternal.constprop.0. GDB reports roughly 261k recursive frames at the 500k repro; 270k also crashes.

GDB bt (top frames):
#0 0x000055bcff76594f in FigureColnameInternal.constprop.0 () #1 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #2 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #3 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #4 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #5 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #6 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #7 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #8 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #9 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #10 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #11 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #12 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #13 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #14 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #15 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #16 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #17 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #18 0x000055bcff765959 in FigureColnameInternal.constprop.0 () #19 0x000055bcff765959 in FigureColnameInternal.constprop.0 () (More stack frames follow...)
Warning: 'set logging off', an alias for the command 'set logging enabled', is deprecated. Use 'set logging enabled off'.

Verbatim coordinator postmaster log:
2026-12-03 16:06:52.845238 MSK,,,p1484041,th1997600576,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 2111634) was terminated by signal 11: Segmentation fault","Failed process was running: CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int:",,,,,,0,,"postmaster.c",4278,

upstream fix for issue is postgres/postgres@181b618

FigureColnameInternal recursively walks a raw expression while
CREATE INDEX derives the preliminary index column name. This happens
before transformExpr() applies its stack-depth protection, so a deep cast
chain can exhaust the backend stack. Check stack depth on every recursive
visit and reject the expression with stack_depth_limit_exceeded.

Add a create_index regression that dynamically builds the deep expression,
so the source tree does not contain a megabyte-scale SQL statement.

SQL-reachable SIGSEGV: CREATE INDEX expression cast chain

The query is executable by the ordinary table owner. The test role sqlsmith_probe has rolsuper=false and owns schema index_hunt and table index_hunt.idx_t. It created a short index successfully with the same role.

Setup SQL:
CREATE SCHEMA index_hunt AUTHORIZATION sqlsmith_probe;
CREATE TABLE index_hunt.idx_t(a integer) DISTRIBUTED RANDOMLY;

Reproducer SQL: execute as sqlsmith_probe; N=270000:
CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::...::int));

Generate the exact SQL with:
python3 - <<'PY'
n = 270000
expr = 'a' + '::int' * n
print('CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((' + expr + '));')
PY

The grammar builds a left-deep TypeCast tree. CREATE INDEX reaches FigureIndexColname()/FigureColnameInternal before transformExpr(). The backend SIGSEGVs in FigureColnameInternal.constprop.0. GDB reports roughly 261k recursive frames at the 500k repro; 270k also crashes.

GDB bt (top frames):
#0  0x000055bcff76594f in FigureColnameInternal.constprop.0 ()
#1  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#2  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#3  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#4  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#5  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#6  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#7  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#8  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#9  0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
#10 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#11 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#12 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#13 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#14 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#15 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#16 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#17 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#18 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
apache#19 0x000055bcff765959 in FigureColnameInternal.constprop.0 ()
(More stack frames follow...)
Warning: 'set logging off', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled off'.

Verbatim coordinator postmaster log:
2026-12-03 16:06:52.845238 MSK,,,p1484041,th1997600576,,,,0,,,seg-1,,,,,"LOG","00000","server process (PID 2111634) was terminated by signal 11: Segmentation fault","Failed process was running: CREATE INDEX idx_t_cast_270k ON index_hunt.idx_t ((a::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int::int:",,,,,,0,,"postmaster.c",4278,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant