GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix uploaded files leak in request_parse_body() by dunglas · Pull Request #25387 · php/php-src

Conversation

@dunglas

@dunglas dunglas commented Nov 11, 2026

Copy link
Copy Markdown
Member

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 replaces SG(rfc1867_uploaded_files) with a new instance. This happens when the body was parsed at startup (POST with enable_post_data_reading=1), or when the userland request_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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dunglas
Fix uploaded files leak in request_parse_body()
939ac48
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.
@dunglas
dunglas requested a review from bukka as a code owner November 11, 2026 13:54
@github-actions github-actions Bot added the Extension: standard label Nov 11, 2026
devnexen
devnexen reviewed Nov 12, 2026
View reviewed changes
Comment thread ext/standard/tests/http/request_parse_body/multipart_after_startup_parse.phpt
$tmp_name = $_FILES['file_name']['tmp_name'];
var_dump(is_uploaded_file($tmp_name));

request_parse_body();

@devnexen devnexen Nov 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- 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"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ext/standard/tests/http/request_parse_body/multipart_twice.phpt
$tmp_name = $files['file_name']['tmp_name'];
var_dump(is_uploaded_file($tmp_name));

request_parse_body();

@devnexen devnexen Nov 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- 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"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@devnexen devnexen devnexen left review comments
@bukka bukka Awaiting requested review from bukka bukka is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Extension: standard

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@dunglas @devnexen
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.