php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54384 Several SPL classes crash when parent constructor is not called
Submitted: 2011-03-25 21:34 UTC Modified: 2011-04-04 04:51 UTC
From: lbarnaud@php.net Assigned: cataphract
Status: Closed Package: SPL related
PHP Version: trunk-SVN-2011-03-25 (SVN) OS:
Private report: No CVE-ID:
 [2011-03-25 21:34 UTC] lbarnaud@php.net
Description:
------------
FilterIterator instances crash when the constructor has not been called 
(accidentally).



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

class Test extends FilterIterator {
    function __construct() {
    }
    function accept() {
    }
}

$t = new Test;
foreach($t as $e);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-25 22:32 UTC] lbarnaud@php.net
I wondered if other classes are be affected by this, and after some
tests I found that the following classes are affected:

IteratorIterator
FilterIterator
RecursiveFilterIterator
ParentIterator
LimitIterator
CachingIterator
RecursiveCachingIterator
NoRewindIterator
InfiniteIterator
RegexIterator
RecursiveRegexIterator
GlobIterator
SplFileObject
SplTempFileObject

tests:

<?php

class IteratorIteratorTest extends IteratorIterator {
    function __construct(){}
}
$o = new IteratorIteratorTest;
$o->rewind()

class FilterIteratorTest extends FilterIterator {
    function __construct(){}
    function accept(){}
}
$o = new FilterIteratorTest;
$o->rewind()

class RecursiveFilterIteratorTest extends RecursiveFilterIterator {
    function __construct(){}
    function accept(){}
}
$o = new RecursiveFilterIteratorTest;
$o->hasChildren()

class ParentIteratorTest extends ParentIterator {
    function __construct(){}
}
$o = new ParentIteratorTest;
$o->accept()

class LimitIteratorTest extends LimitIterator {
    function __construct(){}
}
$o = new LimitIteratorTest;
$o->rewind()

class CachingIteratorTest extends CachingIterator {
    function __construct(){}
}
$o = new CachingIteratorTest;
$o->rewind()

class RecursiveCachingIteratorTest extends RecursiveCachingIterator {
    function __construct(){}
}
$o = new RecursiveCachingIteratorTest;
$o->rewind()

class NoRewindIteratorTest extends NoRewindIterator {
    function __construct(){}
}
$o = new NoRewindIteratorTest;
$o->valid()

class InfiniteIteratorTest extends InfiniteIterator {
    function __construct(){}
}
$o = new InfiniteIteratorTest;
$o->next()

class RegexIteratorTest extends RegexIterator {
    function __construct(){}
}
$o = new RegexIteratorTest;
$o->rewind()

class RecursiveRegexIteratorTest extends RecursiveRegexIterator {
    function __construct(){}
}
$o = new RecursiveRegexIteratorTest;
$o->hasChildren()

class GlobIteratorTest extends GlobIterator {
    function __construct(){}
}
$o = new GlobIteratorTest;
$o->count()

class SplFileObjectTest extends SplFileObject {
    function __construct(){}
}
$o = new SplFileObjectTest;
$o->rewind()

class SplTempFileObjectTest extends SplTempFileObject {
    function __construct(){}
}
$o = new SplTempFileObjectTest;
$o->rewind()
 [2011-03-25 22:43 UTC] felipe@php.net
-Summary: FilterIterator crashes when constructor not called +Summary: Several SPL iterator classes crashes when constructor not called
 [2011-03-26 00:25 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2011-03-27 06:11 UTC] cataphract@php.net
-Summary: Several SPL iterator classes crashes when constructor not called +Summary: Several SPL classes crash when parent constructor is not called
 [2011-03-27 06:21 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=309729
Log: - Fixed bug #54384: Several SPL classes crash when parent constructor is
  not called.
#Merge to 5.3 pending (slight BC break on AppendIterator, as it's no
#longer possible to defer the call to the parent constructor until
#after the constructor is performed).
#Bugs fixed in an atypical way for SPL. The parent constructor call
#check is performed at construction time by using a wrapper constructor
#instead of a check on the beginning of each instance method.
#Perhaps this should be uniformized in trunk; this method was mainly
#applied only to the ones crashing, except a few iterators (at least
#AppendIterator and RecursiveIteratorIterator).
 [2011-03-28 00:44 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=309751
Log: - Improved upon r309729.
- Extented strategy to remaining the classes on spl_directory.c, even those that don't crash.
- UPGRADING.
- Better bug54384.phpt, with all the classes covered.
 [2011-04-04 04:50 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=309929
Log: - Fixed bug #54384 (Dual iterators, GlobIterator, SplFileObject and
  SplTempFileObject crash when user-space classes don't call the paren
  constructor).
 [2011-04-04 04:51 UTC] cataphract@php.net
-Status: Assigned +Status: Closed
 [2011-04-04 04:51 UTC] cataphract@php.net
Commited (different) fix in 5.3.
 [2011-10-29 23:17 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=318566
Log: - Reverted changes that required constructor overrides to invoke the parent
  constructor in several SPL classes and applied 5.3 fixes instead.
  Related bugs: #54384, #55175 and #55300
 [2012-03-19 21:39 UTC] maciej dot sz at gmail dot com
This bug is still present in 5.4.0
Should I report this as separate bug?
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 03:02:48 2014 UTC