php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #72738 realpath() expands junction points
Submitted: 2016-08-02 19:31 UTC Modified: 2020-11-18 17:15 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: anrdaemon at freemail dot ru Assigned: cmb (profile)
Status: Closed Package: Filesystem function related
PHP Version: 7.1.0beta1 OS: Windows
Private report: No CVE-ID: None
 [2016-08-02 19:31 UTC] anrdaemon at freemail dot ru
Description:
------------
On Windows, realpath() expands the directory junction points.
According to an apparently authoritative assesment of pajoye@php.net in the https://bugs.php.net/bug.php?id=72642 , this shouldn't happen.

Test script:
---------------
<?php

$rootdir = substr(getenv('SystemRoot'), 0, 3);
$tmpdir = getenv('TEMP');
shell_exec("mklink /J \"{$rootdir}home\" \"{$rootdir}Users\"");
shell_exec("mklink /J \"{$tmpdir}\\test.dir\" \"{$rootdir}home\\Public\\Desktop\"");
$file = "{$tmpdir}\\test.dir\\desktop.ini";
$rfile1 = realpath($file);
$rfile2 = realpath($rfile1);
printf("orig.file name: %s\n", $file);
printf("realpath(name): %s (%s)\n", $rfile1, $file == $rfile1 ? 'Ok' : 'fail');
printf("THE real name:  %s (%s)\n", $rfile2, $file == $rfile2 ? 'Ok' : 'fail');

rmdir("{$rootdir}home");
rmdir("{$tmpdir}\\test.dir");


Expected result:
----------------
According to pajoye@php.net, expansion shouldn't happen, and all paths must be the same == the original path.

Actual result:
--------------
All paths are different. On each iteration, realpath() only expands a portion of nested junctions.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-02 22:29 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-08-02 22:29 UTC] cmb@php.net
I can confirm this behavior. Obviously, the invariant

  realpath(realpath($x)) == realpath($x)

does not hold in this case.
 [2020-11-16 13:22 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-11-16 13:22 UTC] cmb@php.net
I had a closer look, but I'm not really sure how it is
supposed to work.  In bug #72642 pajoye said:

> This function solves symbolic link only, not junction, mount
> point or hard link.

However, that is not correct; actually, exactly one level of links
is resolved on Windows.

pajoye continues:

> and it is on purpose and by design. The same applies to other
> platforms with hard links for example.

I don't know how other platforms deal with this.  Apparently,
POSIX is not clear about this[1], but the ln man page[2] mentions
that hardlinked directories are usually not supported at all.

Anyhow, symlinked directories are not recursively resolved on
Windows (only one level like for hardlinked directories), and that
would be a bug.

[1] <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html>
[2] <https://man7.org/linux/man-pages/man1/ln.1.html>
 [2020-11-18 17:15 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-11-18 17:15 UTC] cmb@php.net
I talked with other members of the PHPonWindows team, and our
stance is to leave that as is.  The behavior should be documented,
of course.
 [2020-11-19 13:30 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-11-19 13:30 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=cfa78d6bb99348a6f898b133136bcfc256804b09
Log: Fix #72738: realpath() expands junction points
 [2020-11-20 20:00 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=f1d035d62ed389c9ea7c68b14c37ba56add609b9
Log: Fix #72738: realpath() expands junction points
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=2b71fee3ee6b76bfb9a554d69b29e206bf1da9bc
Log: Fix #72738: realpath() expands junction points
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 16:01:30 2024 UTC