streams/userspace.c: PHP_STREAM_FLAG_NO_FCLOSE guard missing in stream_lock handler (incomplete fix for GH-25586)

未關閉 適合新手
#25,816 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
79/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
c, php
領域
backend, devtools

研究方向

閱讀 main/streams/userspace.c 中 php_stream_lock_userspace 附近的程式碼(約第 949 行),並將其回呼處理方式與 GH-25586 的修正進行比較。檢查使用者回呼前後如何設定和還原 PHP_STREAM_FLAG_NO_FCLOSE,然後執行 issue 中的 stream wrapper 回歸案例。當 stream_lock 期間呼叫 fclose() 會警告在回呼作用期間不能關閉 stream,且鎖定呼叫安全完成時,即為完成。

由索引模型根據 Issue 內容生成。

描述

Bug Status: Needs Triage
Description

Same pattern as GH-25586: the stream_lock handler in
main/streams/userspace.c (~line 949) calls the user callback via
zend_call_method_with_1_params without first setting
PHP_STREAM_FLAG_NO_FCLOSE, allowing fclose() inside the callback to free
the stream while C code holds a live pointer.

The following code:

<?php
class LockStream {
    public static $res;

    public function stream_open($path, $mode, $opts, &$opened): bool {
        return true;
    }
    public function stream_lock(int $operation): bool {
        fclose(self::$res);  // succeeds; no NO_FCLOSE guard
        return true;
    }
    public function stream_read(int $count): string { return ''; }
    public function stream_eof(): bool { return true; }
    public function stream_stat(): array|false { return false; }
}

stream_wrapper_register('x', 'LockStream');
$fp = fopen('x://test', 'r');
LockStream::$res = $fp;
flock($fp, LOCK_EX);  // triggers stream_lock → fclose() completes silently
echo "done\n";

Resulted in this output:

done

But I expected this output instead:

Warning: Cannot close stream with active callback in ...
done

Suggested fix (main/streams/userspace.c, php_stream_lock_userspace):

bool originally_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE;
stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
call_result = zend_call_method_with_1_params(...); /* stream_lock */
if (!originally_no_fclose) {
    stream->flags ^= PHP_STREAM_FLAG_NO_FCLOSE;
}
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 小時
30 天內合併 PR
106

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。