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.96) (envelope-from ) id 1wXK2d-003C3U-1p for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jun 2026 14:36:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wXK2c-00C3JI-1J for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jun 2026 14:36:26 +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.96) (envelope-from ) id 1wXK2b-00C3JA-39 for pgsql-hackers@lists.postgresql.org; Wed, 10 Jun 2026 14:36:25 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wXK2a-000000021Vn-03Up for pgsql-hackers@lists.postgresql.org; Wed, 10 Jun 2026 14:36:24 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id 0B8741D0011D; Wed, 10 Jun 2026 10:36:23 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Wed, 10 Jun 2026 10:36:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1781102182; x=1781188582; bh=pQnoAJVrKc 4dYlKC0etVlU1jbx1dGPS4p3cM1gbqFEU=; b=ISHzdzhMvuDydTL/5M2lUxcTON u4eepm7DgV6hlGbY6FbcwkXm1deG4ARm/RAXqHqUvENPS/D1zthHMq/IjxT3cklN af7oE2qgA7e0f2P2eqFyu7ZF6k5c4+5U6danuZR0wGaXVhzPFrErFMfHVn8XcTgf ixf1/UmIKCTDKEOB7Q+ExZpzmyNMXZg1AMmw4dr0oMArpxXFM7zi+ZcnP4HH0Jw0 NrSq3x42nLOc+SQkBCbyQkdDSvNtt8b8F0xEWC4iR1EJImuS9Rq2+lxDqhLXuqzL UELt+eb5GKsyRzZuDPvkSviddc+/RYmiHeIsydqF4qH9A63RusF/GWuuJLYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1781102182; x=1781188582; bh=pQnoAJVrKc4dYlKC0etVlU1jbx1dGPS4p3c M1gbqFEU=; b=KAXBtHNoEofwklC8pLdkjqemkbhrXT55opSQD0PycQXRb7lxJyk ccMLt6YG1C6pyGqjq/BJjf2yoGqWJ0huz/iS9KpNYJ89IzZidUW+6K2bIcXaG21G OuZEqjPG2FQSU7bCo/4tLL0mH5XeVkrQpWCSSm6SEQUILE07Zeh0NDQ+BDUXzsuj rMLZerGpscxnGaVHJyofUu9c2HH5maeWf67yeDtww+nHNAsENSSehJH4K/a0KxUn Iw763BqxPtBJ0afTiBAa1eBLZu6d3ECxm68OFL7OQOUIv7BTZeXA2aWuib+ViVGd DsPSGvyq1mLVKS/G7FSjnW19PH0ga8m8E7A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGhgWCRAocI/h/nDwocoDJItgYO0ZoBDONlgmhZw4LWXqBoz6mRuosmKnxdAVw7/7 Je/NeL1h1m8mF8RqrPiV2BFd7xQZhBQ+02cuX/YWK1zoHXRehOTkHO2tsQuX1kb6ZYhuIs KjqATudki71lDlJVUKNE/k0zlpEmIHU6zKgRGWqSesMeBrXnVTDM9QPMA/dLPZgI5xR5Z9 YiNyEaH1FkjvprXvcWtUNoWvvHy3qgztWv3Y333u8yHTqtjO6yJOQoZ82EjZGgA0s6m1PF FEo4TD4YUx6IFlk7cjIc5bcA0qN6jM5knjdRY5WxBP4NjHqRJ93w+wAoDm/geIjFCUmGWM Q5IO2kYYTtqdEd3+b6p41IcNAPw5LlBH11lsyEgS1LQRCFvmg9CnBuaM2edQ8dlx2m9lqX 0qPUKo6B/J7B2QNQbfMjII/nNgCiP37rwWTjv3A12cp2rm8Sp9Unx+GJEnYcpSIepp9Qbd wcFkCfTt7Br3tEIIuDqw2VKHLjVX01234rM8dcMl38JpSQxmau6jg2IiwB+MAZ8ml4W/y7 q247LBJCdfU9qOSkehpqLjvZ1vqoWg+beVKATWsr59QE0XgFvJ2y/tlOL2GbZv2IiL3B2w tfxsR7wvXQsHdSj27jCIJ/nUHIE3BPTxzdP2lvUFr0tEba1NxBmMgTEBcNTA X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 10 Jun 2026 10:36:22 -0400 (EDT) Date: Wed, 10 Jun 2026 10:36:22 -0400 From: Andres Freund To: Michael Paquier Cc: Ashutosh Bapat , PostgreSQL Hackers Subject: Re: GetBufferDescriptor() being called for local buffers from MarkBufferDirtyHint() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-06-10 12:40:38 +0900, Michael Paquier wrote: > On Sat, Jun 06, 2026 at 01:37:42PM +0530, Ashutosh Bapat wrote: > > 82467f627bd478569de04f4a3f1993098e80c812 added MarkBufferDirtyHint() > > which invokes GetBufferDescriptor() even for local buffers for which > > id < 0. Since GetBufferDescriptor() declares id as uint32, -1 is > > converted to a very large int32 value which is way larger than > > NBuffers. Thus GetBufferDescriptor() may be returning something from > > the BufferBlocks which probably has enough memory to accommodate that > > memory access. But it's a bogus BufferDesc nevertheless. We are not > > seeing any problem with this right now since MarkBufferDirtyHint() > > uses the BufferDesc only when it's a shared buffer. Right fix is to > > let that function handle local buffers first and then call > > GetBufferDescriptor() as in the attached patch. > > @@ -5831,8 +5831,6 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std) > { > BufferDesc *bufHdr; > > - bufHdr = GetBufferDescriptor(buffer - 1); > - > if (!BufferIsValid(buffer)) > elog(ERROR, "bad buffer ID: %d", buffer); > > @@ -5842,6 +5840,8 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std) > return; > } > > + bufHdr = GetBufferDescriptor(buffer - 1); > > Yep, that's clearly wrong. We are lucky that it does not blow up > today but that's a ticking bomb. I think it *should* blow up. It doesn't because we're lacking assertions in GetBufferDescriptor(). But I don't think the assertions added in the patch are quite right. We can't trivially add the correct assertions, because somebody though it was a good idea to give GetBufferDescriptor() a uint32 parameter, which seems completely wrong to me. > Even with that in mind, the result leads to a non-defined behavior. I'm not sure it really does, but it's clearly wrong. Greetings, Andres Freund