aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-07-29 13:30:50 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-07-29 13:31:10 -0400
commitfd96d14d950f2b1d19b5cb3b8e5a7d4d2b3fa161 (patch)
tree61fdc5802e2c510ec570dde172b6d86f85ae5321 /src/backend/parser/parse_expr.c
parent80d690721973f6a031143a24a34b78a0225101a2 (diff)
downloadpostgresql-fd96d14d950f2b1d19b5cb3b8e5a7d4d2b3fa161.tar.gz
postgresql-fd96d14d950f2b1d19b5cb3b8e5a7d4d2b3fa161.zip
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
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9f567f4bf41..059cb7097c7 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -2140,6 +2140,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;