]> granicus.if.org Git - php/commitdiff
Phar: Avoid negative zip dates
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 19 Jun 2019 12:56:11 +0000 (14:56 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 19 Jun 2019 13:09:00 +0000 (15:09 +0200)
The zip date/time encoding format is incredibly stupid.

ext/phar/zip.c

index 3669bd059d49939dd3eed23515064d759777d004..3d2256536ddd732818d35a71fc563215a7ffaede 100644 (file)
@@ -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);
 }