Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cd0ff9c

Browse files
committed
Expand the allowed range of timezone offsets to +/-15:59:59 from Greenwich.
We used to only allow offsets less than +/-13 hours, then it was +/14, then it was +/-15. That's still not good enough though, as per today's bug report from Patric Bechtel. This time I actually looked through the Olson timezone database to find the largest offsets used anywhere. The winners are Asia/Manila, at -15:56:00 until 1844, and America/Metlakatla, at +15:13:42 until 1867. So we'd better allow offsets less than +/-16 hours. Given the history, we are way overdue to have some greppable #define symbols controlling this, so make some ... and also remove an obsolete comment that didn't get fixed the last time. Back-patch to all supported branches.
1 parent 07ab138 commit cd0ff9c

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/backend/utils/adt/date.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1956,9 +1956,8 @@ timetz_recv(PG_FUNCTION_ARGS)
19561956

19571957
result->zone = pq_getmsgint(buf, sizeof(result->zone));
19581958

1959-
/* we allow GMT displacements up to 14:59:59, cf DecodeTimezone() */
1960-
if (result->zone <= -15 * SECS_PER_HOUR ||
1961-
result->zone >= 15 * SECS_PER_HOUR)
1959+
/* Check for sane GMT displacement; see notes in datatype/timestamp.h */
1960+
if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
19621961
ereport(ERROR,
19631962
(errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE),
19641963
errmsg("time zone displacement out of range")));

src/backend/utils/adt/datetime.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -2698,9 +2698,6 @@ DecodeNumberField(int len, char *str, int fmask,
26982698
* Return 0 if okay (and set *tzp), a DTERR code if not okay.
26992699
*
27002700
* NB: this must *not* ereport on failure; see commands/variable.c.
2701-
*
2702-
* Note: we allow timezone offsets up to 13:59. There are places that
2703-
* use +1300 summer time.
27042701
*/
27052702
static int
27062703
DecodeTimezone(char *str, int *tzp)
@@ -2745,7 +2742,8 @@ DecodeTimezone(char *str, int *tzp)
27452742
else
27462743
min = 0;
27472744

2748-
if (hr < 0 || hr > 14)
2745+
/* Range-check the values; see notes in datatype/timestamp.h */
2746+
if (hr < 0 || hr > MAX_TZDISP_HOUR)
27492747
return DTERR_TZDISP_OVERFLOW;
27502748
if (min < 0 || min >= MINS_PER_HOUR)
27512749
return DTERR_TZDISP_OVERFLOW;

src/include/datatype/timestamp.h

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ typedef struct
105105
#define USECS_PER_MINUTE INT64CONST(60000000)
106106
#define USECS_PER_SEC INT64CONST(1000000)
107107

108+
/*
109+
* We allow numeric timezone offsets up to 15:59:59 either way from Greenwich.
110+
* Currently, the record holders for wackiest offsets in actual use are zones
111+
* Asia/Manila, at -15:56:00 until 1844, and America/Metlakatla, at +15:13:42
112+
* until 1867. If we were to reject such values we would fail to dump and
113+
* restore old timestamptz values with these zone settings.
114+
*/
115+
#define MAX_TZDISP_HOUR 15 /* maximum allowed hour part */
116+
#define TZDISP_LIMIT ((MAX_TZDISP_HOUR + 1) * SECS_PER_HOUR)
117+
108118
/*
109119
* DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity
110120
*/

0 commit comments

Comments
 (0)