From 2d987e725f30a81ddc5719ddfb5be0c0e799b572 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 26 Sep 2025 17:08:00 -0400 Subject: [PATCH] parse_date: handle dates in 2038 and beyond if time_t is big enough --- libarchive/archive_parse_date.c | 4 +--- libarchive/test/test_archive_parse_date.c | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libarchive/archive_parse_date.c b/libarchive/archive_parse_date.c index cda0b11a5..d9e968387 100644 --- a/libarchive/archive_parse_date.c +++ b/libarchive/archive_parse_date.c @@ -703,9 +703,7 @@ Convert(time_t Month, time_t Day, time_t Year, Year += 1900; DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 29 : 28; - /* Checking for 2038 bogusly assumes that time_t is 32 bits. But - I'm too lazy to try to check for time_t overflow in another way. */ - if (Year < EPOCH || Year >= 2038 + if (Year < EPOCH || (sizeof(time_t) <= 4 && Year >= 2038) || Month < 1 || Month > 12 /* Lint fluff: "conversion from long may lose accuracy" */ || Day < 1 || Day > DaysInMonth[(int)--Month] diff --git a/libarchive/test/test_archive_parse_date.c b/libarchive/test/test_archive_parse_date.c index 0a70971b1..5251b3393 100644 --- a/libarchive/test/test_archive_parse_date.c +++ b/libarchive/test/test_archive_parse_date.c @@ -39,6 +39,8 @@ DEFINE_TEST(test_archive_parse_date) assertEqualInt(get_date(now, "Jan 1, 1970 UTC"), 0); assertEqualInt(get_date(now, "7:12:18-0530 4 May 1983"), 420900138); assertEqualInt(get_date(now, "2004/01/29 513 mest"), 1075345980); + assertEqualInt(get_date(now, "2038-06-01 00:01:02 UTC"), + sizeof(time_t) <= 4 ? -1 : 2158963262); assertEqualInt(get_date(now, "99/02/17 7pm utc"), 919278000); assertEqualInt(get_date(now, "02/17/99 7:11am est"), 919253460); assertEqualInt(get_date(now, "now - 2 hours"), -- 2.47.3