|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72600 Consider root special perms with stream_wrapper
Submitted: 2016-07-15 06:40 UTC Modified: 2016-07-15 06:55 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: w1s2j3229 at 163 dot com Assigned:
Status: Open Package: *Directory/Filesystem functions
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: w1s2j3229 at 163 dot com
New email:
PHP Version: OS:


 [2016-07-15 06:40 UTC] w1s2j3229 at 163 dot com
I found the problem when calling is_writable() after stream_wrapper_register().

It is OK with non-root user, but the result is not as expected with root user.

I want to remain the same permission as no stream_wrapper so I return just what "stat()" returns in "url_stat()" with my stream_wrapper class.

However, in the filestat.c source code, it does special check to root user( getuid() == 0) only with php_plain_files_wrapper. So I got false while calling is_writable after stream_wrapper_register().

I wonder if it is possible to add a function "is_super_user" in the stream_wrapper, and call it while calling permission check functions such as is_readable, is_writable and is_executable in case to keep consistent with system root user where needed.

Test script:
class TestStream{
        public static function wrap() { stream_wrapper_unregister('file'); stream_wrapper_register('file', get_called_class()); }
        public static function unwrap(){ stream_wrapper_restore('file'); }
        public function url_stat($path, $flags){
                $this->unwrap(); $result = stat($path); $this->wrap();
                return $result;
$file = __DIR__."/tmp"; @mkdir($file, 0777, true); chmod($file, 0);
clearstatcache(); var_dump(is_writable($file));
clearstatcache(); TestStream::wrap(); var_dump(is_writable($file)); TestStream::unwrap();
chmod($file, 0777); rmdir($file);

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-15 06:55 UTC] w1s2j3229 at 163 dot com
Test script must run as root user
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 05:03:37 2021 UTC