php / php/php-src

`is_readable()` and `is_writable()` return false negative on Win32's network-mapped drives

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

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

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

説明

Description

Hi there, good morning PHP team!

I'm working with PHP-CLI on Windows, and part of my project checks if a file path is readable and/or writable. This works as expected if the file in in the local disk, such as C:\.

However, Windows has a feature named network-mapped drives where you can "mount" a shared folder from another host to appear as a local disk, for example the SMB network share \\computername\foo\bar can be "mounted" to Z:\. In this case, calls to file_get_contents() and file_put_contents() will actually succeed, but the corresponding calls to is_readable() and is_writable() will return false.

Consider the following code:

$my_file = "Z:\\Users\\David\\File.txt";

var_dump(
    is_readable($my_file),
    is_writable($my_file),
    file_get_contents($my_file));

This results in this output:

bool(false)
bool(false)
string(34) "I am the content of the `my_file`!"

But I expect the following output:

bool(true)
bool(true)
string(34) "I am the content of the `my_file`!"

I was curious about this behavior, so I read the documentation for is_readable(), and the only piece of useful info I found is a very old user notes contribution that says:

..."is_readable() checks whether you can do file_get_contents() or similar calls, no more, no less."
~ jo at durchholz dot org

This doesn't seem right to me, because as you can see, the file_get_contents() is clearly succeeding while the is_readable() call is failing.

Please note that the PHP-CLI is running through command line with my own user account, not as some service where it wouldn't have access to the network-mapped drive.

So, I'm curious why this happens. Can you please link me to the relevant part of the source tree that implements is_readable() and is_writable()? I'm curious why this issue exists.

Thanks!

PHP Version

PHP 8.1.13

Operating System

Windows 11 Enterprise 22H2

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

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

はじめの一歩

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

調査の方向性

まずソースツリー内の is_readable() と is_writable() の実装を特定し、次に、提供された PHP 8.1.13 の例とネットワークドライブを使って Windows 11 で報告された動作を再現します。これらのチェックを file_get_contents() および file_put_contents() と比較します。原因を特定し、相違点を文書化または修正できれば完了です。

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

評価

技術スタック
c, php
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

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

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