Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ static HashTable *date_object_get_gc(zend_object *object, zval **table, int *n);
static HashTable *date_object_get_properties_for(zend_object *object, zend_prop_purpose purpose);
static HashTable *date_object_get_gc_interval(zend_object *object, zval **table, int *n);
static HashTable *date_object_get_properties_interval(zend_object *object);
static HashTable *date_object_get_properties_for_interval(zend_object *object, zend_prop_purpose purpose);
static HashTable *date_object_get_gc_period(zend_object *object, zval **table, int *n);
static HashTable *date_object_get_properties_for_timezone(zend_object *object, zend_prop_purpose purpose);
static HashTable *date_object_get_gc_timezone(zend_object *object, zval **table, int *n);
Expand Down Expand Up @@ -1816,6 +1817,7 @@ static void date_register_classes(void) /* {{{ */
date_object_handlers_interval.read_property = date_interval_read_property;
date_object_handlers_interval.write_property = date_interval_write_property;
date_object_handlers_interval.get_properties = date_object_get_properties_interval;
date_object_handlers_interval.get_properties_for = date_object_get_properties_for_interval;
date_object_handlers_interval.get_property_ptr_ptr = date_interval_get_property_ptr_ptr;
date_object_handlers_interval.get_gc = date_object_get_gc_interval;
date_object_handlers_interval.compare = date_interval_compare_objects;
Expand Down Expand Up @@ -2240,6 +2242,33 @@ static HashTable *date_object_get_properties_interval(zend_object *object) /* {{
return props;
} /* }}} */

static HashTable *date_object_get_properties_for_interval(zend_object *object, zend_prop_purpose purpose) /* {{{ */
{
HashTable *props;
php_interval_obj *intervalobj;

switch (purpose) {
case ZEND_PROP_PURPOSE_DEBUG:
case ZEND_PROP_PURPOSE_SERIALIZE:
case ZEND_PROP_PURPOSE_VAR_EXPORT:
case ZEND_PROP_PURPOSE_JSON:
case ZEND_PROP_PURPOSE_ARRAY_CAST:
break;
default:
return zend_std_get_properties_for(object, purpose);
}

intervalobj = php_interval_obj_from_obj(object);
props = zend_array_dup(zend_std_get_properties(object));
if (!intervalobj->initialized) {
return props;
}

date_interval_object_to_hash(intervalobj, props);

return props;
} /* }}} */

static zend_object *date_object_new_period(zend_class_entry *class_type) /* {{{ */
{
php_period_obj *intern = zend_object_alloc(sizeof(php_period_obj), class_type);
Expand Down
20 changes: 20 additions & 0 deletions ext/date/tests/bug-gh20503.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-20503 (Assertion failure with ext/date DateInterval property hash construction)
--FILE--
<?php
$obj = new DateInterval('P1W');
$obj->prop3 = $obj;

// Array cast triggers get_properties_for with ARRAY_CAST purpose
// This would previously cause an assertion failure when modifying
// a HashTable with refcount > 1
$props = (array) $obj;
var_dump(count($props));
var_dump(isset($props['prop3']));
var_dump($props['y']);
?>
--EXPECTF--
Deprecated: Creation of dynamic property DateInterval::$prop3 is deprecated in %s on line %d
int(11)
bool(true)
int(0)