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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 05:01:29 2024 UTC