Bug->Doc #78400 [Ver]: Sym-linked files are not accessible

From: Date: Tue, 21 Jul 2020 14:27:29 +0000
Subject: Bug->Doc #78400 [Ver]: Sym-linked files are not accessible
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17723@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78400&edit=1 ID: 78400 Updated by: cmb@php.net Reported by: armin at v dot ieweg dot de Summary: Sym-linked files are not accessible Status: Verified -Type: Bug +Type: Documentation Problem Package: Built-in web server Operating System: Windows 10 PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > […], 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> Previous Comments: ------------------------------------------------------------------------ [2019-08-24 11:05:15] 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> ------------------------------------------------------------------------ [2019-08-11 16:41:16] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78400&edit=1

« previous php.doc.bugs (#17723) next »