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 1po5D4-0008Qo-VX for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Apr 2023 16:26:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1po5D2-0000RS-Ps for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Apr 2023 16:26:36 +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 1po5D2-0000RI-F9 for pgsql-hackers@lists.postgresql.org; Sun, 16 Apr 2023 16:26:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1po5Cv-000AY8-Ku for pgsql-hackers@postgresql.org; Sun, 16 Apr 2023 16:26:35 +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 33GGQS5K2199320; Sun, 16 Apr 2023 12:26:28 -0400 From: Tom Lane To: Justin Pryzby cc: David Rowley , pgsql-hackers@postgresql.org Subject: Re: v16dev: invalid memory alloc request size 8488348128 In-reply-to: References: Comments: In-reply-to Justin Pryzby message dated "Sat, 15 Apr 2023 18:19:04 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2199318.1681662388.1@sss.pgh.pa.us> Date: Sun, 16 Apr 2023 12:26:28 -0400 Message-ID: <2199319.1681662388@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Justin Pryzby writes: > On Sat, Apr 15, 2023 at 11:33:58AM +1200, David Rowley wrote: >> Any chance you could try and come up with a minimal reproducer? > Try this Thanks. I see the problem: finalize_aggregate is no longer forcing a R/W expanded datum returned by the finalfn into R/O form. If we re-use the aggregate result in multiple places, as this query does, then the first use can clobber the value for later uses. (The commit message specifically mentions this concern, so I wonder how we failed to actually do it :-() A minimal fix would be to force to R/O before returning from finalize_aggregate, but I wonder if we should do it later. By the by, I couldn't help noticing that ExecAggTransReparent completely fails to do what its name promises it should do, ie reparent a R/W datum into the proper context instead of physically copying it. That looks suspiciously like something that got broken during some other refactoring somewhere along the line. That'd be a performance bug not a correctness bug, but it should be looked into. regards, tom lane