From: Jeff Davis <pgsql@j-davis.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: can insert timestamp value that can't be read
Date: Wed, 07 May 2014 19:34:17 -0700
Message-ID: <1399516457.27807.58.camel@sussancws0025> (raw)
In-Reply-To: <15053.1399438846@sss.pgh.pa.us>
References: <1399415471.27807.49.camel@sussancws0025>
<15053.1399438846@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Wed, 2014-05-07 at 01:00 -0400, Tom Lane wrote:
> Jeff Davis <pgsql@j-davis.com> writes:
> > It looks like timestamp[tz]_pl_interval() is not doing proper validation
> > in all paths.
>
> > Patch attached. I looked for other areas that might be affected, but
> > none jumped out.
>
> This seems to be adding a heck of a lot of cycles (viz, replacing a
> simple int64 or float8 addition with timestamp2tm then tm2timestamp)
> to fix a corner case that will probably not matter to anyone anytime
> in the next 200 thousand years, give or take a few millenia. I'm okay
> with the concept of detecting overflow here, but not at this price.
> Can't we do a more direct overflow check, comparable to what ordinary
> int64/float8 addition does?
It's a bit more complex than that, because a similar example of the bug
occurs without overflow when float timestamps are enabled. In
timestamp2tm(), the date can end up larger than INT_MAX.
In principle, I think the check in timestamp_pl_interval() can be quite
cheap, because we essentially just need to check for overflow and do a
bounds check. But it's hard to determine the precise valid bounds, and
it seems a little fragile.
I will see if I can extract the important parts of the validity check
into a new function (or macro). It would need to match the other checks
precisely though, otherwise this bug will persist.
> Also, surely timestamp_mi_interval has got the identical issue, and
> probably some other operators.
timestamp_mi_interval() calls timestamp_pl_interval(). I'll take a look
around for other similar problems though.
Regards,
Jeff Davis
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: pgsql@j-davis.com, tgl@sss.pgh.pa.us
Subject: Re: can insert timestamp value that can't be read
In-Reply-To: <1399516457.27807.58.camel@sussancws0025>
References: <1399415471.27807.49.camel@sussancws0025> <15053.1399438846@sss.pgh.pa.us> <1399516457.27807.58.camel@sussancws0025>
* 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