Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHRAk-0007v7-PV for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Jul 2022 14:41:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oHRAj-0004EU-NL for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Jul 2022 14:41:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHRAj-0004EL-F6 for pgsql-bugs@lists.postgresql.org; Fri, 29 Jul 2022 14:41:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHRAh-0001e3-E7 for pgsql-bugs@lists.postgresql.org; Fri, 29 Jul 2022 14:41:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 26TEet9Y3768322; Fri, 29 Jul 2022 10:40:55 -0400 From: Tom Lane To: Alvaro Herrera cc: 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: <3753050.1659102953@sss.pgh.pa.us> References: <20220729101411.7b45rvhlrsgcajjo@alvherre.pgsql> <3753050.1659102953@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 29 Jul 2022 09:55:53 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3768133.1659105591.0@sss.pgh.pa.us> Date: Fri, 29 Jul 2022 10:40:55 -0400 Message-ID: <3768321.1659105655@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3768133.1659105591.1@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 ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="prevent-too-many-cols-in-ROW-expr.patch"; charset="us-ascii" Content-ID: <3768133.1659105591.2@sss.pgh.pa.us> Content-Description: prevent-too-many-cols-in-ROW-expr.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_ex= pr.c index 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, bo= ol allowDefault) newr->args =3D 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 =3D RECORDOID; newr->row_format =3D COERCE_IMPLICIT_CAST; ------- =_aaaaaaaaaa0--