Reject extended zones whose transitions remain in negative unix time#357
Merged
Conversation
…zones
When a TZif file has all explicit transitions in the negative-epoch
range (<0) and includes a POSIX DST footer string, ExtendTransitions()
sets extended_ = true and generates 401 years of transitions. Load()
previously checked `if (last.unix_time < 0)` unconditionally and
appended a static sentinel transition at unix_time = 2147483647 (2038).
This corrupted the transition table and lookup behavior:
1. Lookups for modern dates (e.g., 1970–2038) in BreakTime() skipped
the `if (extended_)` branch because unix_time < 2147483647, matching
the negative-epoch static offset and returning standard time (EST)
instead of daylight saving time (EDT).
2. Far-future lookups (e.g., time_point<seconds>::max()) caused signed
integer overflow when computing `shift * kSecsPer400Years` and when
subtracting negative transition timestamps from large unix times.
This change:
- Guards the 2038 sentinel addition in TimeZoneInfo::Load() with
`if (!extended_)`, preserving the extended 400-year cycle transitions.
- Uses unsigned 64-bit subtraction in TimeZoneInfo::BreakTime() and
clamps `shift` to `seconds::max().count() / kSecsPer400Years`.
- Uses unsigned arithmetic in TimeZoneInfo::MakeTime() to safely
compute civil year differences when `last_year_` is negative.
- Adds unit test coverage in `time_zone_lookup_test.cc`.
devbww
reviewed
Jul 21, 2026
devbww
reviewed
Jul 22, 2026
Contributor
|
PS: It looks like the "This change" part of the PR description could now do with some re-wording. |
devbww
approved these changes
Jul 22, 2026
mkruskal-google
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a TZif file has explicit transitions ending before the epoch and
includes a POSIX DST footer string, ExtendTransitions() sets extended_ = true
and generates 401 years of transitions. Load() previously checked
if (last.unix_time < 0)unconditionally and appended a static sentineltransition at unix_time = 2147483647 (2038).
Appending a static transition to an extended zone table is incompatible with
the 400-year cycle shifting used for future lookups.
This change:
extended transitions fail to reach the non-negative unix time space
(
if (extended_) return false;). All valid zoneinfo files easily meetthis requirement.
preserving the generated 400-year cycle transition table.
last.unix_timeand
last_year_are non-negative, ensuring that 400-year cycle calculationsin BreakTime() and MakeTime() operate safely within bounds.
time_zone_lookup_test.ccto verify lookups forvalid zones with transitions before the epoch, and to confirm rejection of
zones whose extended transitions fail to reach non-negative unix time.