summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-10-08 11:49:56 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-10-08 11:50:37 +0200
commit1b97f291a726480bc1db8b7a06a55663f316ded5 (patch)
tree5e29f81e29969896e81607b331887b3ed3950baa
parent608b48e5f4c255aa282562416c4e35b83d124789 (diff)
parentc097acd52e89a3b1d0cb6a181bb4650be9625b6c (diff)
downloadphp-git-1b97f291a726480bc1db8b7a06a55663f316ded5.tar.gz
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix #75851: Year component overflow with date formats "c", "o", "r" and "y"
-rw-r--r--NEWS4
-rw-r--r--ext/date/php_date.c12
-rw-r--r--ext/date/tests/big_year.phpt2
-rw-r--r--ext/date/tests/bug75851.phpt49
4 files changed, 60 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 82c250ef2f..1776413bf2 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ PHP NEWS
(Nikita)
. 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 #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 a60422b6a6..1e136e00b6 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1147,7 +1147,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;
@@ -1158,7 +1158,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 */
@@ -1217,18 +1217,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 a15a093de0..1cfc5af3dd 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 0000000000..59bdb054ff
--- /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--
+<?php echo PHP_INT_SIZE != 8 ? "skip 64-bit only" : "OK"; ?>
+--INI--
+date.timezone = UTC
+--FILE--
+<?php
+echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", PHP_INT_MIN);
+echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", 67767976233532799);
+echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", 67767976233532800);
+echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", PHP_INT_MAX);
+?>
+--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