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

From: Date: Mon, 20 Apr 2020 14:10:31 +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-226687@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:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   *
 PHP Version:        7.3
 Block user comment: N
 Private report:     N

 New Comment:

for whatever reason, I have the feeling php is mixing up

    /cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php

with

    /cluster/www/www/www/kunzmann/app/shop/controllers/KMAccountController.php



/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php
is a totally valid path and the file exists.


Previous Comments:
------------------------------------------------------------------------
[2020-04-20 09:19:26] m dot staab at complex-it dot de

I reproduce the error on ubuntu18 with php 7.2 with the following commands:

$ GITHUB_ACTION=1 php vendor/bin/php-cs-fixer fix -vvv
string(75) "clxKunzmann=>/cluster/www/www/www/kunzmann/app/shared/lib/clxKunzmann.php
1"
string(105)
"CmsContext=>/cluster/www/www/www/kunzmann/vendor/plugins/rocket/builtin/models/modulecms/CmsContext.php
1"
string(93)
"cms\ViewTypeProvider=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/ViewTypeProvider.php
1"
string(77) "cms\ViewType=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/ViewType.php
1"
string(83)
"cms\UrlProvider=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/UrlProvider.php 1"
string(113)
"CmsUrlProvider=>/cluster/www/www/www/kunzmann/vendor/plugins/rocket/builtin/models/modulecms/CmsUrlProvider.php
1"
string(119)
"CmsModuleMetaData=>/cluster/www/www/www/kunzmann/vendor/plugins/rocket/builtin/models/modulecms/CmsModuleMetaData.php
1"
string(95)
"cms\metadata\shop\Usp=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/shop/Usp.php
1"
string(109)
"cms\metadata\ModuleMetaTrait=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/ModuleMetaTrait.php
1"
string(128)
"CmsInputTypeText=>/cluster/www/www/www/kunzmann/vendor/plugins/rocket/builtin/models/modulecms/inputtypes/CmsInputTypeText.php
1"
string(109)
"CmsInputType=>/cluster/www/www/www/kunzmann/vendor/plugins/rocket/builtin/models/modulecms/CmsInputType.php
1"
string(99)
"cms\metadata\Navigation=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Navigation.php
1"
string(85)
"cms\metadata\Gap=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Gap.php 1"
string(97)
"cms\metadata\Accordion=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Accordion.php
1"
string(105)
"cms\metadata\Contactperson=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Contactperson.php
1"
string(95)
"cms\metadata\Carousel=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Carousel.php
1"
string(111)
"cms\metadata\ImageMultiColumn=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/ImageMultiColumn.php
1"
string(101)
"cms\metadata\Vehiclelist=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Vehiclelist.php
1"
string(115)
"cms\metadata\VehicleQuickSearch=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/VehicleQuickSearch.php
1"
string(101)
"cms\metadata\Contactform=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Contactform.php
1"
string(89)
"cms\metadata\Brand=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Brand.php
1"
string(93)
"cms\metadata\Masonry=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Masonry.php
1"
string(105)
"cms\metadata\Testdriveform=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Testdriveform.php
1"
string(101)
"cms\metadata\Productlist=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Productlist.php
1"
string(105)
"cms\metadata\Productrating=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Productrating.php
1"
string(105)
"cms\metadata\Productslider=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Productslider.php
1"
string(91)
"cms\metadata\Slider=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Slider.php
1"
string(95)
"cms\metadata\Location=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Location.php
1"
string(87)
"cms\metadata\Text=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Text.php
1"
string(103)
"cms\metadata\TextAndImage=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/TextAndImage.php
1"
string(109)
"cms\metadata\TextMultiColumn=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/TextMultiColumn.php
1"
string(93)
"cms\metadata\Divider=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Divider.php
1"
string(93)
"cms\metadata\Heading=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Heading.php
1"
string(89)
"cms\metadata\Video=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Video.php
1"
string(95)
"cms\metadata\Benefits=>/cluster/www/www/www/kunzmann/app/shared/lib/cms/metadata/Benefits.php
1"
string(79) "ClxShopPortal=>/cluster/www/www/www/kunzmann/app/shared/lib/ClxShopPortal.php
1"
Loaded config default from "/cluster/www/www/www/kunzmann/.php_cs.dist".
Using cache file ".php_cs.cache".
string(92)
"KMAccountController=>/cluster/www/www/www/kunzmann/app/shop/models/KMAccountController.php
1"

Fatal error: require_once(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shop/models/KMAccountController.php'
(include_path='.:/usr/share/php') in /cluster/www/www/www/kunzma                          
                                     nn/vendor/plugins/rocket/lib/Rocket.php on line 313
string(82) "CacheMemcached=>/cluster/www/www/www/kunzmann/app/shop/models/CacheMemcached.php
1"

Fatal error: require_once(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shop/models/CacheMemcached.php'
(include_path='.:/usr/share/php') in /cluster/www/www/www/kunzmann/ve                     
                                          ndor/plugins/rocket/lib/Rocket.php on line 313


the php code(parts) which trigger the output and the error is
// snip
        /*
         * The include mechanism over all paths
         */
        foreach ([
            self::$model_paths,
            self::$lib_paths,
            self::$helper_paths,
            self::$controller_paths,
            self::$plugin_paths,
        ] as $paths) {
            foreach ($paths as $path => $dummyVal) {
                if (file_exists($path.DIRECTORY_SEPARATOR.$file)) {
                    self::$classMap[$class_name] = $path.DIRECTORY_SEPARATOR.$file;

                    break 2;
                }
            }
        }

        // trigger cache re-newal, but only once per request
        if (!self::$shutdownRegistered) {
            self::$shutdownRegistered = true;
            register_shutdown_function([
                __CLASS__,
                'storeCache',
            ]);
        }

        // require the already validated path
        if (isset(self::$classMap[$class_name])) {
            clearstatcache(true);
            var_dump($class_name . '=>'. self::$classMap[$class_name] . ' '.
file_exists(self::$classMap[$class_name]));
            require_once self::$classMap[$class_name];

            return true;
        }
        // Remember that this class does not exist.
        self::$missingClassMap[$class_name] = true;
// snip


the strace of the command GITHUB_ACTION=1 sudo strace php vendor/bin/php-cs-fixer fix -vvv
2> strace.out can be found here: https://gist.github.com/clxmstaab/3773f5e76cd1b266b2b7b952ddd177d6

------------------------------------------------------------------------
[2020-04-20 09:09:49] cmb@php.net

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

Then strace might be helpful.

------------------------------------------------------------------------
[2020-04-20 08:57:13] m dot staab at complex-it dot de

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

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

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


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 (#226687) next »