Bug #79486 [Com]: file_exists() returns true for a non-existing file

From: Date: Mon, 20 Apr 2020 08:57:13 +0000
Subject: Bug #79486 [Com]: file_exists() returns true for a non-existing file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226679@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79486&edit=1

 ID:                 79486
 Comment by:         m dot staab at complex-it dot de
 Reported by:        m dot staab at complex-it dot de
 Summary:            file_exists() returns true for a non-existing file
 Status:             Assigned
 Type:               Bug
 Package:            *General Issues
 Operating System:   windows10 x64
 PHP Version:        7.4.5
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

I did some more tests and can reproduce the issue also on php 7.2.30 and also on ubuntu18

not sure where the problem cause could be


Previous Comments:
------------------------------------------------------------------------
[2020-04-18 12:49:10] m dot staab at complex-it dot de

I dont have a buildenv on my workstation (and actually dont want to setup one).
Anything else I could do to to ahead?

I thought about downloading a 7.2 and/or 7.3 binary to test whether the issue was present before.

I could offer a teamviewer pairing session, so you can have a look at it right on the machine..

------------------------------------------------------------------------
[2020-04-18 10:41:31] cmb@php.net

Thanks for the further info!

Since this issue is obviously not easily reproducible, and I have
doubts that tracing with Process Monitor[1] will reveal the
underlying issue, I can only speculate.  As of PHP 7.4.0, the
stat() call (either explicitly or implictly) ends up in
php_win32_ioutil_fstat_int()[2], and given that that the uid and
gid members are not zero, it looks like your hitting the
_fstat64() fallback[3].  This code path uses _open_osfhandle(),
but apparently doesn't regard that "The _open_osfhandle call
transfers ownership of the Win32 file handle to the file
descriptor."[4]  If the documentation is correct, this might
indeed cause issues.

Would you have a PHP build environment[5] available, to do some
debugging, or trying out some potential fixes?  Otherwise I could
try to apply fixes, and provide pre-built binaries for testing,
but that would be somewhat tedious.

[1] <https://docs.microsoft.com/en-us/sysinternals/downloads/procmon>
[2] <https://github.com/php/php-src/blob/php-7.4.5/win32/ioutil.c#L860>
[3] <https://github.com/php/php-src/blob/php-7.4.5/win32/ioutil.c#L872-L888>
[4] <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=vs-2019>
[5] <https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2>

------------------------------------------------------------------------
[2020-04-18 06:47:54] m dot staab at complex-it dot de

Btw: I tried adding clearstatcache(true); right before the file_exists(), but this did not change
the result

------------------------------------------------------------------------
[2020-04-18 06:14:24] m dot staab at complex-it dot de

Not that I am aware of. 

C:\Users\mstaab\Documents\GitHub\kunzmann is a regular git checkout of a private github repo

I am wondering why its not reproducible with a 3 line script from within the same path

------------------------------------------------------------------------
[2020-04-17 17:30:56] cmb@php.net

>   ["uid"]=>
>  int(1000)
>  ["gid"]=>
>  int(1000)

Huh, that's interesting.  These values are supposed to be zero on
Windows.  Is there any reparse point (symlink, mounted volume, VFS
for Git etc.) involved in the path?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=79486


--
Edit this bug report at https://bugs.php.net/bug.php?id=79486&edit=1


Thread (17 messages)

« previous php.bugs (#226679) next »