Skip to content

Commit e68f60b

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #75851: Year component overflow with date formats "c", "o", "r" and "y"
2 parents 484b79e + 1b97f29 commit e68f60b

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug #76979 (define() error message does not mention resources as
1717
valid values). (Michael Moravec)
1818

19+
- Date:
20+
. Fixed bug #75851 (Year component overflow with date formats "c", "o", "r"
21+
and "y"). (Adam Saponara)
22+
1923
- FCGI:
2024
. Fixed #76948 (Failed shutdown/reboot or end session in Windows). (Anatol)
2125

ext/date/php_date.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t
11651165
length = slprintf(buffer, sizeof(buffer), "%02d", (int) isoweek); break; /* iso weeknr */
11661166
case 'o':
11671167
if(!weekYearSet) { timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 1; }
1168-
length = slprintf(buffer, sizeof(buffer), "%d", (int) isoyear); break; /* iso year */
1168+
length = slprintf(buffer, sizeof(buffer), ZEND_LONG_FMT, (zend_long) isoyear); break; /* iso year */
11691169

11701170
/* month */
11711171
case 'F': length = slprintf(buffer, sizeof(buffer), "%s", mon_full_names[t->m - 1]); break;
@@ -1176,7 +1176,7 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t
11761176

11771177
/* year */
11781178
case 'L': length = slprintf(buffer, sizeof(buffer), "%d", timelib_is_leap((int) t->y)); break;
1179-
case 'y': length = slprintf(buffer, sizeof(buffer), "%02d", (int) t->y % 100); break;
1179+
case 'y': length = slprintf(buffer, sizeof(buffer), "%02d", (int) (t->y % 100)); break;
11801180
case 'Y': length = slprintf(buffer, sizeof(buffer), "%s%04lld", t->y < 0 ? "-" : "", php_date_llabs((timelib_sll) t->y)); break;
11811181

11821182
/* time */
@@ -1235,18 +1235,18 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t
12351235
case 'Z': length = slprintf(buffer, sizeof(buffer), "%d", localtime ? offset->offset : 0); break;
12361236

12371237
/* full date/time */
1238-
case 'c': length = slprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
1239-
(int) t->y, (int) t->m, (int) t->d,
1238+
case 'c': length = slprintf(buffer, sizeof(buffer), "%04" ZEND_LONG_FMT_SPEC "-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
1239+
(zend_long) t->y, (int) t->m, (int) t->d,
12401240
(int) t->h, (int) t->i, (int) t->s,
12411241
localtime ? ((offset->offset < 0) ? '-' : '+') : '+',
12421242
localtime ? abs(offset->offset / 3600) : 0,
12431243
localtime ? abs((offset->offset % 3600) / 60) : 0
12441244
);
12451245
break;
1246-
case 'r': length = slprintf(buffer, sizeof(buffer), "%3s, %02d %3s %04d %02d:%02d:%02d %c%02d%02d",
1246+
case 'r': length = slprintf(buffer, sizeof(buffer), "%3s, %02d %3s %04" ZEND_LONG_FMT_SPEC " %02d:%02d:%02d %c%02d%02d",
12471247
php_date_short_day_name(t->y, t->m, t->d),
12481248
(int) t->d, mon_short_names[t->m - 1],
1249-
(int) t->y, (int) t->h, (int) t->i, (int) t->s,
1249+
(zend_long) t->y, (int) t->h, (int) t->i, (int) t->s,
12501250
localtime ? ((offset->offset < 0) ? '-' : '+') : '+',
12511251
localtime ? abs(offset->offset / 3600) : 0,
12521252
localtime ? abs((offset->offset % 3600) / 60) : 0

ext/date/tests/big_year.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ var_dump(date("r", $t));
1313
echo "OK\n";
1414
?>
1515
--EXPECT--
16-
string(36) "Fri, 01 Jan 219250468 00:00:00 -0500"
16+
string(39) "Fri, 01 Jan 292277026596 00:00:00 -0500"
1717
OK

ext/date/tests/bug75851.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Test for bug #75851: Year component overflow with date formats "c", "o", "r" and "y"
3+
--SKIPIF--
4+
<?php echo PHP_INT_SIZE != 8 ? "skip 64-bit only" : "OK"; ?>
5+
--INI--
6+
date.timezone = UTC
7+
--FILE--
8+
<?php
9+
echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", PHP_INT_MIN);
10+
echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", 67767976233532799);
11+
echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", 67767976233532800);
12+
echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", PHP_INT_MAX);
13+
?>
14+
--EXPECT--
15+
-292277022657-01-27T08:29:52+00:00
16+
Fri, 27 Jan -292277022657 08:29:52 +0000
17+
-292277022657-01-27T08:29:52+00:00
18+
Fri, 27 Jan -292277022657 08:29:52 +0000
19+
-292277022657
20+
-57
21+
-292277022657
22+
-9223372036854775808
23+
24+
2147483647-12-31T23:59:59+00:00
25+
Tue, 31 Dec 2147483647 23:59:59 +0000
26+
2147483647-12-31T23:59:59+00:00
27+
Tue, 31 Dec 2147483647 23:59:59 +0000
28+
2147483648
29+
47
30+
2147483647
31+
67767976233532799
32+
33+
2147483648-01-01T00:00:00+00:00
34+
Wed, 01 Jan 2147483648 00:00:00 +0000
35+
2147483648-01-01T00:00:00+00:00
36+
Wed, 01 Jan 2147483648 00:00:00 +0000
37+
2147483648
38+
48
39+
2147483648
40+
67767976233532800
41+
42+
292277026596-12-04T15:30:07+00:00
43+
Sun, 04 Dec 292277026596 15:30:07 +0000
44+
292277026596-12-04T15:30:07+00:00
45+
Sun, 04 Dec 292277026596 15:30:07 +0000
46+
292277026596
47+
96
48+
292277026596
49+
9223372036854775807

0 commit comments

Comments
 (0)