GetBufferDescriptor() being called for local buffers from MarkBufferDirtyHint()

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: GetBufferDescriptor() being called for local buffers from MarkBufferDirtyHint()
Date: 2026-06-06 08:07:42
Message-ID: CAExHW5uzRMYVZsXXS3HXXT0fG_sNrpUhUqwP4NorhaCqH9JDhA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Andres,

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.

I caught this because of an Assertion added in GetBufferDescription()
in my shared buffer resizing patches. I think it's worth committing
that assertion and the related change to BufferManagerShmemInit()
separately from shared buffer resizing patches. Included those changes
in the attached patch as well.

--
Best Wishes,
Ashutosh Bapat

Attachment Content-Type Size
v20260606-0001-MarkBufferDirtyHint-calls-GetBufferDescrip.patch text/x-patch 3.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikolay Samokhvalov 2026-06-06 08:30:51 PG19 FK fast path: OOB write and missed FK checks during batched
Previous Message David Rowley 2026-06-06 04:50:29 Re: Fix tuple deformation with virtual generated NOT NULL columns