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:23 UTC
(cloudberry) 26/38: In transformRowExpr(), check for too many columns in the row.
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 e382864083e3590b4f0a70bded9d14e333af846e
Author: Tom Lane <tg...@sss.pgh.pa.us>
AuthorDate: Fri Jul 29 13:30:50 2022 -0400
In transformRowExpr(), check for too many columns in the row.
A RowExpr with more than MaxTupleAttributeNumber columns would fail at
execution anyway, since we cannot form a tuple datum with more than that
many columns. While heap_form_tuple() has a check for too many columns,
it emerges that there are some intermediate bits of code that don't
check and can be driven to failure with sufficiently many columns.
Checking this at parse time seems like the most appropriate place to
install a defense, since we already check SELECT list length there.
While at it, make the SELECT-list-length error use the same errcode
(TOO_MANY_COLUMNS) as heap_form_tuple does, rather than the generic
PROGRAM_LIMIT_EXCEEDED.
Per bug #17561 from Egor Chindyaskin. The given test case crashes
in all supported branches (and probably a lot further back),
so patch all.
Discussion: https://postgr.es/m/17561-80350151b9ad2ad4@postgresql.org
---
src/backend/parser/parse_expr.c | 8 ++++++++
src/backend/parser/parse_node.c | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index befe81e8ee..fcbbf8a850 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -2166,6 +2166,14 @@ transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
newr->args = transformExpressionList(pstate, r->args,
pstate->p_expr_kind, allowDefault);
+ /* Disallow more columns than will fit in a tuple */
+ if (list_length(newr->args) > MaxTupleAttributeNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_TOO_MANY_COLUMNS),
+ errmsg("ROW expressions can have at most %d entries",
+ MaxTupleAttributeNumber),
+ parser_errposition(pstate, r->location)));
+
/* Barring later casting, we consider the type RECORD */
newr->row_typeid = RECORDOID;
newr->row_format = COERCE_IMPLICIT_CAST;
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index 013267c8ba..6a7d31a18d 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -83,7 +83,7 @@ free_parsestate(ParseState *pstate)
*/
if (pstate->p_next_resno - 1 > MaxTupleAttributeNumber)
ereport(ERROR,
- (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ (errcode(ERRCODE_TOO_MANY_COLUMNS),
errmsg("target lists can have at most %d entries",
MaxTupleAttributeNumber)));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org