8000 Check maximum number of columns in function RTEs, too. · postgres/postgres@51d8b52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51d8b52

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/17561-80350151b9ad2ad4@postgresql.org
1 parent 3f9c205 commit 51d8b52

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

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

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

16691686
Assert(pstate != NULL);
16701687

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

0 commit comments

Comments
 (0)
0