Skip to content

Commit cec079e

Browse files
committed
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()
2 parents 042a975 + 06f5928 commit cec079e

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

ext/date/php_date.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@ static zval *date_period_it_current_data(zend_object_iterator *iter)
15811581
php_date_obj *newdateobj;
15821582

15831583
/* Create new object */
1584+
zval_ptr_dtor(&iterator->current);
15841585
php_date_instantiate(get_base_date_class(object->start_ce), &iterator->current);
15851586
newdateobj = Z_PHPDATE_P(&iterator->current);
15861587
newdateobj->time = timelib_time_ctor();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Multiple calls to DatePeriod iterator current() leak objects
3+
--FILE--
4+
<?php
5+
$start = new DateTime('2018-12-31 00:00:00');
6+
$end = new DateTime('2019-12-31 00:00:00');
7+
8+
$interval = new DateInterval('P1M');
9+
$period = new DatePeriod($start, $interval, 1);
10+
11+
$iter = $period->getIterator();
12+
var_dump($iter->current());
13+
var_dump($iter->current());
14+
$iter->current()->setTimestamp(0);
15+
var_dump($iter->current());
16+
17+
?>
18+
--EXPECT--
19+
object(DateTime)#9 (3) {
20+
["date"]=>
21+
string(26) "2018-12-31 00:00:00.000000"
22+
["timezone_type"]=>
23+
int(3)
24+
["timezone"]=>
25+
string(3) "UTC"
26+
}
27+
object(DateTime)#9 (3) {
28+
["date"]=>
29+
string(26) "2018-12-31 00:00:00.000000"
30+
["timezone_type"]=>
31+
int(3)
32+
["timezone"]=>
33+
string(3) "UTC"
34+
}
35+
object(DateTime)#9 (3) {
36+
["date"]=>
37+
string(26) "2018-12-31 00:00:00.000000"
38+
["timezone_type"]=>
39+
int(3)
40+
["timezone"]=>
41+
string(3) "UTC"
42+
}

ext/tidy/tidy.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,18 +955,18 @@ static zend_result php_tidy_output_handler(void **nothing, php_output_context *o
955955
TidyBuffer inbuf, outbuf, errbuf;
956956

957957
if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
958+
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
959+
php_error_docref(NULL, E_WARNING, "Input string is too long");
960+
return status;
961+
}
962+
958963
doc = tidyCreate();
959964
tidyBufInit(&errbuf);
960965

961966
if (0 == tidySetErrorBuffer(doc, &errbuf)) {
962967
tidyOptSetBool(doc, TidyForceOutput, yes);
963968
tidyOptSetBool(doc, TidyMark, no);
964969

965-
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
966-
php_error_docref(NULL, E_WARNING, "File content is too long");
967-
return status;
968-
}
969-
970970
TIDY_SET_DEFAULT_CONFIG(doc);
971971

972972
tidyBufInit(&inbuf);

0 commit comments

Comments
 (0)