php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50024 basename() chops first character in filename
Submitted: 2009-10-27 18:47 UTC Modified: 2009-11-11 01:00 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: peo at bsdlabs dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2.11 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: peo at bsdlabs dot com
New email:
PHP Version: OS:

 

 [2009-10-27 18:47 UTC] peo at bsdlabs dot com
Description:
------------
The platform is: 
FreeBSD 7.2-STABLE #0: Thu Oct 15 07:23:17 CEST 2009
- Problem not tied to a specific version of OS or PHP
- Vanilla installation of Horde http://www.horde.org
- Identical problem present on two servers
- Problem started to occur spring 2009
- Low server load
- Intermittent
- Comes and goes at certain times during the day. Usually, the problem will start around 11:30 CEST or 10:30 CET, last for 24h and then go away for another 24h.
	And yes, we have looked for causes for this behaviour
- Happens regardless of cache configuration in Horde, even without any caching
- Happens regardless of cache and session settings in php.ini
- The below is an *example*
- One more user on the Horde lists have reported same problem with same OS (FreeBSD)

Reproduce code:
---------------
    function factory($driver, $params = array())
    {
        if (is_array($driver)) {
            $app = $driver[0];
            $driver = $driver[1];
        }
        $driver = basename($driver);
        if (empty($driver) || $driver == 'none') {
            return new Horde_Cache($params);
        }
        if (!empty($app)) {
            include_once $app . '/lib/Cache/' . $driver . '.php';
        } elseif (file_exists(dirname(__FILE__) . '/Cache/' . $driver . '.php')) {
            include_once dirname(__FILE__) . '/Cache/' . $driver . '.php';
        } else {
            include_once 'Horde/Cache/' . $driver . '.php';
        }
        $class = 'Horde_Cache_' . $driver;
        if (class_exists($class)) {
            $cache = new $class($params);
        } else {
            $cache = PEAR::raiseError('Class definition of ' . $class . ' not found.');
        }
        return $cache;
    }

Expected result:
----------------
Should return memcache.php in this case, but it could be "none.php" (where the actual output will be "one.php")

Actual result:
--------------
[21-Oct-2009 07:28:28] after basename d string(8) "memcache"
string(7) "emcache"

[21-Oct-2009 07:28:28] backtrace NULL
string(7) "emcache"
#0  Horde_Cache->factory(memcache, Array ([hostspec] => Array ([0] => localhost),[port] => Array ([0] => 11211),[weight] => Array (),[persistent] => ,[compression] => ,[large_items] => 1,[enabled] => 1)) called at [/usr/local/www/horde/lib/Horde/Cache.php:234]
#1  Horde_Cache->singleton(memcache, Array ([hostspec] => Array ([0] => localhost),[port] => Array ([0] => 11211),[weight] => Array (),[persistent] => ,[compression] => ,[large_items] => 1,[enabled] => 1)) called at [/usr/local/www/horde/lib/Horde/Perms/sql.php:57]
#2  Perms_sql->Perms_sql(Array ([username] => horde,[password] => <password>,[protocol] => unix,[database] => horde,[charset] => iso-8859-1,[splitread] => ,[ssl] => ,[phptype] => mysqli)) called at [/usr/local/www/horde/lib/Horde/Perms.php:462]
#3  Perms->factory(sql, Array ([username] => horde,[password] => <password>,[protocol] => unix,[database] => horde,[charset] => iso-8859-1,[splitread] => ,[ssl] => ,[phptype] => mysqli)) called at [/usr/local/www/horde/lib/Horde/Perms.php:496]
#4  Perms->singleton() called at [/usr/local/www/horde/lib/Horde/Registry.php:278]
#5  Registry->Registry(0) called at [/usr/local/www/horde/lib/Horde/Registry.php:139]
#6  Registry::singleton() called at [/usr/local/www/horde/imp/lib/base.php:49]
#7  require_once(/usr/local/www/horde/imp/lib/base.php) called at [/usr/local/www/horde/imp/redirect.php:89]
#8  require(/usr/local/www/horde/imp/redirect.php) called at [/usr/local/www/horde/imp/index.php:26]
NULL

[21-Oct-2009 07:28:28] PHP Warning:  include_once(Horde/Cache/emcache.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /usr/local/www/horde/lib/Horde/Cache.php on line 194
[21-Oct-2009 07:28:28] PHP Warning:  include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Horde/Cache/emcache.php' for inclusion (include_path='/usr/local/www/horde/lib:.:/usr/local/share/pear') in /usr/local/www/horde/lib/Horde/Cache.php on line 194
[21-Oct-2009 07:28:39] after basename d string(8) "memcache"
string(7) "emcache"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-03 10:39 UTC] jani@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2009-11-04 19:01 UTC] peo at bsdlabs dot com
We are still trying to invent a script that reproduces the error.
The below is what we hoped would do it but it does not so it needs further refinement.

The error occurs when "basename" is fed a filename without path and once in several hundred the first character is missing.

And finally, it comes and goes, like this:

[27-Oct-2009 10:27:22] goes
[28-Oct-2009 00:26:55] comes
[28-Oct-2009 23:28:47] goes (summertime ends)
[30-Oct-2009 00:23:00] comes
[31-Oct-2009 11:40:10] goes
[02-Nov-2009 00:24:10] comes
[03-Nov-2009 11:34:41] goes
[04-Nov-2009 00:27:41] comes
[04-Nov-2009 11:28:55] goes


<?php
  $driver='memcached';
  for ($i=0;$i<500000000;$i++)
  {
    $driver=basename($driver);
    if($driver != 'memcached') echo $driver."\n";
    sleep(1);
  }
  echo "end\n";
?>
 [2009-11-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 20 17:01:21 2019 UTC