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 1pubHG-0003nP-4U for pgsql-bugs@arkaria.postgresql.org; Thu, 04 May 2023 15:53: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 1pubHF-0006Nk-18 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 May 2023 15:53:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pubHE-0006Nb-Pb for pgsql-bugs@lists.postgresql.org; Thu, 04 May 2023 15:53:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pubHC-000YnQ-7s for pgsql-bugs@lists.postgresql.org; Thu, 04 May 2023 15:53:52 +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 344Frmt63414187; Thu, 4 May 2023 11:53:48 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17920: Incorrect memory access in array_position(s) is detected (or not) In-reply-to: <17920-f7c228c627b6d02e@postgresql.org> References: <17920-f7c228c627b6d02e@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 04 May 2023 13:00:00 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3414185.1683215628.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 04 May 2023 11:53:48 -0400 Message-ID: <3414186.1683215628@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > When the following script: > SELECT array_positions('{}'::int[], 1); SELECT array_positions('{}'::int= [], > 1) > is executed under Valgrind, an incorrect memory access is detected: > =3D=3D00:00:00:04.955 1823064=3D=3D Invalid read of size 4 > =3D=3D00:00:00:04.955 1823064=3D=3D at 0x5EDBD0: array_positions > (array_userfuncs.c:806) Fixed, thanks for the report! > I was surprised by the fact, that Valgrind doesn't complain for the sing= le > query execution: > SELECT array_positions('{}'::int[], 1) > IIUC, this is explained by the lack of red zones around palloc'ed memory > areas. > sed "s/VALGRIND_CREATE_MEMPOOL(\(.*\), 0, false);/VALGRIND_CREATE_MEMPOO= L(\1, 16, false);/" -i > src/backend/utils/mmgr/mcxt.c > on master (after 414d66220) helps Valgrind to detect the invalid read on > the single query execution too: I didn't try valgrind'ing this on HEAD, but I think this situation might have been improved by 414d66220. regards, tom lane