Skip to content

Commit 470b7e9

Browse files
context is also unavailable
1 parent 5781571 commit 470b7e9

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

main/output.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,15 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
10351035
OG(running) = NULL;
10361036
}
10371037

1038+
if (!still_have_handler) {
1039+
// Handler and context will have both already been freed
1040+
return status;
1041+
}
1042+
10381043
switch (status) {
10391044
case PHP_OUTPUT_HANDLER_FAILURE:
1040-
if (still_have_handler) {
1041-
/* disable this handler */
1042-
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
1043-
}
1045+
/* disable this handler */
1046+
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
10441047
/* discard any output */
10451048
if (context->out.data && context->out.free) {
10461049
efree(context->out.data);
@@ -1049,22 +1052,18 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
10491052
context->out.data = handler->buffer.data;
10501053
context->out.used = handler->buffer.used;
10511054
context->out.free = 1;
1052-
if (still_have_handler) {
1053-
handler->buffer.data = NULL;
1054-
handler->buffer.used = 0;
1055-
handler->buffer.size = 0;
1056-
}
1055+
handler->buffer.data = NULL;
1056+
handler->buffer.used = 0;
1057+
handler->buffer.size = 0;
10571058
break;
10581059
case PHP_OUTPUT_HANDLER_NO_DATA:
10591060
/* handler ate all */
10601061
php_output_context_reset(context);
10611062
ZEND_FALLTHROUGH;
10621063
case PHP_OUTPUT_HANDLER_SUCCESS:
1063-
if (still_have_handler) {
1064-
/* no more buffered data */
1065-
handler->buffer.used = 0;
1066-
handler->flags |= PHP_OUTPUT_HANDLER_PROCESSED;
1067-
}
1064+
/* no more buffered data */
1065+
handler->buffer.used = 0;
1066+
handler->flags |= PHP_OUTPUT_HANDLER_PROCESSED;
10681067
break;
10691068
}
10701069

tests/output/ob_start_callback_bad_return/handler_removed.phpt renamed to tests/output/ob_start_callback_bad_return/handler_false_removed.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
ob_start(): Check behaviour with deprecation when OOM triggers handler removal
2+
ob_start(): Check behaviour with deprecation when OOM triggers handler removal (handler returns false)
33
--FILE--
44
<?php
55

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
ob_start(): Check behaviour with deprecation when OOM triggers handler removal (handler returns true)
3+
--FILE--
4+
<?php
5+
6+
ob_start(function() {
7+
// We are out of memory, now trigger a deprecation
8+
return true;
9+
});
10+
11+
$a = [];
12+
// trigger OOM in a resize operation
13+
while (1) {
14+
$a[] = 1;
15+
}
16+
17+
?>
18+
--EXPECTF--
19+
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
20+
21+
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) 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+
ob_start(): Check behaviour with deprecation when OOM triggers handler removal (handler returns zero)
3+
--FILE--
4+
<?php
5+
6+
ob_start(function() {
7+
// We are out of memory, now trigger a deprecation
8+
return 0;
9+
});
10+
11+
$a = [];
12+
// trigger OOM in a resize operation
13+
while (1) {
14+
$a[] = 1;
15+
}
16+
17+
?>
18+
--EXPECTF--
19+
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
20+
21+
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d

0 commit comments

Comments
 (0)