Re: Avoid possible overflow (src/port/bsearch_arg.c)

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Tomas Vondra <tomas@vondra.me>, Ranier Vilela <ranier.vf@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>, Tomas Vondra <tv@fuzzy.cz>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2024-10-28T16:52:15Z
Lists: pgsql-hackers
On 28/10/2024 17:30, Tomas Vondra wrote:
>> Some of those other implementations have fixed this, others have not.
>> And they all seem to also have the "involes" typo in the comment that we
>> fixed in commit 7ef8b52cf07 :-). Ranier, you might want to submit this
>> fix to those other projects too.
> 
> Thanks for fixing this, although I wonder if we can actually hit this,
> as we don't really allocate more than 1GB in most places. But it's
> possible, and the pre-bfa2cee code handled it fine.

Yeah, I didn't check closely I'm pretty sure none of the current 
callsites can pass anything near INT_MAX elements.

While we're at it, there's this in dicts/spell.h:

> /*
>  * Structure to store Hunspell options. Flag representation depends on flag
>  * type. These flags are about support of compound words.
>  */
> typedef struct CompoundAffixFlag
> {
>         union
>         {
>                 /* Flag name if flagMode is FM_CHAR or FM_LONG */
>                 const char *s;
>                 /* Flag name if flagMode is FM_NUM */
>                 uint32          i;
>         }                       flag;
>         /* we don't have a bsearch_arg version, so, copy FlagMode */
>         FlagMode        flagMode;
>         uint32          value;
> } CompoundAffixFlag;

We have bsearch_arg() now, so we could switch to that and remove 
'flagMode' from here.

-- 
Heikki Linnakangas
Neon (https://neon.tech)




Commits

  1. Fix overflow in bsearch_arg() with more than INT_MAX elements

  2. Fix typos and grammar in comments and docs

  3. Move bsearch_arg to src/port