pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8230: Time interval size overflow
4+ messages / 3 participants
[nested] [flat]
* BUG #8230: Time interval size overflow
@ 2013-06-16 11:03 rok.kralj@gmail.com
0 siblings, 1 reply; 4+ messages in thread
From: rok.kralj@gmail.com @ 2013-06-16 11:03 UTC (permalink / raw)
To: pgsql-bugs
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #8230: Time interval size overflow
@ 2014-01-25 20:56 Bruce Momjian <bruce@momjian.us>
parent: rok.kralj@gmail.com
0 siblings, 1 reply; 4+ messages in thread
From: Bruce Momjian @ 2014-01-25 20:56 UTC (permalink / raw)
To: rok.kralj@gmail.com; +Cc: pgsql-bugs
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. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
interval.diff (text/x-diff, 1.6K) download
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
new file mode 100644
index a61b40e..ae4e9e7
*** a/src/backend/utils/adt/datetime.c
--- b/src/backend/utils/adt/datetime.c
*************** DecodeInterval(char **field, int *ftype,
*** 2976,2981 ****
--- 2976,2983 ----
type = DTK_MONTH;
if (*field[i] == '-')
val2 = -val2;
+ if (((float)val * MONTHS_PER_YEAR + val2) > INT_MAX)
+ return DTERR_FIELD_OVERFLOW;
val = val * MONTHS_PER_YEAR + val2;
fval = 0;
}
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
new file mode 100644
index 4581862..a751593
*** a/src/backend/utils/adt/timestamp.c
--- b/src/backend/utils/adt/timestamp.c
*************** recalc:
*** 1725,1730 ****
--- 1725,1732 ----
int
tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
{
+ if ((float)tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon > INT_MAX)
+ return -1;
span->month = tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon;
span->day = tm->tm_mday;
#ifdef HAVE_INT64_TIMESTAMP
diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c
new file mode 100644
index efa775d..e1307e3
*** a/src/interfaces/ecpg/pgtypeslib/interval.c
--- b/src/interfaces/ecpg/pgtypeslib/interval.c
*************** recalc:
*** 1036,1041 ****
--- 1036,1043 ----
static int
tm2interval(struct tm * tm, fsec_t fsec, interval * span)
{
+ if ((float)tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon > INT_MAX)
+ return -1;
span->month = tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon;
#ifdef HAVE_INT64_TIMESTAMP
span->time = (((((((tm->tm_mday * INT64CONST(24)) +
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #8230: Time interval size overflow
@ 2014-01-25 21:07 Rok Kralj <rok.kralj@gmail.com>
parent: Bruce Momjian <bruce@momjian.us>
0 siblings, 1 reply; 4+ messages in thread
From: Rok Kralj @ 2014-01-25 21:07 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: pgsql-bugs
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:
http://www.postgresql.org/message-id/CAMWF=HS++N9-NKsh-o5QSymvp0Np-VB0GdWwAt4uie1h8ZdNTQ@mail.gmail....
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #8230: Time interval size overflow
@ 2014-01-25 21:30 Bruce Momjian <bruce@momjian.us>
parent: Rok Kralj <rok.kralj@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Bruce Momjian @ 2014-01-25 21:30 UTC (permalink / raw)
To: Rok Kralj <rok.kralj@gmail.com>; +Cc: pgsql-bugs
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:
>
> http://www.postgresql.org/message-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
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2014-01-25 21:30 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-06-16 11:03 BUG #8230: Time interval size overflow rok.kralj@gmail.com
2014-01-25 20:56 ` Bruce Momjian <bruce@momjian.us>
2014-01-25 21:07 ` Rok Kralj <rok.kralj@gmail.com>
2014-01-25 21:30 ` Bruce Momjian <bruce@momjian.us>
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