From cd8e42fd81c42cf66924a2d6e5aa16e701757353 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 13 Oct 2022 23:33:55 -0700
Subject: [PROPOSED] Fix Y2438 bug when reading fat TZif files

Problem reported by Bradley White in:
https://mm.icann.org/pipermail/tz/2022-October/032054.html
* NEWS: Mention this.
* localtime.c (typesequiv): Ignore tt_ttisstd and tt_ttisut.
---
 NEWS        | 17 +++++++++++++++++
 localtime.c |  6 ++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index bce987a2..a6f1f55c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,22 @@
 News for the tz database
 
+Unreleased, experimental changes
+
+  Briefly:
+    Fix a Y2438 bug when reading TZif data
+
+  Changes to code
+
+    Fix a bug that caused localtime to mishandle timestamps starting
+    in the year 2438 when reading data generated by 'zic -b fat' when
+    distant-future DST transitions occur at times given in standard
+    time or in UT, not the usual case of local time.  This occurs when
+    the corresponding .zi Rule lines specify DST transitions with TO
+    columns of 'max' and AT columns that end in 's' or 'u'.  The
+    number 2438 comes from the 32-bit limit in the year 2038, plus the
+    400-year Gregorian cycle.  (Problem reported by Bradley White.)
+
+
 Release 2022e - 2022-10-11 11:13:02 -0700
 
   Briefly:
diff --git a/localtime.c b/localtime.c
index 073b0966..0ad28dc6 100644
--- a/localtime.c
+++ b/localtime.c
@@ -802,12 +802,14 @@ typesequiv(const struct state *sp, int a, int b)
 		b < 0 || b >= sp->typecnt)
 			result = false;
 	else {
+		/* Compare the relevant members of *AP and *BP.
+		   Ignore tt_ttisstd and tt_ttisut, as they are
+		   irrelevant now and counting them could cause
+		   sp->goahead to mistakenly remain false.  */
 		register const struct ttinfo *	ap = &sp->ttis[a];
 		register const struct ttinfo *	bp = &sp->ttis[b];
 		result = (ap->tt_utoff == bp->tt_utoff
 			  && ap->tt_isdst == bp->tt_isdst
-			  && ap->tt_ttisstd == bp->tt_ttisstd
-			  && ap->tt_ttisut == bp->tt_ttisut
 			  && (strcmp(&sp->chars[ap->tt_desigidx],
 				     &sp->chars[bp->tt_desigidx])
 			      == 0));
-- 
2.34.1

