Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadc3ae6

Browse files
committed
Check maximum number of columns in function RTEs, too.
I thought commitfd96d14 had plugged all the holes of this sort,but no, function RTEs could produce oversize tuples too, eithervia long coldeflists or just from multiple functions in one RTE.(I'm pretty sure the other variants of base RTEs aren't a problem,because they ultimately refer to either a table or a sub-SELECT,whose widths are enforced elsewhere. But we explicitly allow joinRTEs to be overwidth, as long as you don't try to form theirtuple result.)Per further discussion of bug #17561. As before, patch all branches.Discussion:https://postgr.es/m/17561-80350151b9ad2ad4@postgresql.org
1 parent07abcd9 commitadc3ae6

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

‎src/backend/parser/parse_relation.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,8 +1830,16 @@ addRangeTableEntryForFunction(ParseState *pstate,
18301830

18311831
/*
18321832
* Use the column definition list to construct a tupdesc and fill
1833-
* in the RangeTblFunction's lists.
1833+
* in the RangeTblFunction's lists. Limit number of columns to
1834+
* MaxHeapAttributeNumber, because CheckAttributeNamesTypes will.
18341835
*/
1836+
if (list_length(coldeflist)>MaxHeapAttributeNumber)
1837+
ereport(ERROR,
1838+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1839+
errmsg("column definition lists can have at most %d entries",
1840+
MaxHeapAttributeNumber),
1841+
parser_errposition(pstate,
1842+
exprLocation((Node*)coldeflist))));
18351843
tupdesc=CreateTemplateTupleDesc(list_length(coldeflist));
18361844
i=1;
18371845
foreach(col,coldeflist)
@@ -1911,6 +1919,15 @@ addRangeTableEntryForFunction(ParseState *pstate,
19111919
if (rangefunc->ordinality)
19121920
totalatts++;
19131921

1922+
/* Disallow more columns than will fit in a tuple */
1923+
if (totalatts>MaxTupleAttributeNumber)
1924+
ereport(ERROR,
1925+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1926+
errmsg("functions in FROM can return at most %d columns",
1927+
MaxTupleAttributeNumber),
1928+
parser_errposition(pstate,
1929+
exprLocation((Node*)funcexprs))));
1930+
19141931
/* Merge the tuple descs of each function into a composite one */
19151932
tupdesc=CreateTemplateTupleDesc(totalatts);
19161933
natts=0;
@@ -1993,11 +2010,23 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
19932010
Alias*eref;
19942011
intnumaliases;
19952012

2013+
Assert(pstate!=NULL);
2014+
2015+
/* Disallow more columns than will fit in a tuple */
2016+
if (list_length(tf->colnames)>MaxTupleAttributeNumber)
2017+
ereport(ERROR,
2018+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
2019+
errmsg("functions in FROM can return at most %d columns",
2020+
MaxTupleAttributeNumber),
2021+
parser_errposition(pstate,
2022+
exprLocation((Node*)tf))));
2023+
Assert(list_length(tf->coltypes)==list_length(tf->colnames));
2024+
Assert(list_length(tf->coltypmods)==list_length(tf->colnames));
2025+
Assert(list_length(tf->colcollations)==list_length(tf->colnames));
2026+
19962027
refname=alias ?alias->aliasname :
19972028
pstrdup(tf->functype==TFT_XMLTABLE ?"xmltable" :"json_table");
19982029

1999-
Assert(pstate!=NULL);
2000-
20012030
rte->rtekind=RTE_TABLEFUNC;
20022031
rte->relid=InvalidOid;
20032032
rte->subquery=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp