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

From: Date: Thu, 12 Nov 2026 18:53:02 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143657@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-11-13T02:52:26+08:00 Commit: https://github.com/php/php-src/commit/5f65ab1428c2f262b8404f52fff3b970b743f6d1 Raw diff: https://github.com/php/php-src/commit/5f65ab1428c2f262b8404f52fff3b970b743f6d1.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix uploaded files leak in request_parse_body() (#25387) Changed paths: A ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt A ext/standard/tests/http/request_parse_body/multipart_twice.phpt M NEWS M main/rfc1867.c Diff: diff --git a/NEWS b/NEWS index a0bce4ed6f43..4938b79b0713 100644 --- a/NEWS +++ b/NEWS @@ -169,6 +169,8 @@ PHP NEWS rmdir(), touch(), chmod() or stat(). (Ilia Alshanetsky) - Standard: + . Fixed bug GH-25387 (Uploaded files leak in request_parse_body()). + (Kévin Dunglas) . Fixed quoted_printable_decode() truncating input at NUL bytes. (Weilin Du) . Fixed version_compare() silently truncating version strings at NUL bytes by rejecting such input. (Weilin Du) diff --git a/ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt b/ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt new file mode 100644 index 000000000000..0b3976ad6922 --- /dev/null +++ b/ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt @@ -0,0 +1,42 @@ +--TEST-- +request_parse_body() keeps files uploaded during startup parsing +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------84000087610663814162942123332 +-----------------------------84000087610663814162942123332 +Content-Disposition: form-data; name="file_name"; filename="original_file_name.txt" +Content-Type: text/plain + +file data +-----------------------------84000087610663814162942123332-- +--FILE-- +<?php + +$tmp_name = $_FILES['file_name']['tmp_name']; +var_dump(is_uploaded_file($tmp_name)); + +var_dump(request_parse_body()); + +var_dump(is_uploaded_file($tmp_name)); + +$dst = __DIR__ . '/multipart_after_startup_parse.txt'; +var_dump(move_uploaded_file($tmp_name, $dst)); +var_dump(file_get_contents($dst)); + +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/multipart_after_startup_parse.txt'); +?> +--EXPECT-- +bool(true) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +bool(true) +string(9) "file data" diff --git a/ext/standard/tests/http/request_parse_body/multipart_twice.phpt b/ext/standard/tests/http/request_parse_body/multipart_twice.phpt new file mode 100644 index 000000000000..27b6e58f94b8 --- /dev/null +++ b/ext/standard/tests/http/request_parse_body/multipart_twice.phpt @@ -0,0 +1,45 @@ +--TEST-- +request_parse_body() called twice keeps files uploaded by the first call +--ENV-- +REQUEST_METHOD=PUT +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------84000087610663814162942123332 +-----------------------------84000087610663814162942123332 +Content-Disposition: form-data; name="file_name"; filename="original_file_name.txt" +Content-Type: text/plain + +file data +-----------------------------84000087610663814162942123332-- +--FILE-- +<?php + +[, $files] = request_parse_body(); +$tmp_name = $files['file_name']['tmp_name']; +var_dump(is_uploaded_file($tmp_name)); + +var_dump(request_parse_body()); + +var_dump(is_uploaded_file($tmp_name)); + +$dst = __DIR__ . '/multipart_twice.txt'; +var_dump(move_uploaded_file($tmp_name, $dst)); +var_dump(file_get_contents($dst)); + +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/multipart_twice.txt'); +?> +--EXPECT-- +bool(true) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +bool(true) +string(9) "file data" diff --git a/main/rfc1867.c b/main/rfc1867.c index 934e223a5545..a4662ae4e819 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -692,7 +692,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) size_t array_len = 0; int64_t total_bytes = 0, max_file_size = 0; int skip_upload = 0, anonymous_index = 0; - HashTable *uploaded_files = NULL; multipart_buffer *mbuff; zval *array_ptr = (zval *) arg; bool throw_exceptions = SG(request_parse_body_context).throw_exceptions; @@ -790,9 +789,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* Initialize $_FILES[] */ zend_hash_init(&PG(rfc1867_protected_variables), 8, NULL, NULL, 0); - ALLOC_HASHTABLE(uploaded_files); - zend_hash_init(uploaded_files, 8, NULL, free_filename, 0); - SG(rfc1867_uploaded_files) = uploaded_files; + /* request_parse_body() may parse the body again, keep tracking earlier uploads */ + if (!SG(rfc1867_uploaded_files)) { + ALLOC_HASHTABLE(SG(rfc1867_uploaded_files)); + zend_hash_init(SG(rfc1867_uploaded_files), 8, NULL, free_filename, 0); + } if (Z_TYPE(PG(http_globals)[TRACK_VARS_FILES]) != IS_ARRAY) { /* php_auto_globals_create_files() might have already done that */

« previous php.cvs (#143657) next »