BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: exclusion(at)gmail(dot)com
Subject: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs
Date: 2021-01-02 15:00:00
Message-ID: 16801-393c7922143eaa4d@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16801
Logged by: Alexander Lakhin
Email address: exclusion(at)gmail(dot)com
PostgreSQL version: 13.1
Operating system: Ubuntu 20.04
Description:

When executing the following query:
WITH RECURSIVE rec(x) AS (
WITH outermost(x) AS (
SELECT (
WITH innermost as (SELECT 1)
SELECT * FROM innermost
)
)
SELECT * FROM outermost
)
SELECT * FROM rec;

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)
==00:00:00:04.145 217144== by 0x2DD70A: transformSelectStmt
(analyze.c:1202)
==00:00:00:04.145 217144== by 0x2DDAB4: transformStmt (analyze.c:301)
==00:00:00:04.145 217144== by 0x2DEDDA: transformOptionalSelectInto
(analyze.c:246)
==00:00:00:04.145 217144== by 0x2DEE0F: transformTopLevelStmt
(analyze.c:196)
==00:00:00:04.145 217144== by 0x2DEE71: parse_analyze (analyze.c:116)
==00:00:00:04.145 217144== by 0x55E69F: pg_analyze_and_rewrite
(postgres.c:691)
==00:00:00:04.145 217144== by 0x55ED66: exec_simple_query
(postgres.c:1155)
==00:00:00:04.145 217144== by 0x560D83: PostgresMain (postgres.c:4315)
==00:00:00:04.145 217144== by 0x4CC6B8: BackendRun (postmaster.c:4526)
==00:00:00:04.145 217144== Address 0x50890a8 is 24 bytes inside a block of
size 32 client-defined
==00:00:00:04.145 217144== at 0x6B4831: palloc (mcxt.c:974)
==00:00:00:04.145 217144== by 0x42B624: new_list (list.c:134)
==00:00:00:04.145 217144== by 0x42BF1B: lcons (list.c:458)
==00:00:00:04.145 217144== by 0x302C73: makeDependencyGraphWalker
(parse_cte.c:542)
==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)
==00:00:00:04.145 217144== by 0x2DD70A: transformSelectStmt
(analyze.c:1202)
==00:00:00:04.145 217144== by 0x2DDAB4: transformStmt (analyze.c:301)
==00:00:00:04.145 217144== by 0x2DEDDA: transformOptionalSelectInto
(analyze.c:246)
==00:00:00:04.145 217144== by 0x2DEE0F: transformTopLevelStmt
(analyze.c:196)
==00:00:00:04.145 217144== by 0x2DEE71: parse_analyze (analyze.c:116)
==00:00:00:04.145 217144== by 0x55E69F: pg_analyze_and_rewrite
(postgres.c:691)
==00:00:00:04.145 217144==

The first bad commit is 1cff1b95.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2021-01-03 05:15:58 Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs
Previous Message Tom Lane 2021-01-01 20:54:20 Re: BUG #16797: EXTRACT(EPOCH FROM timestamp) is not using local timezone