Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 229e13b0c68f03fde697a4aa8cc7665b47e12a0f0a9133f6e3c4ac5b044b0a87
Ticket: 832d098fdfec8f004cf1c8e8836f7c335da12d54
Clock reads TZif version 3 and 4 zoneinfo files as version 1 - zones with an extended footer lose all their transitions
User & Date: kenneth.kienle on 2026-09-08 05:57:17
Changes

  1. icomment:
    There is a branch for this on bug-832d098fdf-8.6, off core-8-6-branch.
    
    How this came up, since it explains the odd configuration: I build and test
    Tcl 8.6 against the system's tzdata rather than the bundled copy. That
    surfaced this issue, and a default build does not show it.
    
    The reader used the 64-bit block and the footer only when the version byte was
    exactly "2". RFC 9636 section 3.1 defines '2', '3' and '4' as each conforming
    to the one before, and section 4 says a reader should use the version 1 block
    only to skip over it. With tzdata 2026c, 12 of 598 zones are version 3:
    
        zic -b slim -d zi africa antarctica asia australasia europe \
            northamerica southamerica etcetera backward factory
        for f in $(find zi -type f); do
            [ "$(head -c5 $f | tail -c1)" = 3 ] && echo $f
        done
    
      Asia/Jerusalem, Asia/Tel_Aviv, Israel, Asia/Gaza, Asia/Hebron,
      America/Santiago, Chile/Continental, Chile/EasterIsland, Pacific/Easter,
      America/Godthab, America/Nuuk, America/Scoresbysund
    
    When this is reachable matters. SetupTimeZone reads the bundled tzdata first,
    so a default build is not affected. It affects builds made with --with-
    tzdata=no, zones that are not in the bundled copy, and TZif files read
    directly.
    
    Stock 8.6, no bundled tzdata, reading the real slim Asia/Jerusalem:
    
        @1700000000 -> '+0000 '        (UTC, empty abbreviation)
        patched     -> '+0200 IST'     (glibc agrees)
    
    With fat data the reader falls back to the 32-bit block instead, which cannot
    hold a transition after 2038 and has no footer:
    
        America/Nuuk 2040-07-01   stock -0200   patched -0100   glibc -0100
        Asia/Gaza    2050-07-29   stock +0200   patched +0300   glibc +0300
    
    The scope is all 598 zones from a slim build, at 12 instants from 1938 to
    2084, through stock and patched: 144 of 7176 results differ, all of them
    inside those 12 zones. No other zone changes at any instant. On all 144,
    patched agrees with glibc and stock does not.
    
    Two further changes go with the footers that version 3 exists for. The
    transition hour now takes an optional sign and up to three digits, which
    covers the section 3.3.2 range of -167 to 167 (the pattern is a superset of
    it; no bound is enforced). Of the 598 zones in a slim 2026c build, three write
    a signed hour - America/Godthab, America/Nuuk and America/Scoresbysund, all
    /-1. None write a three-digit hour, so the sign is needed by data that exists
    today and the width is forward compatibility. And the sign applies to the
    whole time of day, not to the hours field alone, because [::scan -0 %d]
    returns 0 and loses it.
    
    The version test is [string is digit -strict $version] && $version >= 2. The
    -strict guard is not about version 1: a version 1 file has NUL in that byte,
    and both NUL and ASCII '1' already fail a bare >= 2. What it stops is any non-
    digit byte from 0x3a up, which Tcl's string comparison would otherwise accept
    - 198 byte values.
    
    Accepting version 4 is forward compatibility only. ReadZoneinfoFile refuses a
    file whose version 1 header declares leap seconds, and a zic-written version 4
    file has them, so in the fat case such a file does not reach the new branch.
    
    Tests clock-56.5 to 56.11 use synthetic TZif files and need neither system nor
    bundled tzdata. Reverting one mechanism at a time, measured:
    
        version check (either site)            fails 56.5, 56.6, 56.7
        signed / three-digit hour pattern      fails 56.8, 56.9, 56.10, 56.11
        sign applied to the whole time of day  fails 56.10, 56.11
        sign taken from [::scan], not the text fails 56.11
    
    No test separates the two version-check sites from each other; reverting
    either one fails the same three.
    
    56.9 is deliberately absent from the third row. Its footer is M3.5.0/-1, with
    no minutes and no seconds, so `sign * (h * 3600)` and `(sign * h) * 3600` are
    the same number and the fixture cannot see which one the code computes. It is
    coverage for the hour pattern, which is the row it does appear in. I mention
    it because a reader who reverts by dropping the sign factor, rather than by
    restoring the old placement, will see 56.9 fail and conclude the table is
    wrong.
    
    If you check the fixtures with another tool they contain no transitions, and
    glibc ignores a footer in that case, so `TZ=:<file> date` will disagree. RFC
    9636 section 3.2 says the footer governs when there are no transitions. The
    expected values were computed with glibc from each footer's TZ string instead.
    
    One issue I found next to this and did not touch (it is separate and already
    reachable without this change) is that the leap-second refusal above reads the
    VERSION 1 header, and zic -b slim writes that block empty, so a slim file with
    leap seconds passes the guard. The footer seek then uses `8 * $nLeap`, but
    leap records in the 64-bit block are 12 bytes, so the footer is read from the
    wrong offset. Measured on a zic -b slim -L leapseconds build of 2026c:
    
        Europe/Berlin (version 2, 27 leap records)
            stock 8.6 today -> error, "unable to parse time zone specification"
    
    This is not caused by this branch, but this branch does make it reachable for
    the 12 version 3 zones, which go from silently wrong to that same error:
    
        Asia/Jerusalem  stock '+0000 '  ->  patched: the parse error
        America/Nuuk    stock '+0000 '  ->  patched: the parse error
    
    Changing `8 * $nLeap` to `12 * $nLeap` makes all three correct and agree with
    glibc on offset and abbreviation. I have kept it out of this branch to keep
    things in scope. I'm happy to file it separately or to add it here, I just
    didn't want it to be a surprise.
    
    This is still open on trunk: library/clock.tcl there has the same $version eq
    "2" test and the same two-digit hour pattern.
    
    Kenneth
    
  2. login: "kenneth.kienle"
  3. mimetype: "text/x-markdown"