Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d54fc7e

Browse files
committed
Check maximum number of columns in function RTEs, too.
I thought commit fd96d14 had plugged all the holes of this sort, but no, function RTEs could produce oversize tuples too, either via 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 join RTEs to be overwidth, as long as you don't try to form their tuple result.) Per further discussion of bug #17561. As before, patch all branches. Discussion: https://postgr.es/m/[email protected]
1 parent c308003 commit d54fc7e

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

15201520
/*
15211521
* Use the column definition list to construct a tupdesc and fill
1522-
* in the RangeTblFunction's lists.
1522+
* in the RangeTblFunction's lists. Limit number of columns to
1523+
* MaxHeapAttributeNumber, because CheckAttributeNamesTypes will.
15231524
*/
1525+
if (list_length(coldeflist) > MaxHeapAttributeNumber)
1526+
ereport(ERROR,
1527+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1528+
errmsg("column definition lists can have at most %d entries",
1529+
MaxHeapAttributeNumber),
1530+
parser_errposition(pstate,
1531+
exprLocation((Node *) coldeflist))));
15241532
tupdesc = CreateTemplateTupleDesc(list_length(coldeflist), false);
15251533
i = 1;
15261534
foreach(col, coldeflist)
@@ -1594,6 +1602,15 @@ addRangeTableEntryForFunction(ParseState *pstate,
15941602
if (rangefunc->ordinality)
15951603
totalatts++;
15961604

1605+
/* Disallow more columns than will fit in a tuple */
1606+
if (totalatts > MaxTupleAttributeNumber)
1607+
ereport(ERROR,
1608+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1609+
errmsg("functions in FROM can return at most %d columns",
1610+
MaxTupleAttributeNumber),
1611+
parser_errposition(pstate,
1612+
exprLocation((Node *) funcexprs))));
1613+
15971614
/* Merge the tuple descs of each function into a composite one */
15981615
tupdesc = CreateTemplateTupleDesc(totalatts, false);
15991616
natts = 0;
@@ -1667,6 +1684,18 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
16671684

16681685
Assert(pstate != NULL);
16691686

1687+
/* Disallow more columns than will fit in a tuple */
1688+
if (list_length(tf->colnames) > MaxTupleAttributeNumber)
1689+
ereport(ERROR,
1690+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1691+
errmsg("functions in FROM can return at most %d columns",
1692+
MaxTupleAttributeNumber),
1693+
parser_errposition(pstate,
1694+
exprLocation((Node *) tf))));
1695+
Assert(list_length(tf->coltypes) == list_length(tf->colnames));
1696+
Assert(list_length(tf->coltypmods) == list_length(tf->colnames));
1697+
Assert(list_length(tf->colcollations) == list_length(tf->colnames));
1698+
16701699
rte->rtekind = RTE_TABLEFUNC;
16711700
rte->relid = InvalidOid;
16721701
rte->subquery = NULL;

0 commit comments

Comments
 (0)