libstdc++: Prevent overflow in to_local conversion for timezone rules.
Fixes timezone conversion overflow that caused incorrect rule activation.
This change prevents an integer overflow in the to_local conversion function within libstdc++’s timezone database handling. Previously, adjusting the minimum or maximum system seconds for rules without activation could lead to overflow and undefined behavior, causing invalid rules to be considered active. The fix ensures that minimum and maximum values are constructed directly from time since epoch, resolving incorrect rule activation and ensuring timezone transitions are applied correctly, particularly for zones specified with UNTIL clauses.
In Details
This commit fixes a bug in libstdc++'s timezone handling, specifically in find_active_rule::to_local. Adjusting sys_seconds to std_offset for edge-case Transitions::Entries (e.g., empty rules) could overflow when sys_seconds was at its minimum or maximum. This led to next.when being an erroneously low value, triggering incorrect rule activation. The fix ensures that for these edge cases, local_seconds are constructed directly from time_since_epoch, preserving the min/max values without modification.
- timezone database
- A system-level data store that maps geographical regions to their historical and current timekeeping rules, including standard time, daylight saving time, and offsets from UTC.
- sys_seconds
- A type, likely representing seconds since the Unix epoch, used internally by the C++20 <chrono> library for timezone calculations.
- std_offset
- The offset from Coordinated Universal Time (UTC) that is applied for a given timezone and time, often including daylight saving time adjustments.
- to_local
- A function or method within the timezone library that converts a universal time (UTC) into a local time, accounting for the relevant timezone rules and offsets.
- UNTIL clause
- A directive within timezone data files that specifies a future point in time after which a particular set of timezone rules (e.g., a specific UTC offset or DST rule) will no longer be in effect.