From b1196e2128cf3b1b53b604e3d7f89973fa23ec2d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 19 Jun 2019 14:56:11 +0200 Subject: [PATCH] Phar: Avoid negative zip dates The zip date/time encoding format is incredibly stupid. --- ext/phar/zip.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 3669bd059d..3d2256536d 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -147,8 +147,15 @@ static void phar_zip_u2d_time(time_t time, char *dtime, char *ddate) /* {{{ */ struct tm *tm, tmbuf; tm = php_localtime_r(&time, &tmbuf); - cdate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday; - ctime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1); + if (tm->tm_year >= 1980) { + cdate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday; + ctime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1); + } else { + /* This is the earliest date/time supported by zip. */ + cdate = (1<<5) + 1; /* 1980-01-01 */ + ctime = 0; /* 00:00:00 */ + } + PHAR_SET_16(dtime, ctime); PHAR_SET_16(ddate, cdate); } -- 2.40.0