diff --git a/NEWS b/NEWS index 7ce61b05650..d77f4ed4656 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ PHP NEWS - Core: . Fixed bug #76946 (Cyclic reference in generator not detected). (Nikita) +- Date: + . Fixed bug #75851 (Year component overflow with date formats "c", "o", "r" + and "y"). (Adam Saponara) + - FCGI: . Fixed bug #76948 (Failed shutdown/reboot or end session in Windows). (Anatol) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 955b7e9197e..8f376dfce4f 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1144,7 +1144,7 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t length = slprintf(buffer, sizeof(buffer), "%02d", (int) isoweek); break; /* iso weeknr */ case 'o': if(!weekYearSet) { timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 1; } - length = slprintf(buffer, sizeof(buffer), "%d", (int) isoyear); break; /* iso year */ + length = slprintf(buffer, sizeof(buffer), ZEND_LONG_FMT, (zend_long) isoyear); break; /* iso year */ /* month */ case 'F': length = slprintf(buffer, sizeof(buffer), "%s", mon_full_names[t->m - 1]); break; @@ -1155,7 +1155,7 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t /* year */ case 'L': length = slprintf(buffer, sizeof(buffer), "%d", timelib_is_leap((int) t->y)); break; - case 'y': length = slprintf(buffer, sizeof(buffer), "%02d", (int) t->y % 100); break; + case 'y': length = slprintf(buffer, sizeof(buffer), "%02d", (int) (t->y % 100)); break; case 'Y': length = slprintf(buffer, sizeof(buffer), "%s%04lld", t->y < 0 ? "-" : "", php_date_llabs((timelib_sll) t->y)); break; /* time */ @@ -1214,18 +1214,18 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t case 'Z': length = slprintf(buffer, sizeof(buffer), "%d", localtime ? offset->offset : 0); break; /* full date/time */ - case 'c': length = slprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d", - (int) t->y, (int) t->m, (int) t->d, + case 'c': length = slprintf(buffer, sizeof(buffer), "%04" ZEND_LONG_FMT_SPEC "-%02d-%02dT%02d:%02d:%02d%c%02d:%02d", + (zend_long) t->y, (int) t->m, (int) t->d, (int) t->h, (int) t->i, (int) t->s, localtime ? ((offset->offset < 0) ? '-' : '+') : '+', localtime ? abs(offset->offset / 3600) : 0, localtime ? abs((offset->offset % 3600) / 60) : 0 ); break; - case 'r': length = slprintf(buffer, sizeof(buffer), "%3s, %02d %3s %04d %02d:%02d:%02d %c%02d%02d", + case 'r': length = slprintf(buffer, sizeof(buffer), "%3s, %02d %3s %04" ZEND_LONG_FMT_SPEC " %02d:%02d:%02d %c%02d%02d", php_date_short_day_name(t->y, t->m, t->d), (int) t->d, mon_short_names[t->m - 1], - (int) t->y, (int) t->h, (int) t->i, (int) t->s, + (zend_long) t->y, (int) t->h, (int) t->i, (int) t->s, localtime ? ((offset->offset < 0) ? '-' : '+') : '+', localtime ? abs(offset->offset / 3600) : 0, localtime ? abs((offset->offset % 3600) / 60) : 0 diff --git a/ext/date/tests/big_year.phpt b/ext/date/tests/big_year.phpt index a15a093de04..1cfc5af3dd0 100644 --- a/ext/date/tests/big_year.phpt +++ b/ext/date/tests/big_year.phpt @@ -13,5 +13,5 @@ var_dump(date("r", $t)); echo "OK\n"; ?> --EXPECT-- -string(36) "Fri, 01 Jan 219250468 00:00:00 -0500" +string(39) "Fri, 01 Jan 292277026596 00:00:00 -0500" OK diff --git a/ext/date/tests/bug75851.phpt b/ext/date/tests/bug75851.phpt new file mode 100644 index 00000000000..59bdb054ff3 --- /dev/null +++ b/ext/date/tests/bug75851.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test for bug #75851: Year component overflow with date formats "c", "o", "r" and "y" +--SKIPIF-- + +--INI-- +date.timezone = UTC +--FILE-- + +--EXPECT-- +-292277022657-01-27T08:29:52+00:00 +Fri, 27 Jan -292277022657 08:29:52 +0000 +-292277022657-01-27T08:29:52+00:00 +Fri, 27 Jan -292277022657 08:29:52 +0000 +-292277022657 +-57 +-292277022657 +-9223372036854775808 + +2147483647-12-31T23:59:59+00:00 +Tue, 31 Dec 2147483647 23:59:59 +0000 +2147483647-12-31T23:59:59+00:00 +Tue, 31 Dec 2147483647 23:59:59 +0000 +2147483648 +47 +2147483647 +67767976233532799 + +2147483648-01-01T00:00:00+00:00 +Wed, 01 Jan 2147483648 00:00:00 +0000 +2147483648-01-01T00:00:00+00:00 +Wed, 01 Jan 2147483648 00:00:00 +0000 +2147483648 +48 +2147483648 +67767976233532800 + +292277026596-12-04T15:30:07+00:00 +Sun, 04 Dec 292277026596 15:30:07 +0000 +292277026596-12-04T15:30:07+00:00 +Sun, 04 Dec 292277026596 15:30:07 +0000 +292277026596 +96 +292277026596 +9223372036854775807