Re: a potential size overflow issue

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Zhang <david(dot)zhang(at)highgo(dot)ca>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: a potential size overflow issue
Date: 2020-09-26 05:03:37
Message-ID: 1968349.1601096617@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

David Zhang <david(dot)zhang(at)highgo(dot)ca> writes:
> "InitBufTable" is the function used to initialize the buffer lookup
> table for buffer manager. With the memory size increasing nowadays,
> there is a potential overflow issue for the parameter "int size" used by
> "InitBufTable". This function is invoked in freelist.c as below:
>     InitBufTable(NBuffers + NUM_BUFFER_PARTITIONS);

> The number of buffer block “NBuffers” is also defined as "int", and
> "NUM_BUFFER_PARTITIONS" has a default value 128. In theory, it may get
> the chance to overflow the "size" parameter in "InitBufTable".

No, because guc.c limits NBuffers to INT_MAX/2.

> Therefore, it would be better to change "InitBufTable(int size)" to
> "InitBufTable(long size)".

If I was worried about this, that wouldn't be much of a fix, since
on many platforms "long" is not any wider than "int". (We really
oughta try to move away from relying on "long", because its size
is so poorly standardized.)

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2020-09-26 05:16:51 Re: Parallel INSERT (INTO ... SELECT ...)
Previous Message Merlin Moncure 2020-09-26 00:37:07 Re: Optimize memory allocation code