1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix memory leak in tidy output handler on error
  Fix leaks with multiple calls to DatePeriod iterator current()
This commit is contained in:
Niels Dossche
2025-05-26 19:42:39 +02:00
3 changed files with 48 additions and 5 deletions

View File

@@ -1581,6 +1581,7 @@ static zval *date_period_it_current_data(zend_object_iterator *iter)
php_date_obj *newdateobj;
/* Create new object */
zval_ptr_dtor(&iterator->current);
php_date_instantiate(get_base_date_class(object->start_ce), &iterator->current);
newdateobj = Z_PHPDATE_P(&iterator->current);
newdateobj->time = timelib_time_ctor();

View File

@@ -0,0 +1,42 @@
--TEST--
Multiple calls to DatePeriod iterator current() leak objects
--FILE--
<?php
$start = new DateTime('2018-12-31 00:00:00');
$end = new DateTime('2019-12-31 00:00:00');
$interval = new DateInterval('P1M');
$period = new DatePeriod($start, $interval, 1);
$iter = $period->getIterator();
var_dump($iter->current());
var_dump($iter->current());
$iter->current()->setTimestamp(0);
var_dump($iter->current());
?>
--EXPECT--
object(DateTime)#9 (3) {
["date"]=>
string(26) "2018-12-31 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#9 (3) {
["date"]=>
string(26) "2018-12-31 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#9 (3) {
["date"]=>
string(26) "2018-12-31 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}

View File

@@ -955,6 +955,11 @@ static zend_result php_tidy_output_handler(void **nothing, php_output_context *o
TidyBuffer inbuf, outbuf, errbuf;
if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
return status;
}
doc = tidyCreate();
tidyBufInit(&errbuf);
@@ -962,11 +967,6 @@ static zend_result php_tidy_output_handler(void **nothing, php_output_context *o
tidyOptSetBool(doc, TidyForceOutput, yes);
tidyOptSetBool(doc, TidyMark, no);
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
php_error_docref(NULL, E_WARNING, "File content is too long");
return status;
}
TIDY_SET_DEFAULT_CONFIG(doc);
tidyBufInit(&inbuf);