Skip to content

Commit b1196e2

Browse files
committed
Phar: Avoid negative zip dates
The zip date/time encoding format is incredibly stupid.
1 parent 7bf6326 commit b1196e2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ext/phar/zip.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,15 @@ static void phar_zip_u2d_time(time_t time, char *dtime, char *ddate) /* {{{ */
147147
struct tm *tm, tmbuf;
148148

149149
tm = php_localtime_r(&time, &tmbuf);
150-
cdate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday;
151-
ctime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1);
150+
if (tm->tm_year >= 1980) {
151+
cdate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday;
152+
ctime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1);
153+
} else {
154+
/* This is the earliest date/time supported by zip. */
155+
cdate = (1<<5) + 1; /* 1980-01-01 */
156+
ctime = 0; /* 00:00:00 */
157+
}
158+
152159
PHAR_SET_16(dtime, ctime);
153160
PHAR_SET_16(ddate, cdate);
154161
}

0 commit comments

Comments
 (0)