Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpdSn-0003yY-Ua for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Sep 2016 15:41:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bpdSn-0000RN-Gz for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Sep 2016 15:41:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bpdS8-0007zy-RC for pgsql-bugs@postgresql.org; Thu, 29 Sep 2016 15:40:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bpdS4-00066K-SF for pgsql-bugs@postgresql.org; Thu, 29 Sep 2016 15:40:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u8TFek3J022271; Thu, 29 Sep 2016 11:40:46 -0400 From: Tom Lane To: Peter Geoghegan cc: David Rowley , Michael Paquier , Robert Haas , Regina Obe , PostgreSQL mailing lists Subject: Re: BUG #14344: string_agg(DISTINCT ..) crash In-reply-to: References: <20160929035538.20224.39628@wrigleys.postgresql.org> <12479.1475122250@sss.pgh.pa.us> <000001d21a09$dd22a9f0$9767fdd0$@pcorp.us> Comments: In-reply-to Peter Geoghegan message dated "Thu, 29 Sep 2016 16:30:53 +0100" Date: Thu, 29 Sep 2016 11:40:46 -0400 Message-ID: <22270.1475163646@sss.pgh.pa.us> X-Pg-Spam-Score: -4.9 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Peter Geoghegan writes: > I see what the problem is. This use-after-free bug occurs because, for > some reason, tuplesort_gettupleslot()'s contract was not updated by me > alongside analogous routines like tuplesort_getindextuple() as part of > the batch memory commit. This meant that at least one particular case > (process_ordered_aggregate_multi() calls to tuplesort_gettupleslot(), > with distinct columns) felt entitled to reuse some slot's tuple, a > tuple located in memory managed by tuplesort.c as batch memory. My immediate reaction to this is WTF. It seems like you have completely broken the expected contract of tuplesort_gettupleslot, which is that it copies the data into caller-owned memory. That cannot stand. Even if you are willing to hack all the core callers so that they no longer expect that, you've probably broken --- subtly --- callers in extensions. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs