Hi,

I found a bug in `zic.c` and would like to propose a fix. Please see the
attached file.

Best regards,
Dmitry Khalanskiy.
From 622d11fdb9dfc0b02e3db1a68a12020018dc4778 Mon Sep 17 00:00:00 2001
From: Dmitry Khalanskiy <[email protected]>
Date: Mon, 2 Nov 2026 10:48:06 +0100
Subject: [PATCH] Fix reading uninitialized data

When the `-r` specifies a high bound,
`outzone` omits a rule string and instead emits a fake
transition 402 after the last actually observed one.

If there were no recorded transitions, the fake transition
may or may not get created, as this depends on the state of
memory that does not get cleaned after processing earlier
time zones.

Specifically, `lastat` gets set to `attypes`, which is a
non-`null` pointer, so the check `!lastat` always fails,
leading to the read of `lastat->at` and executing logic based on
the values within.

To reproduce the uninitialized read, run with the arguments
`-r /@12717475200 tzdata.zi` and read the compiled `Etc/UTC`.
It should include the fake transition, since `2373-01-01` is
exactly 402 years after the last recorded transition
(`1970-01-01`), but it does not.
---
 zic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/zic.c b/zic.c
index cd0dcac2..a93be126 100644
--- a/zic.c
+++ b/zic.c
@@ -3733,7 +3733,7 @@ outzone(const struct zone *zpfirst, ptrdiff_t zonecount)
 		for (lastat = attypes, i = 1; i < timecnt; i++)
 			if (attypes[i].at > lastat->at)
 				lastat = &attypes[i];
-		if (!lastat || lastat->at < rpytime(&xr, max_year - 1)) {
+		if (0 == timecnt || lastat->at < rpytime(&xr, max_year - 1)) {
 			addtt(rpytime(&xr, max_year + 1),
 			      lastat ? lastat->type : defaulttype);
 			attypes[timecnt - 1].dontmerge = true;
-- 
2.54.0

Reply via email to