Avoid overflow with simplehash

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Avoid overflow with simplehash
Date: 2023-07-06 14:28:18
Message-ID: CAEudQAocXNJ6s1VLz+hMamLAQAiewRoW17OJ6-+9GACKfj6iPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

SimpleHash.

The function SH_START_ITERATE can trigger some overflow.

See:
typedef struct SH_ITERATOR
{
uint32 cur; /* current element */
uint32 end;
bool done; /* iterator exhausted? */
} SH_ITERATOR;

The cur field is uint32 size and currently can be stored a uint64,
which obviously does not fit.

Also, the current index is int, which is possibly insufficient
since items can be up to uint32.

Attached a fix.

best regards,
Ranier Vilela

Attachment Content-Type Size
avoid-overflow-with-simplehash-start-iterate.patch application/octet-stream 740 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2023-07-06 14:29:10 Re: generic plans and "initial" pruning
Previous Message Pavel Stehule 2023-07-06 14:21:31 Re: Schema variables - new implementation for Postgres 15