php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36320 Custom dir_readdir() causes readdir() to crash when returns false
Submitted: 2006-02-07 16:16 UTC Modified: 2006-02-08 00:44 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: Jared dot Williams1 at ntlworld dot com Assigned:
Status: Suspended Package: Streams related
PHP Version: 5.1.2 OS: Win2000
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 - 29 = ?
Subscribe to this entry?

 
 [2006-02-07 16:16 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-08 00:44 UTC] iliaa@php.net
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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Mar 18 17:01:28 2019 UTC