php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35567 DirectoryIterator segfaults after Notice
Submitted: 2005-12-06 07:45 UTC Modified: 2005-12-06 21:35 UTC
From: judas dot iscariote at gmail dot com Assigned: helly (profile)
Status: Not a bug Package: SPL related
PHP Version: 5CVS-2005-12-06 (CVS) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 49 = ?
Subscribe to this entry?

 
 [2005-12-06 07:45 UTC] judas dot iscariote at gmail dot com
Description:
------------
DirectoryIterator class is segfaulting after a Notice :

Notice - Object of class DirectoryIterator could not be converted to int ( registered in apache error_log before segfault)


Reproduce code:
---------------
$dirs =  new DirectoryIterator( 'dir' );

foreach(  $dirs as $entry ) {

 if($dirs->isDir($entry) && !$dirs->isDot($entry)){

                        $list[] = $entry;
                    }

                }

Expected result:
----------------
code executed correctly.

Actual result:
--------------
notice] child pid 16011 exit signal Segmentation fault (11)

can't get a backtrace :-(


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-06 07:49 UTC] judas dot iscariote at gmail dot com
php -v
PHP 5.1.2-dev (cgi) (built: Dec  6 2005 03:03:55) (DEBUG)
 [2005-12-06 08:47 UTC] judas dot iscariote at gmail dot com
if useful.. it is crashing with something like this..

$dirs =  new DirectoryIterator( $this->dirname );...

of course $this->dirname contains a **valid** directory path.
 [2005-12-06 08:49 UTC] judas dot iscariote at gmail dot com
$dirs =  new DirectoryIterator( $this->dirname() );

I mean... :-(
 [2005-12-06 10:02 UTC] helly@php.net
Several things:
- storing the output of an iterator in an array is most likely wrong. Instead use a FilterIterator to wrap the input iterator (DirectoryIterator in your case) and work on its result.

- $dirs = new DirectoryIterator($dirs->dirname()); pretty much sounds like an endless loop. *Which does crash*. Try using xdebug to detect such loops or simply place a var_dump() showing what you are creating the iterator on.

- It seems you are trying some kind of recursion. Use RecursiveIteratorIterator with RecursiveDirectoryIterator for that.

- To be able to give you a real answer i would need real code that crashes - short reproducing script.
 [2005-12-06 19:27 UTC] judas dot iscariote at gmail dot com
until I come with a test case I got this with valgrind..


==10761== Process terminating with default action of signal 11 (SIGSEGV)
==10761==  Access not within mapped region at address 0xD
==10761==    at 0x14393929: zend_std_object_get_class (zend_object_handlers.c:1002)
==10761==    by 0x1436F768: convert_to_long_base (zend_operators.c:342)
==10761==    by 0x14375466: compare_function (zend_operators.c:1341)
==10761==    by 0x14375AB8: is_equal_function (zend_operators.c:1474)
==10761==    by 0x142BABC3: ??? (array.c:1248)
==10761==    by 0x14397B55: ??? (zend_vm_execute.h:192)
==10761==    by 0x1439713F: execute (zend_vm_execute.h:92)
==10761==    by 0x1439C008: ??? (zend_vm_execute.h:4334)
==10761==    by 0x1439713F: execute (zend_vm_execute.h:92)
==10761==    by 0x1439C008: ??? (zend_vm_execute.h:4334)
==10761==    by 0x1439713F: execute (zend_vm_execute.h:92)
==10761==    by 0x14377A7F: zend_execute_scripts (zend.c:1101)
 [2005-12-06 20:17 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The backtrace suggest that as helly suggested you are triggering an unterminated loop resulting a crash. As such this is the expected behaviour.
 [2005-12-06 21:35 UTC] judas dot iscariote at gmail dot com
Ilia : I found you are right ,  sorry. and thanks for the fast response.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC