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

From: Date: Wed, 17 Jun 2020 18:13:44 +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-227528@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:         alexdowad@php.net
 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:

Thanks for reporting this issue.

I think the best thing you can do is:

1. Make a copy of the entire application source code in another directory.
2. Delete some code which is not related to the problem.
3. Test to see if the modified application still exhibits the problem.
4A. If so, go to step 2.
4B. If not, revert the change. Go to step 2 but try deleting something different this time.

After you repeat that loop maybe 100 times, you will have a small test file which exhibits the
problem. Almost all the proprietary code from your application will be gone, so it won't hurt
anything to share that test file, and then the PHP developers can find and fix the problem.

I have done this myself multiple times. It doesn't take as long as it sounds.


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

if relevant: here is the result of the "stat" command when executed via php on ubuntu18lts


php -v
PHP 7.2.30-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Apr 19 2020 07:50:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.30-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend
Technologies


$ tail /www/www/logs/php_errors.log
[24-Apr-2020 11:37:07 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/admin/models/Filter.php'
(include_path='.:/usr/share/php') in /c                                                   
            luster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php on line 53
[24-Apr-2020 11:37:11 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/admin/models/Filter.php'
(include_path='.:/usr/share/php') in /c                                                   
            luster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php on line 53
[24-Apr-2020 11:38:09 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php'
(include_path='.:/us                                                               
r/share/php') in /cluster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php
on line 53
[24-Apr-2020 11:38:24 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php'
(include_path='.:/us                                                               
r/share/php') in /cluster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php
on line 53
[24-Apr-2020 11:39:44 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php'
(include_path='.:/us                                                               
r/share/php') in /cluster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php
on line 53
[24-Apr-2020 11:40:09 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php'
(include_path='.:/us                                                               
r/share/php') in /cluster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php
on line 53
[24-Apr-2020 11:40:21 Europe/Berlin] PHP Fatal error:  require(): Failed opening required
'/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php'
(include_path='.:/us                                                               
r/share/php') in /cluster/www/www/www/kunzmann/vendor/symfony/class-loader/MapClassLoader.php
on line 53
mstaab@mst18:/cluster/www/www/www/kunzmann$ ls
/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php
/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php

php -r
'var_dump(stat("/cluster/www/www/www/kunzmann/app/shared/controllers/KMAccountController.php"));'
array(26) {
  [0]=>
  int(51)
  [1]=>
  int(4474739)
  [2]=>
  int(33279)
  [3]=>
  int(1)
  [4]=>
  int(11226)
  [5]=>
  int(12128)
  [6]=>
  int(0)
  [7]=>
  int(23570)
  [8]=>
  int(1587720923)
  [9]=>
  int(1585235276)
  [10]=>
  int(1587720894)
  [11]=>
  int(262144)
  [12]=>
  int(48)
  ["dev"]=>
  int(51)
  ["ino"]=>
  int(4474739)
  ["mode"]=>
  int(33279)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(11226)
  ["gid"]=>
  int(12128)
  ["rdev"]=>
  int(0)
  ["size"]=>
  int(23570)
  ["atime"]=>
  int(1587720923)
  ["mtime"]=>
  int(1585235276)
  ["ctime"]=>
  int(1587720894)
  ["blksize"]=>
  int(262144)
  ["blocks"]=>
  int(48)
}

------------------------------------------------------------------------
[2020-04-20 14:10:31] m dot staab at complex-it dot de

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.

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

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


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