|
| 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 | +// The field count needed to reach the startup gap varies by build and platform. |
| 18 | +$counts = range(1700, 1950, 4); |
| 19 | +$rinitFailed = false; |
| 20 | +$oomReported = false; |
| 21 | +foreach ($counts as $count) { |
| 22 | + $post = []; |
| 23 | + for ($i = 0; $i < $count; $i++) { |
| 24 | + $post[] = 'p' . $i . '=' . str_repeat('y', 4000); |
| 25 | + } |
| 26 | + $body = implode('&', $post); |
| 27 | + |
| 28 | + $command = [ |
| 29 | + getenv('TEST_PHP_CGI_EXECUTABLE'), |
| 30 | + '-n', |
| 31 | + '-d', 'memory_limit=8M', |
| 32 | + '-d', 'post_max_size=64M', |
| 33 | + '-d', 'max_input_vars=20000', |
| 34 | + '-d', 'html_errors=0', |
| 35 | + ]; |
| 36 | + $environment = [ |
| 37 | + 'REQUEST_METHOD' => 'POST', |
| 38 | + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', |
| 39 | + 'CONTENT_LENGTH' => (string) strlen($body), |
| 40 | + 'SCRIPT_FILENAME' => $script, |
| 41 | + 'REDIRECT_STATUS' => '1', |
| 42 | + ]; |
| 43 | + $process = proc_open($command, [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']], $pipes, null, $environment); |
| 44 | + fwrite($pipes[0], $body); |
| 45 | + fclose($pipes[0]); |
| 46 | + $output = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]); |
| 47 | + fclose($pipes[1]); |
| 48 | + fclose($pipes[2]); |
| 49 | + proc_close($process); |
| 50 | + |
| 51 | + $rinitFailed = $rinitFailed || str_contains($output, 'request_startup()'); |
| 52 | + $oomReported = $oomReported || str_contains($output, 'Allowed memory size'); |
| 53 | +} |
| 54 | +unlink($script); |
| 55 | + |
| 56 | +echo !$rinitFailed && $oomReported ? "OOM handled\n" : "RINIT failure or no OOM reported\n"; |
| 57 | +?> |
| 58 | +--EXPECT-- |
| 59 | +OOM handled |
0 commit comments