Conversation
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,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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