Repository navigation
Conversation
Calling request_parse_body() on a multipart request whose body was already parsed (at startup, or by a previous call) replaced SG(rfc1867_uploaded_files). The files from the first parse were no longer accepted by is_uploaded_file() and move_uploaded_file(), and were never deleted at the end of the request.
devnexen
reviewed
Nov 12, 2026
| $tmp_name = $_FILES['file_name']['tmp_name']; | ||
| var_dump(is_uploaded_file($tmp_name)); | ||
|
|
||
| request_parse_body(); |
Member
There was a problem hiding this comment.
--- a/ext/standard/tests/http/request_parse_body/multipart_twice.phpt
+++ b/ext/standard/tests/http/request_parse_body/multipart_twice.phpt
@@ -17,11 +17,29 @@
$tmp_name = $files['file_name']['tmp_name'];
var_dump(is_uploaded_file($tmp_name));
-request_parse_body();
+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"| $tmp_name = $files['file_name']['tmp_name']; | ||
| var_dump(is_uploaded_file($tmp_name)); | ||
|
|
||
| request_parse_body(); |
Member
There was a problem hiding this comment.
--- 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
@@ -14,11 +14,29 @@
$tmp_name = $_FILES['file_name']['tmp_name'];
var_dump(is_uploaded_file($tmp_name));
-request_parse_body();
+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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on the "Request lifecycle hooks for SAPIs with a worker mode" RFC, I discovered a bug affecting existing SAPIs.
Calling
request_parse_body()on a multipart request whose body was already parsed replacesSG(rfc1867_uploaded_files)with a new instance. This happens when the body was parsed at startup (POST withenable_post_data_reading=1), or when the userlandrequest_parse_body()function is called several times.The files from the previous parses are then lost. This patch reuses the existing table instead.
Related to #24802 and #24987, but neither the same bug nor the same fix.
AI: Claude Code used to find the issue and write the patch.