Skip to content

Commit d63be80

Browse files
committed
Fix GH-24787 delayed OOM during request startup
1 parent fd1ea3c commit d63be80

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎main/main.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,9 @@ zend_result php_request_startup(void)
19041904
/* PG(during_request_startup) = 0; */
19051905

19061906
php_hash_environment();
1907+
if (ZEND_HAS_OOM()) {
1908+
zend_handle_delayed_oom();
1909+
}
19071910
zend_activate_modules();
19081911
PG(modules_activated)=1;
19091912
} zend_catch {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-24787 (Delayed OOM during request startup is handled as a fatal error)
3+
--SKIPIF--
4+
<?php
5+
if (!getenv('TEST_PHP_CGI_EXECUTABLE')) {
6+
die('skip php-cgi not available');
7+
}
8+
if (!extension_loaded('uri')) {
9+
die('skip uri extension not available');
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
$script = tempnam(sys_get_temp_dir(), 'gh24787');
15+
file_put_contents($script, "<?php echo \"request completed\\n\";");
16+
17+
$cookies = [];
18+
for ($i = 0; $i < 5000; $i++) {
19+
$cookies[] = "cookie$i=value";
20+
}
21+
22+
$process = proc_open(
23+
[getenv('TEST_PHP_CGI_EXECUTABLE'), '-n', '-d', 'memory_limit=8M', '-d', 'max_input_vars=10000', '-d', 'html_errors=0'],
24+
[STDIN, ['pipe', 'w'], ['pipe', 'w']],
25+
$pipes,
26+
null,
27+
['REQUEST_METHOD' => 'GET', 'HTTP_COOKIE' => implode('; ', $cookies), 'SCRIPT_FILENAME' => $script, 'REDIRECT_STATUS' => '1']
28+
);
29+
$output = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
30+
fclose($pipes[1]);
31+
fclose($pipes[2]);
32+
proc_close($process);
33+
unlink($script);
34+
35+
echo str_contains($output, 'Allowed memory size') ? "OOM handled\n" : $output;
36+
?>
37+
--EXPECT--
38+
OOM handled

0 commit comments

Comments
 (0)