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 1kvwQw-0007Qg-Vq for pgsql-bugs@arkaria.postgresql.org; Sun, 03 Jan 2021 06:00:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kvwQv-0000ap-RP for pgsql-bugs@arkaria.postgresql.org; Sun, 03 Jan 2021 06:00:05 +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 1kvwQv-0000ai-LZ for pgsql-bugs@lists.postgresql.org; Sun, 03 Jan 2021 06:00:05 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kvwQt-000203-HX for pgsql-bugs@lists.postgresql.org; Sun, 03 Jan 2021 06:00:04 +0000 Received: by mail-lf1-x131.google.com with SMTP id y19so56978768lfa.13 for ; Sat, 02 Jan 2021 22:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=FtzgqwLB03lrv+5eKW1g2CFVaUjhjvtleFv3ewkM0f4=; b=DcXnwKaCNeQZRzAGhC3ibgAekkJiiXsw8VmvSTs9l3JRMR0JkIyFMqpAwS4JHSYoKR 1My82vTloh1rb3nmXIws/h6w9FFF5w8EelvTnCdDM5YIo41Guk1hmJLmkNpqM7HhcS1H U9h1T+gots9CNc2xc+ld9bWkrxrcTdXv9XaFI5Psw+vRK8RrczMUikJ3AphCYkTOhZaU Z3CPv279DKRQe4eHeAYLhJ4V+oEcEOK4b++pwGRsdJWbXsh3PVf0cN12E+JiBftNWIxo CUhM/2DXqxDEJsKU/Jod4Bp+vf5H53OG3EwHZ9+NC9f7wftvhKPyt+O1QD7wH1cuc8ro lnGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=FtzgqwLB03lrv+5eKW1g2CFVaUjhjvtleFv3ewkM0f4=; b=DPDbHzpnntkYVD3B7iSgQnJqGwTYZxoHQdFRdjrdlW1dqq5Yn3DtkUd1lqpkGUX+ep FcHeVpqFT84SVRxY1h3Y3Ip7+Le1QYpo+VaNKgraYzwVjGsv0xw12jZJYNPoSUBA+mPi 89WJKeVPwBeR2PYuncNOXsCT8nNoPzEuOY7VG473V87TpkpwwC10e6T/fC3bVR0A/pVG JrEyFzcCSClHqKcJ+mhRchySJSz9DRg5ypqtjTqEH8jYYhsaJ/vqGGer4+wV7lto80Je mtqf74U8Zyd4a8R70xwBpk027/H6+7gyeZt5oBvOTDfJ2HXv0LiBZCn15v6XJN9/qCG7 Dtsg== X-Gm-Message-State: AOAM532SMI8HvEm8w3ec7JbIstwVzA+XN3QLXUcsDk4AwYNmZ2sNhBpD pRB8vFjPRkFXje0cghzDiNUdkFlw3koEFw== X-Google-Smtp-Source: ABdhPJwxh66947BeG/T5yGvgqkycM8t9L2QiGgWNf0U9cdzACGlha/VXDTpoF8Xpx+kkzfbj8a/cgw== X-Received: by 2002:a19:8cb:: with SMTP id 194mr31127958lfi.463.1609653601820; Sat, 02 Jan 2021 22:00:01 -0800 (PST) Received: from [1.0.0.7] ([178.155.6.1]) by smtp.gmail.com with ESMTPSA id q1sm8331974ljm.133.2021.01.02.22.00.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Jan 2021 22:00:01 -0800 (PST) Subject: Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs To: Michael Paquier , pgsql-bugs@lists.postgresql.org References: <16801-393c7922143eaa4d@postgresql.org> From: Alexander Lakhin Message-ID: Date: Sun, 3 Jan 2021 09:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Michael, 03.01.2021 08:15, Michael Paquier wrote: > On Sat, Jan 02, 2021 at 03:00:00PM +0000, PG Bug reporting form wrote: >> valgrind detects an invalid read: >> ==00:00:00:04.145 217144== Invalid read of size 8 >> ==00:00:00:04.145 217144== at 0x302CB7: makeDependencyGraphWalker >> (parse_cte.c:549) >> ==00:00:00:04.145 217144== by 0x302EA1: makeDependencyGraph >> (parse_cte.c:439) >> ==00:00:00:04.145 217144== by 0x304557: transformWithClause >> (parse_cte.c:176) >> >> The first bad commit is 1cff1b95. > The same kind of list manipulation is done in two places in > parse_cte.c, and there are extra ones in split_pathtarget_walker(). I > cannot reproduce that here, and I have just tried with different > optimization levels on HEAD and REL_13_STABLE. Are you using specific > options for valgrind? I'm using gcc 10.2.0 and valgrind-3.15.0, and building REL_13_STABLE (c09f6882) with: CPPFLAGS="-DUSE_VALGRIND -Og" ./configure --enable-debug --enable-cassert && make -j8 Also I'm using a  patch [1] to inject valgrind into the `make check` procedure. So it's possible to reproduce the issue with the extended with.sql: echo " WITH RECURSIVE rec(x) AS (     WITH outermost(x) AS (       SELECT (         WITH innermost as (SELECT 1)         SELECT * FROM innermost       )     )     SELECT * FROM outermost ) SELECT * FROM rec; " >>src/test/regress/sql/with.sql make check 'make check' fails and src/test/regress/log/postmaster.log contains the aforementioned valgrind message. If it's still not reproduced for you, please let me know your OS/compiler/valgrind version and I'll try it in your environment too. [1] https://www.postgresql.org/message-id/10dae4a1-e714-601d-7518-c19414255180%40gmail.com Best regards, Alexander