Thanks for installing the fix.

> I didn't see use of uninitialized transition times in the unpatched
> code. Can you give a scenario when that happened?

It needs 32-bit time_t (I used -Dtime_tz=int32_t) and a TZif file
whose version 2+ data has these three transitions, out of order:

  -2**40, 2**40, -2**40 + 1   (types 0, 1, 2)

In the first loop of tzloadbody at 48e83594:

  i = 0: -2**40 is kept, clamped to TIME_T_MIN: types[0] = 1,
         ats[0] = TIME_T_MIN, timecnt = 1.
  i = 1: 2**40 > TIME_T_MAX is discarded: types[1] = 0.
  i = 2: -2**40 + 1 is kept, also clamped to TIME_T_MIN.  As it
         equals ats[0], it is taken to replace the last kept
         transition, but the code clears types[i - 1], which is
         types[1] (already 0), not types[0].  ats[0] is rewritten
         and timecnt stays 1.

So types[0] and types[2] both remain 1, and the second loop sets
sp->timecnt to 2, though only sp->ats[0] was ever stored.  Lookups
then read sp->ats[1] in localsub's binary search, e.g. localtime_rz
with t = 0.  With tzalloc (or ALL_STATE) that slot is uninitialized
heap memory, and MSan reports use-of-uninitialized-value in
localsub; otherwise it holds zero or whatever an earlier load left
there.  The local time then depends on that value: in my ASan
build, t = 0 came out in type 2.  With 64-bit time_t the same file
is rejected, since 2**40 is kept and -2**40 + 1 then compares as
out of order.

With your 9fb2c56f the file is rejected with 32-bit time_t too; my
test of it now passes with 32- and 64-bit time_t, under ASan, UBSan
and MSan, and also with -DMIN_TRANSITION_GAP=1.

Ana

Reply via email to