PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_FTP » Bug #4836

Off-by-one error in regex for Windows directory listings

Details

Submitted2005-07-14 22:57 UTC
Fromjeffg at interkey dot net
Assignedtoby
StatusClosed
PackageNet_FTP
PHP Version4.3.11
OSWindows 2000 Server
Roadmaps(Not assigned)

Comments

[2005-07-14 22:57 UTC] jeffg at interkey dot net

Description:
------------
When attempting to obtain a directory listing from a Windows FTP server via ls(), the regular expression assigns the string value "<DIR>" to the is_dir attribute of the file's entry in the listing. Unfortunately, the regular expression is structured in such a way that it captures the filesize if the file is not a directory, and any file with a size greater than zero is erroneously tagged as being a directory. This obviously mucks up getRecursive() when the function attempts to descend into a directory that is actually a file.

Reproduce code:
---------------
The original code, at line 576, is as follows:

'windows' => array(
'pattern' => '/(.+)\s+(.+)\s+((<DIR>)|[0-9]+)\s+(.+)/',
'map' => array('name'=>5,'date'=>1,'is_dir'=>3)
)

3 is an inappropriate match, as it captures either <DIR> or the filesize. It should be match number 4, the (<DIR>) inside match number 3:

'windows' => array(
'pattern' => '/(.+)\s+(.+)\s+((<DIR>)|[0-9]+)\s+(.+)/',
'map' => array('name'=>5,'date'=>1,'is_dir'=>4)
)