For php://input fread() writes temp files
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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