Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 331f8b8

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 aadaaef commit 331f8b8

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

17821782
/*
17831783
* Use the column definition list to construct a tupdesc and fill
1784-
* in the RangeTblFunction's lists.
1784+
* in the RangeTblFunction's lists. Limit number of columns to
1785+
* MaxHeapAttributeNumber, because CheckAttributeNamesTypes will.
17851786
*/
1787+
if (list_length(coldeflist) > MaxHeapAttributeNumber)
1788+
ereport(ERROR,
1789+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1790+
errmsg("column definition lists can have at most %d entries",
1791+
MaxHeapAttributeNumber),
1792+
parser_errposition(pstate,
1793+
exprLocation((Node *) coldeflist))));
17861794
tupdesc = CreateTemplateTupleDesc(list_length(coldeflist));
17871795
i = 1;
17881796
foreach(col, coldeflist)
@@ -1862,6 +1870,15 @@ addRangeTableEntryForFunction(ParseState *pstate,
18621870
if (rangefunc->ordinality)
18631871
totalatts++;
18641872

1873+
/* Disallow more columns than will fit in a tuple */
1874+
if (totalatts > MaxTupleAttributeNumber)
1875+
ereport(ERROR,
1876+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1877+
errmsg("functions in FROM can return at most %d columns",
1878+
MaxTupleAttributeNumber),
1879+
parser_errposition(pstate,
1880+
exprLocation((Node *) funcexprs))));
1881+
18651882
/* Merge the tuple descs of each function into a composite one */
18661883
tupdesc = CreateTemplateTupleDesc(totalatts);
18671884
natts = 0;
@@ -1946,6 +1963,18 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
19461963

19471964
Assert(pstate != NULL);
19481965

1966+
/* Disallow more columns than will fit in a tuple */
1967+
if (list_length(tf->colnames) > MaxTupleAttributeNumber)
1968+
ereport(ERROR,
1969+
(errcode(ERRCODE_TOO_MANY_COLUMNS),
1970+
errmsg("functions in FROM can return at most %d columns",
1971+
MaxTupleAttributeNumber),
1972+
parser_errposition(pstate,
1973+
exprLocation((Node *) tf))));
1974+
Assert(list_length(tf->coltypes) == list_length(tf->colnames));
1975+
Assert(list_length(tf->coltypmods) == list_length(tf->colnames));
1976+
Assert(list_length(tf->colcollations) == list_length(tf->colnames));
1977+
19491978
rte->rtekind = RTE_TABLEFUNC;
19501979
rte->relid = InvalidOid;
19511980
rte->subquery = NULL;

0 commit comments

Comments
 (0)