php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77061 file_exists() race condition when used with symlinks
Submitted: 2018-10-25 19:14 UTC Modified: 2018-10-25 22:56 UTC
From: brandon dot jansen63 at gmail dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.6.38 OS: Windows 7/10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: brandon dot jansen63 at gmail dot com
New email:
PHP Version: OS:

 

 [2018-10-25 19:14 UTC] brandon dot jansen63 at gmail dot com
Description:
------------
If the following conditions are met:

1) Two simultaneous calls to file_exists() are made for the same file for which file_exists() would normally return TRUE,
2) The path given to file_exists() includes a directory which is a symlink (created with mklink /D),
3) PHP has not cached the real path of the file,

Then one of the calls to file_exists() may return FALSE while the other returns TRUE.

Test script:
---------------
<?php
echo "Starting...\r\n";

while( file_exists( 'C:\test_symlink\test.txt' ) )
{
    clearstatcache( true );
}

echo "You shouldn't see this message.\r\n";
?>

Expected result:
----------------
Assuming that a file "test.txt" has been created somewhere on the file system, and that the symlink C:\test_symlink has been created with the following command:

    mklink /D C:\test_symlink <path-to-test.txt-containing-folder>

Then when two instances of the test script are run in parallel, each should display the message "Starting..." and continue to run with no further output until manually terminated.

Actual result:
--------------
Each of the two instances of the test script displays "Starting...". However, after the second instance is started, one of the instances terminates with the message "You shouldn't see this message."

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-25 19:59 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-10-25 19:59 UTC] requinix@php.net
PHP 5.6 is not supported. Does this still happen with PHP 7.1 or later?
 [2018-10-25 20:24 UTC] brandon dot jansen63 at gmail dot com
-Status: Feedback +Status: Open
 [2018-10-25 20:24 UTC] brandon dot jansen63 at gmail dot com
I went back and tested this on PHP 7.1.23 and 7.2.6, and neither version showed the problem.
 [2018-10-25 22:56 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-10-25 22:56 UTC] requinix@php.net
Then that means the problem has been fixed in some form or another.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Sep 24 23:05:52 2022 UTC