Skip to content

Commit 3842168

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-20906: Assertion failure when messing up output buffers
2 parents 07e29ac + 1709689 commit 3842168

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug GH-21052 (Preloaded constant erroneously propagated to file-cached
77
script). (ilutov)
88

9+
- Standard:
10+
. Fixed bug GH-20906 (Assertion failure when messing up output buffers).
11+
(ndossche)
12+
913
12 Mar 2026, PHP 8.5.4
1014

1115
- Core:

ext/standard/basic_functions.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,10 @@ PHP_FUNCTION(highlight_file)
17511751
}
17521752

17531753
if (i) {
1754-
php_output_start_default();
1754+
if (UNEXPECTED(php_output_start_default() != SUCCESS)) {
1755+
zend_throw_error(NULL, "Unable to start output handler");
1756+
RETURN_THROWS();
1757+
}
17551758
}
17561759

17571760
php_get_highlight_struct(&syntax_highlighter_ini);
@@ -1786,7 +1789,10 @@ PHP_FUNCTION(php_strip_whitespace)
17861789
Z_PARAM_PATH_STR(filename)
17871790
ZEND_PARSE_PARAMETERS_END();
17881791

1789-
php_output_start_default();
1792+
if (UNEXPECTED(php_output_start_default() != SUCCESS)) {
1793+
zend_throw_error(NULL, "Unable to start output handler");
1794+
RETURN_THROWS();
1795+
}
17901796

17911797
zend_stream_init_filename_ex(&file_handle, filename);
17921798
zend_save_lexical_state(&original_lex_state);
@@ -1823,7 +1829,10 @@ PHP_FUNCTION(highlight_string)
18231829
ZEND_PARSE_PARAMETERS_END();
18241830

18251831
if (i) {
1826-
php_output_start_default();
1832+
if (UNEXPECTED(php_output_start_default() != SUCCESS)) {
1833+
zend_throw_error(NULL, "Unable to start output handler");
1834+
RETURN_THROWS();
1835+
}
18271836
}
18281837

18291838
EG(error_reporting) = E_ERROR;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-20906 (Assertion failure when messing up output buffers) - php_strip_whitespace
3+
--CREDITS--
4+
vi3tL0u1s
5+
--FILE--
6+
<?php
7+
class A {
8+
function __destruct() {
9+
php_strip_whitespace(__FILE__);
10+
echo "x";
11+
$c = new A;
12+
ob_start(function () use ($c) { return '/'; }, 1);
13+
ob_start(function () use (&$c) { $c = new A; return '/'; }, 1);
14+
}
15+
}
16+
17+
try {
18+
new A;
19+
} catch (Throwable $e) {
20+
echo $e::class, ": ", $e->getMessage(), "\n";
21+
}
22+
?>
23+
--EXPECTF--
24+
%a
25+
Fatal error: php_strip_whitespace(): Cannot use output buffering in output buffering display handlers in %s on line %d
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-20906 (Assertion failure when messing up output buffers) - highlight_file
3+
--CREDITS--
4+
vi3tL0u1s
5+
--FILE--
6+
<?php
7+
class A {
8+
function __destruct() {
9+
highlight_file(__FILE__, true);
10+
echo "x";
11+
$c = new A;
12+
ob_start(function () use ($c) { return '/'; }, 1);
13+
ob_start(function () use (&$c) { $c = new A; return '/'; }, 1);
14+
}
15+
}
16+
17+
new A;
18+
?>
19+
--EXPECTF--
20+
%a
21+
Fatal error: highlight_file(): Cannot use output buffering in output buffering display handlers in %s on line %d
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-20906 (Assertion failure when messing up output buffers) - highlight_string
3+
--CREDITS--
4+
vi3tL0u1s
5+
--FILE--
6+
<?php
7+
class A {
8+
function __destruct() {
9+
highlight_string(__FILE__, true);
10+
echo "x";
11+
$c = new A;
12+
ob_start(function () use ($c) { return '/'; }, 1);
13+
ob_start(function () use (&$c) { $c = new A; return '/'; }, 1);
14+
}
15+
}
16+
17+
new A;
18+
?>
19+
--EXPECTF--
20+
%a
21+
Fatal error: highlight_string(): Cannot use output buffering in output buffering display handlers in %s on line %d

0 commit comments

Comments
 (0)