Skip to content

Commit 06f5928

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix memory leak in tidy output handler on error Fix leaks with multiple calls to DatePeriod iterator current()
2 parents cd751f9 + b39e17b commit 06f5928

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
evaluation) and GH-18464 (Recursion protection for deprecation constants not
1212
released on bailout). (DanielEScherzer and ilutov)
1313

14+
- Date:
15+
. Fix leaks with multiple calls to DatePeriod iterator current(). (nielsdos)
16+
1417
- Intl:
1518
. Fix memory leak in intl_datetime_decompose() on failure. (nielsdos)
1619

@@ -28,6 +31,9 @@ PHP NEWS
2831
- Soap:
2932
. Fix memory leaks in php_http.c when call_user_function() fails. (nielsdos)
3033

34+
- Tidy:
35+
. Fix memory leak in tidy output handler on error. (nielsdos)
36+
3137
06 Jun 2025, PHP 8.4.8
3238

3339
- Core:

ext/date/php_date.c

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

16191619
/* Create new object */
1620+
zval_ptr_dtor(&iterator->current);
16201621
php_date_instantiate(get_base_date_class(object->start_ce), &iterator->current);
16211622
newdateobj = Z_PHPDATE_P(&iterator->current);
16221623
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
@@ -961,18 +961,18 @@ static zend_result php_tidy_output_handler(void **nothing, php_output_context *o
961961
TidyBuffer inbuf, outbuf, errbuf;
962962

963963
if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
964+
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
965+
php_error_docref(NULL, E_WARNING, "Input string is too long");
966+
return status;
967+
}
968+
964969
doc = tidyCreate();
965970
tidyBufInit(&errbuf);
966971

967972
if (0 == tidySetErrorBuffer(doc, &errbuf)) {
968973
tidyOptSetBool(doc, TidyForceOutput, yes);
969974
tidyOptSetBool(doc, TidyMark, no);
970975

971-
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
972-
php_error_docref(NULL, E_WARNING, "File content is too long");
973-
return status;
974-
}
975-
976976
TIDY_SET_DEFAULT_CONFIG(doc);
977977

978978
tidyBufInit(&inbuf);

0 commit comments

Comments
 (0)