Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vBbRw-001Dz6-Gp for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 16:12:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vBbRv-0006MD-5Q for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 16:12:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vBbRu-0006M3-Pb for pgsql-hackers@lists.postgresql.org; Wed, 22 Oct 2025 16:12:29 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vBbRr-003BcK-33 for pgsql-hackers@postgresql.org; Wed, 22 Oct 2025 16:12:28 +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 59MGC8ru798103; Wed, 22 Oct 2025 12:12:08 -0400 From: Tom Lane To: Thomas Munro cc: Noah Misch , Melanie Plageman , vignesh C , Andres Freund , Pg Hackers , Heikki Linnakangas , Nazir Bilal Yavuz , Robert Haas , "Andrey M. Borodin" Subject: Re: Confine vacuum skip logic to lazy_scan_skip In-reply-to: References: <20240306234733.nd4a636colxkgq2e@liskov> <20240707144944.58.nmisch@google.com> <20240716015226.60.nmisch@google.com> Comments: In-reply-to Thomas Munro message dated "Wed, 24 Jul 2024 17:40:12 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <798101.1761149528.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 22 Oct 2025 12:12:08 -0400 Message-ID: <798102.1761149528@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ seizing on this old commit as being most closely related to the issue ] Thomas Munro writes: > On Tue, Jul 16, 2024 at 1:52=E2=80=AFPM Noah Misch w= rote: >> On Mon, Jul 15, 2024 at 03:26:32PM +1200, Thomas Munro wrote: >> That's reasonable. radixtree already forbids mutations concurrent with >> iteration, so there's no new concurrency hazard. One alternative is >> per_buffer_data big enough for MaxOffsetNumber, but that might thrash c= aches >> measurably. That patch is good to go apart from these trivialities: > Thanks! I have pushed that patch, without those changes you didn't like= . The security team recently updated our Coverity instance to the latest version, and it's started complaining as follows: *** CID 1667418: Memory - corruptions (OVERRUN) /srv/coverity/git/pgsql-git/postgresql/src/backend/access/heap/vacuumlazy.= c: 2812 in lazy_vacuum_heap_rel() 2806 * already have the correct page pinned anyway. 2807 */ 2808 visibilitymap_pin(vacrel->rel, blkno, &vmbuffer); 2809 = 2810 /* We need a non-cleanup exclusive lock to mark dead_item= s unused */ 2811 LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); >>> CID 1667418: Memory - corruptions (OVERRUN) >>> Overrunning callee's array of size 291 by passing argument "num_of= fsets" (which evaluates to 2048) in call to "lazy_vacuum_heap_page". 2812 lazy_vacuum_heap_page(vacrel, blkno, buf, offsets, 2813 num_offsets, vmbuffer); 2814 = 2815 /* Now that we've vacuumed the page, record its available= space */ 2816 page =3D BufferGetPage(buf); 2817 freespace =3D PageGetHeapFreeSpace(page); The reason it thinks that num_offsets could be as much as 2048 is presumably the code a little bit above this: OffsetNumber offsets[MaxOffsetNumber]; ... num_offsets =3D TidStoreGetBlockOffsets(iter_result, offsets, leng= thof(offsets)); Assert(num_offsets <=3D lengthof(offsets)); However, lazy_vacuum_heap_page blindly assumes that the passed value will be no more than MaxHeapTuplesPerPage. It seems like we ought to get these two functions in sync, either both using MaxOffsetNumber or both using MaxHeapTuplesPerPage for their array sizes. It looks to me like MaxHeapTuplesPerPage should be sufficient. Also, after reading TidStoreGetBlockOffsets I wonder if we should replace that Assert with num_offsets =3D Min(num_offsets, lengthof(offsets)); Thoughts? regards, tom lane