Re: [PATCH] Fix possible overflow on tuplesort.c

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Fix possible overflow on tuplesort.c
Date: 2020-04-23 19:43:14
Message-ID: 20200423194314.GA22975@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020-Apr-16, Ranier Vilela wrote:

> When multiplying variables, the overflow will take place anyway, and only
> then will the meaningless product be explicitly promoted to type int64.
> It is one of the operands that should have been cast instead to avoid the
> overflow.
>
> - if (state->availMem < (int64) ((newmemtupsize - memtupsize) * sizeof(SortTuple)))
> + if (state->availMem < ((int64) (newmemtupsize - memtupsize) * sizeof(SortTuple)))

Doesn't sizeof() return a 64-bit wide value already?

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2020-04-23 19:43:43 Re: [PATCH] FIx resource leaks (pg_resetwal.c)
Previous Message Tom Lane 2020-04-23 19:38:56 Re: HEAPDEBUGALL is broken