You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ma...@apache.org on 2024/12/24 02:38:26 UTC
(cloudberry) 29/38: Check maximum number of columns in function RTEs, too.
This is an automated email from the ASF dual-hosted git repository.
maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit db8a250295fd226ab30bea58d87c859bd3f3384d
Author: Tom Lane <tg...@sss.pgh.pa.us>
AuthorDate: Mon Aug 1 12:22:35 2022 -0400
Check maximum number of columns in function RTEs, too.
I thought commit fd96d14d9 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
---
src/backend/parser/parse_relation.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 87126e7851..2c274eefe9 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -2017,8 +2017,16 @@ addRangeTableEntryForFunction(ParseState *pstate,
/*
* Use the column definition list to construct a tupdesc and fill
- * in the RangeTblFunction's lists.
+ * in the RangeTblFunction's lists. Limit number of columns to
+ * MaxHeapAttributeNumber, because CheckAttributeNamesTypes will.
*/
+ if (list_length(coldeflist) > MaxHeapAttributeNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_COLUMNS),
+ errmsg("column definition lists can have at most %d entries",
+ MaxHeapAttributeNumber),
+ parser_errposition(pstate,
+ exprLocation((Node *) coldeflist))));
tupdesc = CreateTemplateTupleDesc(list_length(coldeflist));
i = 1;
foreach(col, coldeflist)
@@ -2098,6 +2106,15 @@ addRangeTableEntryForFunction(ParseState *pstate,
if (rangefunc->ordinality)
totalatts++;
+ /* Disallow more columns than will fit in a tuple */
+ if (totalatts > MaxTupleAttributeNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_COLUMNS),
+ errmsg("functions in FROM can return at most %d columns",
+ MaxTupleAttributeNumber),
+ parser_errposition(pstate,
+ exprLocation((Node *) funcexprs))));
+
/* Merge the tuple descs of each function into a composite one */
tupdesc = CreateTemplateTupleDesc(totalatts);
natts = 0;
@@ -2182,6 +2199,18 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
Assert(pstate != NULL);
+ /* Disallow more columns than will fit in a tuple */
+ if (list_length(tf->colnames) > MaxTupleAttributeNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_COLUMNS),
+ errmsg("functions in FROM can return at most %d columns",
+ MaxTupleAttributeNumber),
+ parser_errposition(pstate,
+ exprLocation((Node *) tf))));
+ Assert(list_length(tf->coltypes) == list_length(tf->colnames));
+ Assert(list_length(tf->coltypmods) == list_length(tf->colnames));
+ Assert(list_length(tf->colcollations) == list_length(tf->colnames));
+
rte->rtekind = RTE_TABLEFUNC;
rte->relid = InvalidOid;
rte->subquery = NULL;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org