[php-src] master: Merge branch 'PHP-8.6'

From: Date: Tue, 10 Nov 2026 06:49:25 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143512@lists.php.net to get a copy of this message
Author: Go Kudo (zeriyoshi) Date: 2026-11-10T15:45:33+09:00 Commit: https://github.com/php/php-src/commit/3cb920a5b128061a117a67c46240cce6694b6fe8 Raw diff: https://github.com/php/php-src/commit/3cb920a5b128061a117a67c46240cce6694b6fe8.diff Merge branch 'PHP-8.6' Changed paths: A sapi/cgi/tests/stream_error_default_context.phpt M ext/standard/file.c Diff: diff --git a/ext/standard/file.c b/ext/standard/file.c index ff68374928c5..e64167df3283 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -111,6 +111,9 @@ PHPAPI int php_le_stream_context(void) static ZEND_RSRC_DTOR_FUNC(file_context_dtor) { php_stream_context *context = (php_stream_context*)res->ptr; + if (context == FG(default_context)) { + FG(default_context) = NULL; + } if (Z_TYPE(context->options) != IS_UNDEF) { zval_ptr_dtor(&context->options); ZVAL_UNDEF(&context->options); diff --git a/sapi/cgi/tests/stream_error_default_context.phpt b/sapi/cgi/tests/stream_error_default_context.phpt new file mode 100644 index 000000000000..240bd9342be7 --- /dev/null +++ b/sapi/cgi/tests/stream_error_default_context.phpt @@ -0,0 +1,63 @@ +--TEST-- +Stream errors before RINIT do not use the default stream context freed by the previous request +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +include "include.inc"; + +$php = get_cgi_path(); +reset_env_vars(); + +$dir = __DIR__ . '/stream_error_default_context'; +@mkdir($dir); +file_put_contents("$dir/index.php", '<?php file_get_contents(__FILE__); echo "ok ", count($_POST), "\n";'); +/* Larger than SAPI_POST_BLOCK_SIZE, so the request body is spilled to a temporary file */ +$body = 'a=' . str_repeat('a', 20000); +/* php-cgi -T reads CONTENT_LENGTH bytes of stdin for each request */ +file_put_contents("$dir/body", $body . $body); + +$env = [ + 'REDIRECT_STATUS' => '1', + 'REQUEST_METHOD' => 'POST', + 'SCRIPT_FILENAME' => "$dir/index.php", + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => (string) strlen($body), +]; +foreach (['PATH', 'USE_ZEND_ALLOC', 'USE_TRACKED_ALLOC', 'ASAN_OPTIONS', 'LSAN_OPTIONS', 'UBSAN_OPTIONS'] as $name) { + if (getenv($name) !== false) { + $env[$name] = getenv($name); + } +} + +/* The first request creates the default stream context, the second one fails to spill its body */ +$proc = proc_open( + [$php, '-n', '-d', 'display_errors=0', '-d', 'log_errors=1', '-d', "sys_temp_dir=$dir/missing", '-T', '2'], + [0 => ['file', "$dir/body", 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], + $pipes, + $dir, + $env +); +$stdout = stream_get_contents($pipes[1]); +$stderr = stream_get_contents($pipes[2]); +proc_close($proc); + +var_dump(substr_count($stdout, "ok 0\n")); +echo $stderr; +?> +--CLEAN-- +<?php +$dir = __DIR__ . '/stream_error_default_context'; +@unlink("$dir/index.php"); +@unlink("$dir/body"); +@rmdir($dir); +?> +--EXPECTF-- +int(2) +PHP Warning: PHP Request Startup: Unable to create temporary file, Check permissions in temporary files directory. in Unknown on line 0 +PHP Warning: PHP Request Startup: POST data can't be buffered; all data discarded in Unknown on line 0 +PHP Warning: PHP Request Startup: Unable to create temporary file, Check permissions in temporary files directory. in Unknown on line 0 +PHP Warning: PHP Request Startup: POST data can't be buffered; all data discarded in Unknown on line 0 + +Elapsed time: %s sec

« previous php.cvs (#143512) next »