https://bugs.winehq.org/show_bug.cgi?id=50532
Bug ID: 50532 Summary: get_timezone_info doing binary search in the wrong way Product: Wine Version: 6.0-rc6 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: ntdll Assignee: wine-bugs@winehq.org Reporter: gmascellani@codeweavers.com Distribution: ---
get_timezone_info in dlls/ntdll/unix/system.c appears to compute the daylight saving time changes for a given year in a smelly if not buggy way. I don't have any specific examples of mistaken computations, but the code seems to basically work by chance.
More specifically, the indention of the code seems to be the following: * two time_t values are computed, corresponding to the beginning and the end of the requested year (year_start and year_end); * a binary search procedure is used to narrow down that interval around a DST change event.
However, this cannot work in general, because binary searches only work for monotonic data, and DST is not monotonic (each year it switches forth and back, assuming there is DST at all). The algorithm works "by chance", because it first tests the beginning of the interval and then half of the interval, and usually beginning of January and beginning of June are on different DST values; then the algorithm recurses on the first half of the year, and there DST is monotonic (again, usually; I don't know if this is always true).
Moreover, year_end is also set to an invalid value (0th day of 12th month, which is a month past December). Doing the "arithmetic" this corresponds to 31st of December, but is that a supported way to specify it? Why not directly setting 31st of December? Anyway, the core of this bug is the issue with binary search.