From:             
Operating system: Linux
PHP version:      5.3.6
Package:          *Directory/Filesystem functions
Bug Type:         Bug
Bug description:incorrect accounting for realpath_cache_size

Description:
------------
When items are removed from the realpath_cache, if the path is the same as
the 

realpath, then the incorrect size is subtracted from realpath_cache_size.



This is due to the "realpath_cache_add" function. If the realpath and the
path are 

the same, then an optimization occurs where bucket->realpath is assigned to
the 

same location as bucket->path (so there's no copy being done). The size
added to 

realpath_cache_size takes this into account, but not when removing.



This can cause the size to be incorrect and also be negative.



I've submitted a patch and some test code.

Test script:
---------------
<?php



// set the ini options to more easily reproduce

// realpath_cache_ttl = 1

// realpath_cache_siz = 16K



for($i = 0; $i < 5000; $i++) {

    file_put_contents("/tmp/foo-$i.txt", "");

    clearstatcache(true, "/tmp/foo-$i.txt");

    echo "$i - stat cache is: ".realpath_cache_size()."\n";



    if(realpath_cache_size() < 0) {

        print "Hit realpath_cache_size bug\n";

        break;

    }

}



// clean up created files

for ($x = 0; $x < $i; $x++) {

    unlink("/tmp/foo-$x.txt");

}



Expected result:
----------------
If bug is present it should output 'Hit realpath_cache_size bug'




-- 
Edit bug report at http://bugs.php.net/bug.php?id=54866&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54866&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54866&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54866&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54866&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54866&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54866&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54866&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54866&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54866&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54866&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54866&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54866&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54866&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54866&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54866&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54866&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54866&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54866&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54866&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54866&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54866&r=mysqlcfg

Reply via email to