Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f19bl-0002Dt-T6 for pgsql-admin@arkaria.postgresql.org; Wed, 28 Mar 2018 11:51:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f19bk-00014N-1q for pgsql-admin@arkaria.postgresql.org; Wed, 28 Mar 2018 11:51:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f19bj-00014D-NT for pgsql-admin@lists.postgresql.org; Wed, 28 Mar 2018 11:51:11 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f19bc-0003S8-08 for pgsql-admin@postgresql.org; Wed, 28 Mar 2018 11:51:10 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id D9BCF42BF4; Wed, 28 Mar 2018 13:50:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id DjXF6HAyHhMH; Wed, 28 Mar 2018 13:50:48 +0200 (CEST) Message-ID: <1522237846.2820.26.camel@cybertec.at> Subject: Re: Strange timezone 'math' in 9.6.8 From: Laurenz Albe To: Ervin Weber , pgsql-admin Date: Wed, 28 Mar 2018 13:50:46 +0200 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ervin Weber wrote: > Seems that PostgreSQL does do math inside invalid time zone names, > without reporting any errors to client if time zone name has sign and > number inside range. > > staging=# show server_version; > server_version > ---------------- > 9.6.8 > (1 row) > > staging=# select now(), now() at time zone 'fubar+167'; > now | timezone > -------------------------------+---------------------------- > 2018-03-28 09:16:25.897444+00 | 2018-03-21 10:16:25.897444 > (1 row) > > staging=# select now(), now() at time zone 'fubar+168'; > ERROR: time zone "fubar+168" not recognized The cause of the error is the following code in src/timezone/localtime.c, in function "getsecs": /* * Given a pointer into a time zone string, extract a number of seconds, * in hh[:mm[:ss]] form, from the string. * If any error occurs, return NULL. * Otherwise, return a pointer to the first character not part of the number * of seconds. */ static const char * getsecs(const char *strp, int32 *secsp) { int num; /* * 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like * "M10.4.6/26", which does not conform to Posix, but which specifies the * equivalent of "02:00 on the first Sunday on or after 23 Oct". */ strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1); if (strp == NULL) return NULL; So any time zone offset that is one week or more fails. The seemingly arbitrary limit is explained by the comment; the code serves several purposes. One could argue that time zones offsets beyound 12 or 24 hours should cause an error, but apart from that the behavior is correct, right? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com