php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60841 expand_filepath fails to resolve symlinks that point to \xxx\yyy
Submitted: 2012-01-22 21:16 UTC Modified: 2021-10-19 09:28 UTC
Votes:6
Avg. Score:4.2 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:2 (40.0%)
From: cataphract@php.net Assigned:
Status: Verified Package: Filesystem function related
PHP Version: 7.4 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
29 - 20 = ?
Subscribe to this entry?

 
 [2012-01-22 21:16 UTC] cataphract@php.net
Description:
------------
If a path includes a symlink that points to a path like \xxx\yyy, PHP understands 
it as a relative path, while it's actually an absolute path (or quasi-absolute, 
as it doesn't have a drive letter).

Expected result:
----------------
foocontents

Actual result:
--------------
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd \

C:\>mkdir t

C:\>mkdir t\test

C:\>mklink /D t\testlink \t\test
symbolic link created for t\testlink <<===>> \t\test

C:\>echo foocontents > \t\testlink\foo

C:\>php -r "echo file_get_contents('t\testlink\foo');"

Warning: file_get_contents(t\testlink\foo): failed to open stream: No such file
or directory in Command line code on line 1

C:\>php -r "echo file_get_contents('t\test\foo');"
foocontents

C:\>type t\testlink\foo
foocontents

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-22 22:05 UTC] pajoye@php.net
It is not an absolute path but a relative path to the current drive.

It can have very different meanings withing a request (PWD and co). I remember to 
have made a doc about that back then, let me find it back and try to provide a fix 
or document it better.
 [2012-01-22 22:05 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pajoye
 [2017-10-24 07:35 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pajoye +Assigned To:
 [2020-11-18 15:30 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-11-18 15:30 UTC] cmb@php.net
Well, in Windows parlance[1], it is

| An absolute path from the root of the current drive.

[1] <https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats>
 [2021-10-14 15:36 UTC] cmb@php.net
-Operating System: Windows 7 +Operating System: Windows -PHP Version: 5.3.9 +PHP Version: 7.4
 [2021-10-14 15:36 UTC] cmb@php.net
This is not particularly related to expand_file(), but rather to
tsrm_realpath_r(), as the following shows:

    C:\>php -r "echo file_get_contents('t\testlink\foo');"
    C:\t\t\test\foo

As it is now, PHP on Windows properly supports:

* absolute paths with drive letter
* relative paths without drive letter
* UNC paths

However, it does not fully support:

* absolute paths without drive letter (this ticket)
* relative paths with drive letter (bug #78939)

Fixing this is certainly possible, but in my opinion this must not
be done for any stable PHP branch, to avoid behavioral changes,
and even security issues, and requires extensive testing, due to
the complexity of tsrm_realpath_r().  It is important, though, to
document this issue.

FTR:

| An absolute path from the root of the current drive.

Doing the following after the supplied script may yield surprising
results:

C:\>D:

D:\>type C:\t\testlink\foo
foocontents

So the current drive when resolving the symlink is not the current
drive, but apparently the drive on which the link is stored.

Interestingly, when opening the file properties dialog of
C:\t\testlink in Explorer, it shows C:\t\t\test, so one may argue
that PHP's behavior is correct. ;)
 [2021-10-14 15:39 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2021-10-19 09:28 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 10 10:04:15 2022 UTC