diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-19 14:56:11 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-19 15:09:00 +0200 |
commit | b1196e2128cf3b1b53b604e3d7f89973fa23ec2d (patch) | |
tree | bca51d6a3ad8bf1e473baf703809c6531b25dea4 /ext/phar | |
parent | 7bf6326259a57cda44345369d4b02ff66d1376b8 (diff) | |
download | php-git-b1196e2128cf3b1b53b604e3d7f89973fa23ec2d.tar.gz |
Phar: Avoid negative zip dates
The zip date/time encoding format is incredibly stupid.
Diffstat (limited to 'ext/phar')
-rw-r--r-- | ext/phar/zip.c | 11 |
1 files 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); } |