BUG #8230: Time interval size overflow

Started by Rok Kraljalmost 13 years ago4 messagesbugs
Jump to latest
#1Rok Kralj
rok.kralj@gmail.com

The following bug has been logged on the website:

Bug reference: 8230
Logged by: Rok Kralj
Email address: rok.kralj@gmail.com
PostgreSQL version: 9.2.4
Operating system: Arch Linux
Description:

As far as I know, the INTERVAL type is represented using three int32, one
for months, days and milliseconds.

However, overflow detections seems to work correctly only on these three
types; if they get overflown indirectly, they do not get detected:

SELECT INTERVAL '3000000000 days'
ERROR: interval field value out of range: "3000000000 days"

SELECT INTERVAL '2000000000 years'
-147483648 years

I'm surprised this hasn't been reported yet. The expected behaviour is to
raise an error.

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Bruce Momjian
bruce@momjian.us
In reply to: Rok Kralj (#1)
Re: BUG #8230: Time interval size overflow

On Sun, Jun 16, 2013 at 11:03:53AM +0000, rok.kralj@gmail.com wrote:

The following bug has been logged on the website:

Bug reference: 8230
Logged by: Rok Kralj
Email address: rok.kralj@gmail.com
PostgreSQL version: 9.2.4
Operating system: Arch Linux
Description:

As far as I know, the INTERVAL type is represented using three int32, one
for months, days and milliseconds.

However, overflow detections seems to work correctly only on these three
types; if they get overflown indirectly, they do not get detected:

SELECT INTERVAL '3000000000 days'
ERROR: interval field value out of range: "3000000000 days"

SELECT INTERVAL '2000000000 years'
-147483648 years

I'm surprised this hasn't been reported yet. The expected behaviour is to
raise an error.

The attached patch fixes the problem:

test=> SELECT INTERVAL '2000000000 years';
ERROR: interval out of range
LINE 1: SELECT INTERVAL '2000000000 years';

It also fixes this case

test=> SELECT INTERVAL '2000000000-3 years';
ERROR: interval field value out of range: "2000000000-3 years"
LINE 1: SELECT INTERVAL '2000000000-3 years';

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachments:

interval.difftext/x-diff; charset=us-asciiDownload+6-0
#3Rok Kralj
rok.kralj@gmail.com
In reply to: Bruce Momjian (#2)
Re: BUG #8230: Time interval size overflow

Hello Bruce,

thank you for your contribution. However, as seen from my later report, the
situation is much much worse (complex, if you want) than this bug. Please
see this:

/messages/by-id/CAMWF=HS++N9-NKsh-o5QSymvp0Np-VB0GdWwAt4uie1h8ZdNTQ@mail.gmail.com

Rok Kralj,
PostgreSQL enthusiast

2014-01-25 Bruce Momjian <bruce@momjian.us>

On Sun, Jun 16, 2013 at 11:03:53AM +0000, rok.kralj@gmail.com wrote:

The following bug has been logged on the website:

Bug reference: 8230
Logged by: Rok Kralj
Email address: rok.kralj@gmail.com
PostgreSQL version: 9.2.4
Operating system: Arch Linux
Description:

As far as I know, the INTERVAL type is represented using three int32, one
for months, days and milliseconds.

However, overflow detections seems to work correctly only on these three
types; if they get overflown indirectly, they do not get detected:

SELECT INTERVAL '3000000000 days'
ERROR: interval field value out of range: "3000000000 days"

SELECT INTERVAL '2000000000 years'
-147483648 years

I'm surprised this hasn't been reported yet. The expected behaviour is to
raise an error.

The attached patch fixes the problem:

test=> SELECT INTERVAL '2000000000 years';
ERROR: interval out of range
LINE 1: SELECT INTERVAL '2000000000 years';

It also fixes this case

test=> SELECT INTERVAL '2000000000-3 years';
ERROR: interval field value out of range: "2000000000-3 years"
LINE 1: SELECT INTERVAL '2000000000-3 years';

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

--
eMail: rok.kralj@gmail.com

#4Bruce Momjian
bruce@momjian.us
In reply to: Rok Kralj (#3)
Re: BUG #8230: Time interval size overflow

On Sat, Jan 25, 2014 at 10:07:36PM +0100, Rok Kralj wrote:

Hello Bruce,

thank you for your contribution. However, as seen from my later report, the
situation is much much worse (complex, if you want) than this bug. Please see
this:

/messages/by-id/CAMWF=
HS++N9-NKsh-o5QSymvp0Np-VB0GdWwAt4uie1h8ZdNTQ@mail.gmail.com

Yes, I see that in my mailbox and will address those shortly, but at
least this patch fixes part of the problem.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs