com php-src: Phar: Avoid negative zip dates: ext/phar/zip.c
| From: | Nikita Popov | Date: | Wed, 19 Jun 2019 13:09:00 +0000 |
| Subject: | com php-src: Phar: Avoid negative zip dates: ext/phar/zip.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106888@lists.php.net to get a copy of this message | ||
Commit: b1196e2128cf3b1b53b604e3d7f89973fa23ec2d
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 19 Jun 2019 14:56:11 +0200
Parents: 7bf6326259a57cda44345369d4b02ff66d1376b8
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b1196e2128cf3b1b53b604e3d7f89973fa23ec2d
Log:
Phar: Avoid negative zip dates
The zip date/time encoding format is incredibly stupid.
Changed paths:
M ext/phar/zip.c
Diff:
diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index 3669bd0..3d22565 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);
}