#36320 [Opn->Sus]: Custom dir_readdir() causes readdir() to crash when returns false

From: Date: Tue, 07 Feb 2006 23:44:23 +0000
Subject: #36320 [Opn->Sus]: Custom dir_readdir() causes readdir() to crash when returns false
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93026@lists.php.net to get a copy of this message
ID: 36320 Updated by: iliaa@php.net Reported By: Jared dot Williams1 at ntlworld dot com -Status: Open +Status: Suspended Bug Type: Streams related Operating System: Win2000 PHP Version: 5.1.2 New Comment: There is no easy fix for this problem inside PHP source code. The problem stems from PHP's shutdown order, where classes are destroyed prior to resources. The fix you can implement involves adding a missing clodedir() call to your script. Previous Comments: ------------------------------------------------------------------------ [2006-02-07 16:16:31] Jared dot Williams1 at ntlworld dot com Description: ------------ dir_readdir seems to cause a crash when used with readdir(). Code below is based on the \ext\standard\tests\file\userdirstream.phpt test, but instead of using scandir() which appears to work fine, the manual looping causes an application exception. Reproduce code: --------------- class test { public $idx = 0; function dir_opendir($path, $options) { print "Opening\n"; $this->idx = 0; return true; } function dir_readdir() { $sample = array('first','second','third','fourth'); if ($this->idx >= count($sample)) return false; else return $sample[$this->idx++]; } function dir_rewinddir() { $this->idx = 0; return true; } function dir_closedir() { print "Closing up!\n"; return true; } } stream_wrapper_register('test', 'test'); $dh = opendir('test://example.com/path/to/test'); if ($dh) { while (($f = readdir($dh)) !== FALSE) echo $f, "\n"; } Expected result: ---------------- Opening first second third fourth without an application exception Actual result: -------------- Opening first second third fourth with an application exception ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36320&edit=1

« previous php.bugs (#93026) next »