Skip to content

Commit 3bd2241

Browse files
committed
Fix overflow for INTERVAL 'x ms' where x is more than a couple million,
and integer datetimes are in use. Per bug report from Hubert Depesz Lubaczewski. Alex Hunsaker
1 parent e31b35f commit 3bd2241

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.208 2009/06/11 14:49:03 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.209 2009/08/18 21:23:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2986,6 +2986,9 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
29862986
break;
29872987

29882988
case DTK_MILLISEC:
2989+
/* avoid overflowing the fsec field */
2990+
tm->tm_sec += val / 1000;
2991+
val -= (val / 1000) * 1000;
29892992
#ifdef HAVE_INT64_TIMESTAMP
29902993
*fsec += rint((val + fval) * 1000);
29912994
#else

src/include/utils/timestamp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.80 2009/06/11 14:49:13 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.81 2009/08/18 21:23:14 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -39,6 +39,8 @@
3939
* TimeOffset and fsec_t are convenience typedefs for temporary variables
4040
* that are of different types in the two cases. Do not use fsec_t in values
4141
* stored on-disk, since it is not the same size in both implementations.
42+
* Also, fsec_t is only meant for *fractional* seconds; beware of overflow
43+
* if the value you need to store could be many seconds.
4244
*/
4345

4446
#ifdef HAVE_INT64_TIMESTAMP

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy