|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48814 Subclass of RecursiveDirectoryIterator segfaults with custom constructor
Submitted: 2009-07-06 11:59 UTC Modified: 2012-11-16 19:33 UTC
From: dennis at born05 dot nl Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.2.10, 5.3.0 OS: Fedora Core 6
Private report: No CVE-ID: None
 [2009-07-06 11:59 UTC] dennis at born05 dot nl
When you subclass RecursiveDirectoryIterator and override the 
constructor with enhanced functionality it makes PHP segfault.

I have tested this on 5.2.10 and 5.3.0, both display similar (but not 
equal) behaviour, the output is somewhat different, but both versions 

Reproduce code:
class MyRDI extends RecursiveDirectoryIterator
	public $base_path;
	public function __construct($path, $flags = 0)
		$this->base_path = $path;
		parent::__construct($path, $flags);

$iterator = new RecursiveIteratorIterator(new MyRDI('/path/to/dir/hierarchy'));
foreach($iterator as $entry)
	echo $entry->getFilename()."\n";

Expected result:
See a list of all the filenames

Actual result:
PHP segfaults


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-06 12:00 UTC] dennis at born05 dot nl
Applies for 5.2.10 AND 5.3.0
 [2009-07-20 22:01 UTC]
HEAD works fine.

5.2 and 5.3 segfaults:

(gdb) bt
#0  0x08412082 in _zval_ptr_dtor (zval_ptr=0xa37dc0f, __zend_filename=0x87bbafc "/home/felipe/dev/php5/Zend/zend_variables.c", 
    __zend_lineno=175) at /home/felipe/dev/php5/Zend/zend.h:391
#1  0x08421c68 in _zval_ptr_dtor_wrapper (zval_ptr=0xa37dc10) at /home/felipe/dev/php5/Zend/zend_variables.c:175
#2  0x08434493 in zend_hash_destroy (ht=0xa37db58) at /home/felipe/dev/php5/Zend/zend_hash.c:526
#3  0x0844d749 in zend_object_std_dtor (object=0xa38460c, tsrm_ls=0xa22d070) at /home/felipe/dev/php5/Zend/zend_objects.c:45
#4  0x0827ddff in spl_filesystem_object_free_storage (object=0xa38460c, tsrm_ls=0xa22d070) at /home/felipe/dev/php5/ext/spl/spl_directory.c:81
#5  0x08453566 in zend_objects_store_del_ref_by_handle_ex (handle=5, handlers=0x87d0e40, tsrm_ls=0xa22d070)
    at /home/felipe/dev/php5/Zend/zend_objects_API.c:220
#6  0x08453138 in zend_objects_store_del_ref (zobject=0xa37d78c, tsrm_ls=0xa22d070) at /home/felipe/dev/php5/Zend/zend_objects_API.c:172
#7  0x0842185b in _zval_dtor_func (zvalue=0xa37d78c, __zend_filename=0x87ba958 "/home/felipe/dev/php5/Zend/zend_execute_API.c", 
    __zend_lineno=435) at /home/felipe/dev/php5/Zend/zend_variables.c:52
---Type <return> to continue, or q <return> to quit---
#8  0x08411d2c in _zval_dtor (zvalue=0xa37d78c, __zend_filename=0x87ba958 "/home/felipe/dev/php5/Zend/zend_execute_API.c", __zend_lineno=435)
    at /home/felipe/dev/php5/Zend/zend_variables.h:35
#9  0x08412111 in _zval_ptr_dtor (zval_ptr=0xa387cd0, __zend_filename=0x876bf7c "/home/felipe/dev/php5/ext/spl/spl_iterators.c", 
    __zend_lineno=352) at /home/felipe/dev/php5/Zend/zend_execute_API.c:435
#10 0x0826e5d7 in spl_recursive_it_move_forward_ex (object=0xa37c814, zthis=0xa37bf40, tsrm_ls=0xa22d070)
    at /home/felipe/dev/php5/ext/spl/spl_iterators.c:352
#11 0x0826e888 in spl_recursive_it_move_forward (iter=0xa37d5b4, tsrm_ls=0xa22d070) at /home/felipe/dev/php5/ext/spl/spl_iterators.c:387
#12 0x0847bba4 in ZEND_FE_FETCH_SPEC_VAR_HANDLER (execute_data=0xa3ab6a4, tsrm_ls=0xa22d070)
    at /home/felipe/dev/php5/Zend/zend_vm_execute.h:8894
#13 0x0845647b in execute (op_array=0xa37f748, tsrm_ls=0xa22d070) at /home/felipe/dev/php5/Zend/zend_vm_execute.h:104
#14 0x084252c2 in zend_execute_scripts (type=8, tsrm_ls=0xa22d070, retval=0x0, file_count=3) at /home/felipe/dev/php5/Zend/zend.c:1188

 [2012-11-16 19:33 UTC]
-Status: Assigned +Status: Closed
 [2012-11-16 19:33 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC