php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81179 fileperms() return wrong access information
Submitted: 2021-06-20 04:20 UTC Modified: 2021-06-21 12:41 UTC
From: jhr at informedwebmaster dot com Assigned: cmb (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 8.0.7 OS: Windows Server 2019 Ver.: 1809
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jhr at informedwebmaster dot com
New email:
PHP Version: OS:

 

 [2021-06-20 04:20 UTC] jhr at informedwebmaster dot com
Description:
------------
This bug can be reproduced by creating a directory called test in the root of drive C:, add an text file in the directory named "test.txt", give the IUSR user read but not write access to the file. IUSR is the user account php uses on IIS 10 when running php-scripts. Then runthe following php-code:

echo substr(sprintf('%o', fileperms('C:\test\test.txt')), -4);

It will show "0666" even thou the current user does not have write permission to the file. If it's helpful, is_writable('C:\test\test.txt') does correctly return false.

Test script:
---------------
I did not write this code, i found it on php.net. But it works fine to reproduce the bug(please read description):

echo substr(sprintf('%o', fileperms('C:\test\test.txt')), -4);

Expected result:
----------------
I expected to see "0644".

Actual result:
--------------
Actual result was "0666".

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-21 11:27 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-06-21 12:41 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2021-06-21 12:41 UTC] cmb@php.net
Well, fileperms() calls stat() (actually, on Windows there is an
own implementation as of PHP 7.4.0, so MSVCRT stat() is no longer
called, but that doesn't matter n this regard), and that only
checks the file attributes, and if the read-only flag is set, it
reports that the file has no write permissions for *all* users
(i.e. you either get 0444 or 0666 for files, never e.g. 0644).

is_writable(), however, additionally does an AccessCheck()
according to the ACL, so reports whether the file is actually
writable by the (impersonated) user.

While this is inconsistent on Windows, it doesn't really make
sense to fix it, because file permissons are rather different to
POSIX.  We should, however, document this behavior.
 [2021-06-21 13:00 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/1f7d8b1ee9e6c7350857ddc8bfce248a65a29787
Log: Fix #81179: fileperms() return wrong access information
 [2021-06-21 13:00 UTC] git@php.net
-Status: Verified +Status: Closed
 [2021-06-21 18:25 UTC] git@php.net
Automatic comment on behalf of mumumu
Revision: https://github.com/php/doc-ja/commit/1526c598b481db765e3504ce8d56a84c2cd96cc6
Log: Fix #81179: fileperms() return wrong access information
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC