GNU bug report logs - #79437
30.2; world-clock silently and incorrectly parses invalid time zone

Previous Next

Package: emacs;

Reported by: "Jorge P. de Morais Neto" <jorge+git <at> disr.it>

Date: Fri, 12 Sep 2025 16:06:03 UTC

Severity: normal

Found in version 30.2

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 79437 <at> debbugs.gnu.org, "Jorge P. de Morais Neto" <jorge+git <at> disr.it>
Subject: bug#79437: 30.2; world-clock silently and incorrectly parses invalid time zone
Date: Sun, 14 Sep 2025 10:30:37 -0700
[Message part 1 (text/plain, inline)]
On 2025-09-13 22:24, Eli Zaretskii wrote:

> Only the second one can be checked relatively easily by looking in the
> directory where the zoneinfo files are installed.  But how does one
> validate the other 2 forms?  And how does one know which format iz
> used to begin with?

Plus, not every TZDB installation has "zoneinfo files" in the usual 
sense; some have a database using some other format.

However, something along those lines could be done, if somebody wanted 
to maintain it (I don't). The idea is not to exactly validate the forms; 
instead, do a reasonably conservative validation that rejects forms that 
(as as we know) are not supported on any Emacs platform. This would 
accept some unlikely mistakes, but would be good enough for most users.

Something like the following, perhaps, and then have world-clock-display 
run (world-clock--check-entries alist) first thing.

None of this is tested; it's just a sketch. And I'm not advocating for 
this change as it's hacky and I would rather not support it, but if 
somebody else wants to take it up it should work acceptably.

  (defconst world-clock--tz-regexp
    (let* ((abbr "\\([A-Za-z]\\{3,\\}\|<[A-Za-z0-9+-]\\{3,\\}>\\)")
           (offset "\\([+-]?[0-9]+\\(:[0-5][0-9]\\(:[0-5][0-9]\\)?\\)?\\)")
           (date "\\(J?[0-9]+\\|M\\([1-9]\\|1[0-2]\\)\\.[1-5]\\.[0-6]\\)")
           (time offset)
           (comma-date-time (concat "," date "\\(/" time "\\)?"))

           ;; TZDB time zones at UTC offset zero at the Epoch.
           ;; The others are filtered out by the call to current-time-zone.
           ;; This list is for circa 2025 TZDB and may need updating.
           (tzdb+0000-regexp
 
"\\(Africa/\\(Abidjan\\|Accra\\|Bamako\\|Banjul\\|Bissau\\|Conakry"
            "" "\\|Dakar\\|Freetown\\|Lome\\|Monrovia\\|Nouakchott"
            "" "\\|Ouagadougou\\|Sao_Tome\\|Timbuktu\\)"
            "\\|America/Danmarkshavn"
            "\\|Atlantic/\\(Azores\\|Reykjavik\\|St_Helena\\)"
            "\\|\\(Etc/\\)?\\(GMT[+-]?0\\|Greenwich\\|UCT\\|UTC"
            "" "\\|Universal\\|Zulu\\)"
            "\\|Iceland")

           ;; POSIX.1-2017 (and earlier) TZ strings.
           (posix-tz-regexp
            (concat "\\(" abbr offset
                    "\\(" abbr offset
                    "?\\(" comma-date-time comma-date-time
                    "\\)?\\)?\\)")))
      (concat "\\`:?\\(" tzdb+0000-regexp
              "\\|" posix-tz-regexp "\\)\\'")))

  (defun world-clock--check-entries (alist)
    (dolist (pair alist)
      (let ((tz (car pair)))
        (unless (string-match-p world-clock--tz-regexp tz)
          (when (zerop (car (current-time-zone 0 tz)))
            (error "Invalid time zone specification" tz))))))

PS. I noticed some other glitches in this area and installed the 
attached patch on master. It's a pain to maintain this stuff!
[0001-Fix-incorrect-timezones-for-London-and-Paris.patch (text/x-patch, attachment)]

This bug report was last modified 4 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.