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

Commit5d280bc

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 parent24872bb commit5d280bc

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
@@ -1559,8 +1559,16 @@ addRangeTableEntryForFunction(ParseState *pstate,
15591559

15601560
/*
15611561
* Use the column definition list to construct a tupdesc and fill
1562-
* in the RangeTblFunction's lists.
1562+
* in the RangeTblFunction's lists. Limit number of columns to
1563+
* MaxHeapAttributeNumber, because CheckAttributeNamesTypes will.
15631564
*/
1565+
if (list_length(coldeflist)>MaxHeapAttributeNumber)
1566+
ereport(ERROR,
1567+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1568+
errmsg("column definition lists can have at most %d entries",
1569+
MaxHeapAttributeNumber),
1570+
parser_errposition(pstate,
1571+
exprLocation((Node*)coldeflist))));
15641572
tupdesc=CreateTemplateTupleDesc(list_length(coldeflist));
15651573
i=1;
15661574
foreach(col,coldeflist)
@@ -1640,6 +1648,15 @@ addRangeTableEntryForFunction(ParseState *pstate,
16401648
if (rangefunc->ordinality)
16411649
totalatts++;
16421650

1651+
/* Disallow more columns than will fit in a tuple */
1652+
if (totalatts>MaxTupleAttributeNumber)
1653+
ereport(ERROR,
1654+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1655+
errmsg("functions in FROM can return at most %d columns",
1656+
MaxTupleAttributeNumber),
1657+
parser_errposition(pstate,
1658+
exprLocation((Node*)funcexprs))));
1659+
16431660
/* Merge the tuple descs of each function into a composite one */
16441661
tupdesc=CreateTemplateTupleDesc(totalatts);
16451662
natts=0;
@@ -1714,6 +1731,18 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
17141731

17151732
Assert(pstate!=NULL);
17161733

1734+
/* Disallow more columns than will fit in a tuple */
1735+
if (list_length(tf->colnames)>MaxTupleAttributeNumber)
1736+
ereport(ERROR,
1737+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1738+
errmsg("functions in FROM can return at most %d columns",
1739+
MaxTupleAttributeNumber),
1740+
parser_errposition(pstate,
1741+
exprLocation((Node*)tf))));
1742+
Assert(list_length(tf->coltypes)==list_length(tf->colnames));
1743+
Assert(list_length(tf->coltypmods)==list_length(tf->colnames));
1744+
Assert(list_length(tf->colcollations)==list_length(tf->colnames));
1745+
17171746
rte->rtekind=RTE_TABLEFUNC;
17181747
rte->relid=InvalidOid;
17191748
rte->subquery=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp