php / php/php-src

For php://input fread() writes temp files

オープン
#8,239 コメント 6 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Category: Engine Feature Status: Verified
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code:

<?php
// index.php

$postBodyResource = fopen("php://input", 'rb');
while (!feof($postBodyResource)) {
    $data = fread($postBodyResource, 5 * 1024);
}
fclose($postBodyResource);

and Apache 2.4 config

Alias "/api" "${SRVROOT}/htdocs/Api"
<Directory "${SRVROOT}/htdocs/Api">
    RewriteEngine On 
    RewriteCond %{REQUEST_FILEaNAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]

    Script POST "index.php"
    Script PUT "index.php"

    php_value enable_post_data_reading Off
</Directory>

Resulted in this output:
If I do a HTTP POST (Content-Type: application/octet-stream) at http://localhost/api with a body larger than 16 kB, PHP creates a temp file at sys_temp_dir or upload_dir that stores the whole content of the stream php://input while doing fread().

But I expected this output instead:
At least there should be a configuration option to disable writing the temp files.

See temp file writing so caused by php_fopen_wrapper.c#L231.

Please, see Stackoverflow for some discussion.

PHP Version

PHP 7.4+

Operating System

Windows 10 21H2

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンク先の行にある ext/standard/php_fopen_wrapper.c から始め、提供されたスクリプト、Apache 設定、および Windows 上で 16 kB を超える POST ボディを使って PHP 7.4+ の動作を再現してください。php://input が完全なストリームを一時ファイルに書き込む理由を追跡してください。報告された動作またはその設定による制御に対処し、回帰テストでカバーできれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
apache, c, php
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。