diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2018-10-08 11:51:54 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2018-10-08 11:52:37 +0200 |
commit | e68f60b087b49390b477844a3c5783849ba7d8c4 (patch) | |
tree | cce129d5359937d89ec7b0aaf1a221906d517982 /ext | |
parent | 484b79e868ca735adf54105a3154f866d8479022 (diff) | |
parent | 1b97f291a726480bc1db8b7a06a55663f316ded5 (diff) | |
download | php-git-e68f60b087b49390b477844a3c5783849ba7d8c4.tar.gz |
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"
Diffstat (limited to 'ext')
-rw-r--r-- | ext/date/php_date.c | 12 | ||||
-rw-r--r-- | ext/date/tests/big_year.phpt | 2 | ||||
-rw-r--r-- | ext/date/tests/bug75851.phpt | 49 |
3 files changed, 56 insertions, 7 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 59eb4f2a8d..c152c71d3d 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1165,7 +1165,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; @@ -1176,7 +1176,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 */ @@ -1235,18 +1235,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 |