From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: krking@zju.edu.cn
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17480: Assertion failure in parse_relation.c
Date: Tue, 10 May 2022 12:50:57 +0200
Message-ID: <202205101050.sepjyffoevsy@alvherre.pgsql> (raw)
In-Reply-To: <17480-1c9d73565bb28e90@postgresql.org>
On 2022-May-10, PG Bug reporting form wrote:
> Testcase:
> ```
> CREATE TABLE v0 ( v3 INT , v2 VARCHAR , v1 INT , UNIQUE ( v1 , v3 ) ) ;
> VALUES ( - - -128 , - - - - 127 , NULL ) ;
> SELECT FROM LATERAL XMLTABLE ( ROW ( ) PASSING NULL BY VALUE COLUMNS v1
> TIMESTAMP WITHOUT TIME ZONE ARRAY ) AS DELETE ( v3 , v3 , v2 , v3 , v1 ,
> FIRST , v1 , FLOAT , INT , v2 , v3 , VERSION , v2 , FLOAT , INT , v1 , NO ,
> ROW , v3 , v2 ) ORDER BY v2 , v2 ;
> ```
Hmm, were you using a fuzzer to generate this query? It would sure be
useful to have it process some more and see what other crashes it
discovers.
Your example can be reduced to this, which already crashes the server:
SELECT * FROM XMLTABLE (ROW () passing null COLUMNS v1 TIMESTAMP, v2 int) AS f (v1, v2, v3);
and with this it is clear that the problem is that the alias list is too
long for the COLUMNS specification of the XMLTABLE function. This can
be avoided by throwing an error:
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.cindex 7465919044..6c817a9c55 100644--- a/src/backend/parser/parse_relation.c+++ b/src/backend/parser/parse_relation.c@@ -2001,6 +2001,12 @@ addRangeTableEntryForTableFunc(ParseState *pstate,
eref->colnames = list_concat(eref->colnames,
list_copy_tail(tf->colnames, numaliases));
+ if (numaliases > list_length(tf->colnames))+ ereport(ERROR,+ (errcode(ERRCODE_SYNTAX_ERROR),+ errmsg("%s function has %d columns available but %d columns specified",+ "XMLTABLE", list_length(tf->colnames), numaliases)));+
rte->eref = eref;
/*
(Obviously, no regression test changes output after this patch.)
This mirrors what happens when you give too many aliases to tables or
other things. (In pg15 and up, it needs to be aware of JSON_TABLE too.
I made this on pg14.)
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Uno puede defenderse de los ataques; contra los elogios se esta indefenso"
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: alvherre@alvh.no-ip.org, krking@zju.edu.cn, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17480: Assertion failure in parse_relation.c
In-Reply-To: <202205101050.sepjyffoevsy@alvherre.pgsql>
* 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