pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mats Kindahl <mats@timescale.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17876: Function width_bucket() for float8 input returns value out of range
Date: Thu, 30 Mar 2023 11:35:03 -0400
Message-ID: <186575.1680190503@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+14424DZUcLpWnoRURmT1m6Uet1_R39sV=8XhtFRiigVtYqDg@mail.gmail.com>
References: <17876-61f280d1601f978d@postgresql.org>
	<CA+14427KvPsskajKSriGACyrudcOyh5ohmt=0WPuNjoMTSQM6A@mail.gmail.com>
	<3807420.1680093217@sss.pgh.pa.us>
	<CA+14424DZUcLpWnoRURmT1m6Uet1_R39sV=8XhtFRiigVtYqDg@mail.gmail.com>

Mats Kindahl <mats@timescale.com> writes:
> However, better safe than sorry, so I modified the patch to include the
> check. And yes, you're right in that there is no need to check for the
> operand diff since the previous checks guarantee that the operand is
> between the bounds, and since the diff between the bounds is not infinite,
> the diff between the operand and any of the bounds cannot be infinite.
> Added a comment to that effect to the patch as well.

I looked this over and noted two problems:

* You missed fixing the mirror code path (bound1 > bound2).

* It seems at least possible that, for an operand just slightly less
than bound2, the quotient ((operand - bound1) / (bound2 - bound1))
could round to exactly 1, even though it should theoretically always
be in [0, 1).  If that did happen, and count is INT_MAX, then the final
addition of 1 would create its own possibility of integer overflow.
We have code to check that but it's only applied in the operand >= bound2
case.  I fixed that by moving the overflow-aware addition of 1 to the
bottom of the function so it's done in all cases, and adjusting the other
code paths to account for that.

Pushed with those changes and some cosmetic tweaking.

			regards, tom lane





view thread (9+ messages)  latest in thread

Message-ID: <186575.1680190503@sss.pgh.pa.us>
Permalink:  ../186575.1680190503@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/186575.1680190503@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mats@timescale.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17876: Function width_bucket() for float8 input returns value out of range
  In-Reply-To: <186575.1680190503@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox