Skip to content

Commit 46a3f25

Browse files
committed
Fixed bug #62852 (Unserialize invalid DateTime causes crash)
1 parent 1a23d42 commit 46a3f25

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

ext/date/php_date.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,16 +2544,19 @@ static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dat
25442544
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
25452545
convert_to_long(*z_timezone_type);
25462546
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
2547+
zend_error_handling error_handling;
2548+
2549+
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
25472550
convert_to_string(*z_timezone);
25482551

25492552
switch (Z_LVAL_PP(z_timezone_type)) {
25502553
case TIMELIB_ZONETYPE_OFFSET:
25512554
case TIMELIB_ZONETYPE_ABBR: {
25522555
char *tmp = emalloc(Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 2);
25532556
snprintf(tmp, Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 2, "%s %s", Z_STRVAL_PP(z_date), Z_STRVAL_PP(z_timezone));
2554-
php_date_initialize(*dateobj, tmp, Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 1, NULL, NULL, 0 TSRMLS_CC);
2557+
php_date_initialize(*dateobj, tmp, Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 1, NULL, NULL, 1 TSRMLS_CC);
25552558
efree(tmp);
2556-
return 1;
2559+
break;
25572560
}
25582561

25592562
case TIMELIB_ZONETYPE_ID:
@@ -2567,10 +2570,15 @@ static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dat
25672570
tzobj->tzi.tz = tzi;
25682571
tzobj->initialized = 1;
25692572

2570-
php_date_initialize(*dateobj, Z_STRVAL_PP(z_date), Z_STRLEN_PP(z_date), NULL, tmp_obj, 0 TSRMLS_CC);
2573+
php_date_initialize(*dateobj, Z_STRVAL_PP(z_date), Z_STRLEN_PP(z_date), NULL, tmp_obj, 1 TSRMLS_CC);
25712574
zval_ptr_dtor(&tmp_obj);
2572-
return 1;
2575+
break;
2576+
default:
2577+
zend_restore_error_handling(&error_handling TSRMLS_CC);
2578+
return 0;
25732579
}
2580+
zend_restore_error_handling(&error_handling TSRMLS_CC);
2581+
return 1;
25742582
}
25752583
}
25762584
}

ext/date/tests/bug62852.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #62852 (Unserialize invalid DateTime causes crash)
3+
--INI--
4+
date.timezone=GMT
5+
--FILE--
6+
<?php
7+
try {
8+
$datetime = unserialize('O:8:"DateTime":3:{s:4:"date";s:20:"10007-06-07 03:51:49";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}');
9+
var_dump($datetime);
10+
} catch (Exception $e) {
11+
var_dump($e->getMessage());
12+
}
13+
?>
14+
--EXPECTF--
15+
string(%d) "DateTime::__wakeup(): Failed to parse time string (%s) at position 12 (0): Double time specification"

0 commit comments

Comments
 (0)