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

Commitd947a8b

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 parent523926d commitd947a8b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

‎src/backend/parser/parse_relation.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,8 +1819,16 @@ addRangeTableEntryForFunction(ParseState *pstate,
18191819

18201820
/*
18211821
* Use the column definition list to construct a tupdesc and fill
1822-
* in the RangeTblFunction's lists.
1822+
* in the RangeTblFunction's lists. Limit number of columns to
1823+
* MaxHeapAttributeNumber, because CheckAttributeNamesTypes will.
18231824
*/
1825+
if (list_length(coldeflist)>MaxHeapAttributeNumber)
1826+
ereport(ERROR,
1827+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1828+
errmsg("column definition lists can have at most %d entries",
1829+
MaxHeapAttributeNumber),
1830+
parser_errposition(pstate,
1831+
exprLocation((Node*)coldeflist))));
18241832
tupdesc=CreateTemplateTupleDesc(list_length(coldeflist));
18251833
i=1;
18261834
foreach(col,coldeflist)
@@ -1900,6 +1908,15 @@ addRangeTableEntryForFunction(ParseState *pstate,
19001908
if (rangefunc->ordinality)
19011909
totalatts++;
19021910

1911+
/* Disallow more columns than will fit in a tuple */
1912+
if (totalatts>MaxTupleAttributeNumber)
1913+
ereport(ERROR,
1914+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1915+
errmsg("functions in FROM can return at most %d columns",
1916+
MaxTupleAttributeNumber),
1917+
parser_errposition(pstate,
1918+
exprLocation((Node*)funcexprs))));
1919+
19031920
/* Merge the tuple descs of each function into a composite one */
19041921
tupdesc=CreateTemplateTupleDesc(totalatts);
19051922
natts=0;
@@ -1984,6 +2001,18 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
19842001

19852002
Assert(pstate!=NULL);
19862003

2004+
/* Disallow more columns than will fit in a tuple */
2005+
if (list_length(tf->colnames)>MaxTupleAttributeNumber)
2006+
ereport(ERROR,
2007+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
2008+
errmsg("functions in FROM can return at most %d columns",
2009+
MaxTupleAttributeNumber),
2010+
parser_errposition(pstate,
2011+
exprLocation((Node*)tf))));
2012+
Assert(list_length(tf->coltypes)==list_length(tf->colnames));
2013+
Assert(list_length(tf->coltypmods)==list_length(tf->colnames));
2014+
Assert(list_length(tf->colcollations)==list_length(tf->colnames));
2015+
19872016
rte->rtekind=RTE_TABLEFUNC;
19882017
rte->relid=InvalidOid;
19892018
rte->subquery=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp