Re: Fw: Re: heap_force_common in contrib/pg_surgery/heap_surgery.c has an off by one stack buffer overflow - Mailing list pgsql-bugs

From Ashutosh Sharma
Subject Re: Fw: Re: heap_force_common in contrib/pg_surgery/heap_surgery.c has an off by one stack buffer overflow
Date
Msg-id CAE9k0P=9M4RzzPpHFdYjPyvfxkEToY-iomUT7twZvKSwsVXQmA@mail.gmail.com
Whole thread
Responses Re: Fw: Re: heap_force_common in contrib/pg_surgery/heap_surgery.c has an off by one stack buffer overflow
List pgsql-bugs
Hi Michael,

Thanks for the patch.

On Fri, Jun 5, 2026 at 12:27 PM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Fri, Jun 05, 2026 at 08:17:15AM +0900, Michael Paquier wrote:
> > At the end, the first pattern is an outlier, we don't need to worry
> > about performance in pg_surgery, and we're talking about three lines
> > of code in pg_surgery to change (two for include_this_tid, one for the
> > assertion).  With all that in mind, I'd just do a -1 conversion and
> > call it a day.  :)
>
> Which implies something like the simpler patch attached.

I have one small comment:

"+ Assert((offno - 1) < MaxHeapTuplesPerPage);"

I think this can be simplified to:

Assert(offno <= MaxHeapTuplesPerPage);

Since "offno" is already 1-based, there doesn't seem to be a need to
subtract 1 from it and adjust the comparison accordingly.

--
With Regards,
Ashutosh Sharma.



pgsql-bugs by date:

Previous
From: Fujii Masao
Date:
Subject: Re: BUG #19508: pg_buffercache_pages() crashes the backend with an incompatible caller-supplied record definition
Next
From: "Zhijie Hou (Fujitsu)"
Date:
Subject: RE: BUG #19500: pgrepack logical decoding plugin can crash assert builds via SQL decoding API