Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-30 Thread Ranier Vilela
Em ter., 29 de ago. de 2023 às 20:06, Michael Paquier escreveu: > On Thu, Aug 24, 2023 at 07:02:40PM -0700, Peter Geoghegan wrote: > > FWIW I'm pretty sure that it's impossible to run into problems here in > > practice -- the minheap is allocated by palloc(), and the high > > watermark number of

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-29 Thread Michael Paquier
On Thu, Aug 24, 2023 at 07:02:40PM -0700, Peter Geoghegan wrote: > FWIW I'm pretty sure that it's impossible to run into problems here in > practice -- the minheap is allocated by palloc(), and the high > watermark number of free pages is pretty small. Even still, I agree > with your conclusion. Th

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread Peter Geoghegan
On Thu, Aug 24, 2023 at 6:44 PM David Rowley wrote: > I agree with this. I think Ranier's patch is good and we should apply > it and backpatch it. FWIW I'm pretty sure that it's impossible to run into problems here in practice -- the minheap is allocated by palloc(), and the high watermark number

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread Peter Geoghegan
On Thu, Aug 24, 2023 at 6:18 PM Michael Paquier wrote: > Still that looks entirely different to me. Here we have a problem > where the number of free blocks stored may cause an overflow in the > internal routine retrieving a free block, but your other thread > is about long being not enough on Wi

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread David Rowley
On Fri, 25 Aug 2023 at 13:19, Michael Paquier wrote: > Still that looks entirely different to me. Here we have a problem > where the number of free blocks stored may cause an overflow in the > internal routine retrieving a free block, but your other thread > is about long being not enough on Wind

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread Michael Paquier
On Thu, Aug 24, 2023 at 05:33:15PM -0700, Peter Geoghegan wrote: > I am in favor of fixing the problem. I don't quite recall what it was > that made the discussion stall last time around. I think that you mean this one: https://www.postgresql.org/message-id/CAH2-WznCscXnWmnj=STC0aSa7QG+BRedDnZsP=j

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread Peter Geoghegan
On Thu, Aug 24, 2023 at 4:47 PM Michael Paquier wrote: > > patch attached. > > Yeah, it looks like you're right here. Will do something about that. This is a known issue. It has been discussed before. I am in favor of fixing the problem. I don't quite recall what it was that made the discussion

Re: Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread Michael Paquier
On Thu, Aug 24, 2023 at 02:46:42PM -0300, Ranier Vilela wrote: > With Windows both *long* and *int* are 4 bytes. > But with Linux *long* is 8 bytes and *int* are 4 bytes. And I recall that WIN32 is the only place where we treat long as 4 bytes. > patch attached. Yeah, it looks like you're right

Avoid a possible overflow (src/backend/utils/sort/logtape.c)

2023-08-24 Thread Ranier Vilela
Hi, nFreeBlocks stores the number of free blocks and your type is *long*. At Function ltsGetFreeBlock is locally stored in heapsize wich type is *int* With Windows both *long* and *int* are 4 bytes. But with Linux *long* is 8 bytes and *int* are 4 bytes. patch attached. best regards, Ranier Vi