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 1lF6A6-0003sk-Jx for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Feb 2021 02:13:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lF6A4-000788-A2 for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Feb 2021 02:13:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lF6A4-000781-3p for pgsql-bugs@lists.postgresql.org; Thu, 25 Feb 2021 02:13:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lF6A0-0004YF-Oh for pgsql-bugs@lists.postgresql.org; Thu, 25 Feb 2021 02:13:50 +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 11P2DkKG051878; Wed, 24 Feb 2021 21:13:46 -0500 From: Tom Lane To: Michael Paquier cc: Alexander Lakhin , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs In-reply-to: References: <16801-393c7922143eaa4d@postgresql.org> <4057243.1614179963@sss.pgh.pa.us> <31724.1614213386@sss.pgh.pa.us> Comments: In-reply-to Michael Paquier message dated "Thu, 25 Feb 2021 10:30:41 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <51876.1614219226.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 24 Feb 2021 21:13:46 -0500 Message-ID: <51877.1614219226@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > Yes, thanks. While looking at that this morning, I have been able to > get a crash with my previous patch once I used more nesting in those > CTEs and your test is much simpler. I also got a test case able to > break things the same way in checkWellFormedRecursionWalker(): > WITH RECURSIVE outermost(x) AS ( > SELECT 1 > UNION (WITH innermost as (WITH innermost2 AS (SELECT 2) SELECT * FROM = innermost2) > SELECT * FROM outermost > UNION SELECT * FROM innermost) > ) > SELECT * FROM outermost ORDER BY 1; Hmm, I don't see any failure from that... In my understanding of the bug, you need at least half a dozen levels of WITH nesting to provoke a problem, because nothing will go wrong until the innerwiths list gets to be six entries long, causing list.c to move its elements array to somewhere else. If it is possible to fail without that then there's still something here that I don't get. regards, tom lane