php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65136 RecursiveDirectoryIterator segfault
Submitted: 2013-06-26 16:46 UTC Modified: -
From: ivan dot enderlin at hoa-project dot net Assigned:
Status: Closed Package: SPL related
PHP Version: 5.5.0 OS:
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: ivan dot enderlin at hoa-project dot net
New email:
PHP Version: OS:

 

 [2013-06-26 16:46 UTC] ivan dot enderlin at hoa-project dot net
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-26 16:49 UTC] ivan dot enderlin at hoa-project dot net
The segfault is cause by the second instruction in the getChildren() method.
 [2013-06-27 04:38 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fa8611c81ee72839cdff3e72b18cc586feb4aa29
Log: Fixed bug #65136 (RecursiveDirectoryIterator segfault)
 [2013-06-27 04:38 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2014-10-07 23:18 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=fa8611c81ee72839cdff3e72b18cc586feb4aa29
Log: Fixed bug #65136 (RecursiveDirectoryIterator segfault)
 [2014-10-07 23:29 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=fa8611c81ee72839cdff3e72b18cc586feb4aa29
Log: Fixed bug #65136 (RecursiveDirectoryIterator segfault)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC