streams/userspace.c: PHP_STREAM_FLAG_NO_FCLOSE guard missing in stream_stat handler (incomplete fix for GH-25586)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
main/streams/userspace.c の _php_stream_stat から始め、stream_stat コールバックの処理を、既存の flush、write、read、seek、cast のガードと比較してください。既存のユーザーストリームのテストに倣い、ストリーム上で fclose() を呼び出す stream_stat() コールバックの回帰テストを追加してください。完了条件は、アクティブなコールバックの実行中に fclose() が警告を出し、ストリームを閉じないことです。
索引モデルが issue の本文から書いたものです。
説明
Description
GH-25586 (Nov 2026) added PHP_STREAM_FLAG_NO_FCLOSE guard to the flush
handler in main/streams/userspace.c to prevent use-after-free when a user
stream wrapper's stream_flush() callback calls fclose() on the stream.
The same guard is absent from the stream_stat handler (_php_stream_stat,
line ~865).
The following code:
<?php
class UAFStream {
public static $res;
public function stream_open($path, $mode, $opts, &$opened): bool {
return true;
}
public function stream_stat(): array|false {
// Without PHP_STREAM_FLAG_NO_FCLOSE, fclose() succeeds here,
// freeing the stream while C code may still hold a pointer to it.
fclose(self::$res);
return false;
}
public function stream_read(int $count): string { return ''; }
public function stream_eof(): bool { return true; }
}
stream_wrapper_register('x', 'UAFStream');
$fp = fopen('x://test', 'r');
UAFStream::$res = $fp;
fstat($fp); // triggers stream_stat → fclose() completes with no warning
echo "done\n";
Resulted in this output:
done
No warning is emitted and fclose() completes successfully inside the callback,
freeing the stream resource while fstat() / _php_stream_stat() may still
hold pointers into it.
But I expected this output instead:
Warning: Cannot close stream with active callback in ...
done
Consistent with the guard added for flush in GH-25586: fclose() should be
a no-op (with a warning) when called from within a stream callback.
Suggested fix (main/streams/userspace.c, _php_stream_stat):
bool originally_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE;
stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
call_result = zend_call_method_with_0_params(...); /* stream_stat */
if (!originally_no_fclose) {
stream->flags ^= PHP_STREAM_FLAG_NO_FCLOSE;
}
This is the identical pattern used for flush (GH-25586), write, read,
seek, and cast.
PHP Version
PHP 8.6.0 (cli) (built: Nov 19 2026 15:17:27) (ZTS)
Operating System
Ubuntu 26.04
- 主要言語
- C
- スター
- 41.9k
- フォーク
- 8.5k
- 平均マージ
- 2日 18時間
- マージ済み PR(30日)
- 106
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
php/php-src のほかの issue
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)オープンExtension: openssl Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
php/php-src#25402 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Life-Framework/Life-Framework#5378 ·
メンテナーはふだん 1 日以内に返信
-
bug status: planned ui
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ChupathingyCE/chupathingyce#2126 ·
メンテナーはふだん 1 日以内に返信
-
good first issue simulation
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
MarcosAsh/Lattice_Fluid_Dynamics#270 ·
メンテナーはふだん 1 日以内に返信
-
needs-kind
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
falcosecurity/libs#3173 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
vincentarelbundock/xtx#11 ·