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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 18:01:30 2024 UTC