Bug #77061 [NEW]: file_exists() race condition when used with symlinks
| From: | brandon dot jansen63 at gmail dot com | Date: | Thu, 25 Oct 2018 19:14:24 +0000 |
| Subject: | Bug #77061 [NEW]: file_exists() race condition when used with symlinks | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-217684@lists.php.net to get a copy of this message | ||
From: brandon dot jansen63 at gmail dot com
Operating system: Windows 7/10
PHP version: 5.6.38
Package: *Directory/Filesystem functions
Bug Type: Bug
Bug description:file_exists() race condition when used with symlinks
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."
--
Edit bug report at https://bugs.php.net/bug.php?id=77061&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77061&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77061&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77061&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77061&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77061&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77061&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77061&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77061&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77061&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77061&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77061&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77061&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77061&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77061&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77061&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77061&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77061&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77061&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77061&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77061&r=mysqlcfg