From: ivan dot enderlin at hoa-project dot net
Operating system:
PHP version: 5.5.0
Package: SPL related
Bug Type: Bug
Bug description:RecursiveDirectoryIterator segfault
Description:
------------
The following code adds the relativePath data on SplClassInfo object
returned by the RecursiveDirectoryIterator. This is a simple extension, no
tricky things.
You need at least some subdirectories with files to reproduce the bug.
Test script:
---------------
<?php
namespace Bug {
class Directory extends \RecursiveDirectoryIterator {
protected $_splFileInfoClass = null;
protected $_relativePath = null;
public function __construct ( $path, $flags = null, $splFileInfoClass =
null ) {
if(null === $flags)
parent::__construct($path);
else
parent::__construct($path, $flags);
$this->setSplFileInfoClass($splFileInfoClass);
$this->setRelativePath($path);
return;
}
public function current ( ) {
$out = parent::current();
if( null !== $this->_splFileInfoClass
&& $out instanceof \SplFileInfo) {
$out->setInfoClass($this->_splFileInfoClass);
$out = $out->getFileInfo();
if($out instanceof SplFileInfo)
$out->setRelativePath($this->getRelativePath());
}
return $out;
}
public function getChildren ( ) {
$out = parent::getChildren();
$out->setRelativePath($this->getRelativePath());
if($out instanceof \RecursiveDirectoryIterator)
$out->setSplFileInfoClass($this->_splFileInfoClass);
return $out;
}
public function setSplFileInfoClass ( $splFileInfoClass ) {
$this->_splFileInfoClass = $splFileInfoClass;
return;
}
public function setRelativePath ( $path ) {
$this->_relativePath = $path;
return;
}
public function getRelativePath ( ) {
return $this->_relativePath;
}
}
class SplFileInfo extends \SplFileInfo {
protected $_relativePath = null;
public function __construct ( $filename, $relativePath = null ) {
parent::__construct($filename);
$this->_relativePath = $relativePath;
return;
}
public function setRelativePath ( $relativePath ) {
$old = $this->_relativePath;
$this->_relativePath = $relativePath;
return $old;
}
public function getRelativePath ( ) {
return $this->_relativePath;
}
public function getRelativePathname ( ) {
if(null === $relative = $this->getRelativePath())
return $this->getPathname();
return substr($this->getPathname(), strlen($relative));
}
}
}
namespace {
$finder = new Bug\Directory('/tmp');
$finder->setSplFileInfoClass('Bug\SplFileInfo');
foreach(new \RecursiveIteratorIterator($finder) as $entry)
var_dump($entry->getRelativePathname());
}
Expected result:
----------------
relative pathnames printed.
Actual result:
--------------
segfault.
--
Edit bug report at https://bugs.php.net/bug.php?id=65136&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65136&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65136&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65136&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65136&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65136&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65136&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65136&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65136&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65136&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65136&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65136&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65136&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65136&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65136&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65136&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65136&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65136&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65136&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65136&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65136&r=mysqlcfg