From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: kyzevan23@mail.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17561: Server crashes on executing row() with very long argument list
Date: Fri, 29 Jul 2022 10:40:55 -0400
Message-ID: <3768321.1659105655@sss.pgh.pa.us> (raw)
In-Reply-To: <3753050.1659102953@sss.pgh.pa.us>
References: <20220729101411.7b45rvhlrsgcajjo@alvherre.pgsql>
<3753050.1659102953@sss.pgh.pa.us>
I wrote:
> I think the parser should've prevented this. It's in charge of
> rejecting overlength SELECT lists, for example. Also, the limit
> probably needs to be just MaxTupleAttributeNumber.
Concretely, about as attached.
In the existing code, if you just supply 10000 or so columns you
reach this error in heaptuple.c:
if (numberOfAttributes > MaxTupleAttributeNumber)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_COLUMNS),
errmsg("number of columns (%d) exceeds limit (%d)",
numberOfAttributes, MaxTupleAttributeNumber)));
I borrowed the errcode from that, but the wording from parse_node.c:
if (pstate->p_next_resno - 1 > MaxTupleAttributeNumber)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("target lists can have at most %d entries",
MaxTupleAttributeNumber)));
I'm a bit inclined to adjust parse_node.c to also use TOO_MANY_COLUMNS
(54011) instead of the generic PROGRAM_LIMIT_EXCEEDED (54000).
regards, tom lane
Attachments:prevent-too-many-cols-in-ROW-expr.patch (text/x-diff, 836B) downloaddiff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.cindex 9f567f4bf4..059cb7097c 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;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, alvherre@alvh.no-ip.org, kyzevan23@mail.ru, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17561: Server crashes on executing row() with very long argument list
In-Reply-To: <3768321.1659105655@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox