php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78400 Sym-linked files are not accessible
Submitted: 2019-08-11 16:41 UTC Modified: 2020-07-21 14:27 UTC
From: armin at v dot ieweg dot de Assigned: cmb (profile)
Status: Closed Package: Built-in web server
PHP Version: Irrelevant OS: Windows 10
Private report: No CVE-ID: None
 [2019-08-11 16:41 UTC] armin at v dot ieweg dot de
Description:
------------
I've already created an issue on Github, regarding their web-server. But it figured out that the issue also occures, when using the built-in web server nativley.

What I did:

> php -S localhost:8000 -t .
PHP 7.2.19 Development Server started at Sun Aug 11 16:25:34 2019
Listening on http://localhost:8000
Document root is C:\Dev\test
Press Ctrl-C to quit.
[Sun Aug 11 16:25:39 2019] ::1:60634 [200]: /images/test/test.png

I've started the server and requested an image which is a symlink to "../realfile.png" (which is still located within document root). The server response is 200 but with a content-length of 0. Regular files work normal.

Here you find the original github issue: https://github.com/symfony/symfony/issues/33089


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-24 11:05 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-08-24 11:05 UTC] cmb@php.net
The culprit is that we're basically calling stat() on the
symlink[1], and take st_size as being the size of the symlinked
file[2], while it is not.

[1] <https://github.com/php/php-src/blob/php-7.2.21/sapi/cli/php_cli_server.c#L1382>
[2] <https://github.com/php/php-src/blob/php-7.2.21/sapi/cli/php_cli_server.c#L2050>
 [2020-07-21 14:27 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2020-07-21 14:27 UTC] cmb@php.net
> […], while it is not.

Oh, I misread the POSIX standard.  Actually, stat()ing a symlink
is supposed to give the target's size, and that works fine on
Linux (<https://3v4l.org/0u1fj>).

Now let's take a step away from the reported issue, and analyse
PHP's stat() function, which is obviously closely related.

On Windows, stat() works as expected on ZTS builds, and also on
NTS builds as of PHP 7.4.0.  However, NTS builds on previous PHP
versions rely on GetFileAttributesEx() for which the symbolik link
behavior is documented[1]:

| If the path points to a symbolic link, the function returns
| attributes for the symbolic link.

This is apparently not the case for you, as well as for me (may
very well depend on the Windows version).

And now back to the issue at hand.  The stat(3) call in the
built-in Webserver is (correctly) mapped to php_sys_stat(), and as
such relies on GetFileAttributesEx() (regardless of ZTS/NTS);
therefore the reported behavior is only fixed as of PHP 7.4.0
(even on ZTS builds).

Given the invasive nature of the required fix, and that PHP 7.3 is
already late in its release cycle, I don't think that we want to
back-port the fix to that version (PHP 7.2 is already off the table
for regular bug fixes).  Therefore I'm changing this to doc issue.

[1] <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesexa>
 [2020-07-22 09:26 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=fe81a24d2e124209c833c9715ec4c83ca546274b
Log: Fix #78400: Sym-linked files are not accessible
 [2020-07-22 09:26 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-07-24 04:55 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=a97f3629218e772f427716e8c1c8dfd25b12e040
Log: Fix #78400: Sym-linked files are not accessible PHP_CLI_SERVER_WORKERS is not supported on Windows
 [2020-07-24 05:10 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=a2d3eab6ea6720fa7017818f8edf0a7244eb4eaa
Log: Fix #78400: Sym-linked files are not accessible
 [2020-12-30 11:59 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=ce893e2c9d703688a34ae278cbae3c9a0bef2562
Log: Fix #78400: Sym-linked files are not accessible
 [2020-12-30 11:59 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=29d0fbfc8dbcaaa5dfd699bad734784767ea0f69
Log: Fix #78400: Sym-linked files are not accessible PHP_CLI_SERVER_WORKERS is not supported on Windows
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC