Skip to content

Commit 4b0a4f4

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20906: Assertion failure when messing up output buffers
2 parents be6038a + 3842168 commit 4b0a4f4

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed

ext/standard/basic_functions.c

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

17471747
if (i) {
1748-
php_output_start_default();
1748+
if (UNEXPECTED(php_output_start_default() != SUCCESS)) {
1749+
zend_throw_error(NULL, "Unable to start output handler");
1750+
RETURN_THROWS();
1751+
}
17491752
}
17501753

17511754
php_get_highlight_struct(&syntax_highlighter_ini);
@@ -1780,7 +1783,10 @@ PHP_FUNCTION(php_strip_whitespace)
17801783
Z_PARAM_PATH_STR(filename)
17811784
ZEND_PARSE_PARAMETERS_END();
17821785

1783-
php_output_start_default();
1786+
if (UNEXPECTED(php_output_start_default() != SUCCESS)) {
1787+
zend_throw_error(NULL, "Unable to start output handler");
1788+
RETURN_THROWS();
1789+
}
17841790

17851791
zend_stream_init_filename_ex(&file_handle, filename);
17861792
zend_save_lexical_state(&original_lex_state);
@@ -1817,7 +1823,10 @@ PHP_FUNCTION(highlight_string)
18171823
ZEND_PARSE_PARAMETERS_END();
18181824

18191825
if (i) {
1820-
php_output_start_default();
1826+
if (UNEXPECTED(php_output_start_default() != SUCCESS)) {
1827+
zend_throw_error(NULL, "Unable to start output handler");
1828+
RETURN_THROWS();
1829+
}
18211830
}
18221831

18231832
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)