Bug #36365 [Asn]: scandir duplicates file name at every 65535th file
| From: | cmb@php.net | Date: | Sun, 07 Jun 2015 23:51:19 +0000 |
| Subject: | Bug #36365 [Asn]: scandir duplicates file name at every 65535th file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193186@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=36365&edit=1
ID: 36365
Updated by: cmb@php.net
Reported by: pilhoon at gmail dot com
Summary: scandir duplicates file name at every 65535th file
Status: Assigned
Type: Bug
Package: Directory function related
Operating System: windows
PHP Version: *
Assigned To: pajoye
Block user comment: N
Private report: N
New Comment:
The problem is in readdir_r()[1]. If dp->offset != 0
FindNextFile() is called, then dp->offset is increased. Finally,
the directory entry is composed and "returned". However,
dp->offset is a short int[2], so once for every 65535 entries
FindNextFile() is not called, but a directory entry is added
nonetheless. Furthermore, dp->dent.d_off is not correct for high
values.
[1] <https://github.com/php/php-src/blob/php-5.6.9/win32/readdir.c#L92-L118>
[2] <https://github.com/php/php-src/blob/php-5.6.9/win32/readdir.h#L35>
Previous Comments:
------------------------------------------------------------------------
[2012-09-08 03:24:40] gobie at centrum dot cz
Same problem reproduced
PHP Version 5.4.4 Windows 7 x64
PHP Version 5.3.13 Windows 7 x32
But all PHP methods listing files are affected scandir, glob, DirectoryIterator.
Reproduce code:
---------------
// Settings
$dir = './test/';
$totalFiles = 1e5;
// Create empty files
!is_dir($dir) && mkdir($dir);
for ($i = 0; $i < $totalFiles; ++$i) {
$filename = $dir . str_pad($i, 6, '0', STR_PAD_LEFT);
touch($filename);
}
// Glob
$files = glob($dir . '*');
echo 'glob: ' . count($files) . '/' . $totalFiles . PHP_EOL;
// Scandir
$files = scandir($dir);
echo 'scandir: ' . (count($files) - 2) . '/' . $totalFiles . PHP_EOL; // . and
..
// DirectoryIterator
$it = new DirectoryIterator($dir);
echo 'DirectoryIterator: ' . (iterator_count($it) - 2) . '/' . $totalFiles .
PHP_EOL; // . and ..
unset($it);
Expected result:
----------------
glob: 100000/100000
scandir: 100000/100000
DirectoryIterator: 100000/100000
Actual result:
--------------
glob: 100001/100000
scandir: 100001/100000
DirectoryIterator: 100001/100000
------------------------------------------------------------------------
[2010-01-15 01:00:01] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2010-01-07 18:26:21] pajoye@php.net
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2010-01-07 18:02:51] enzo at smshome dot net
Same problem here using PHP Version 5.2.5 (x64) with Windows XP 64bit Professional Edition.
Duplicated files every 65535 files read using scandir(). I think you should put an alert on manual
page:
http://php.net/manual/en/function.scandir.php
------------------------------------------------------------------------
[2006-02-19 01:00:04] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=36365
--
Edit this bug report at https://bugs.php.net/bug.php?id=36365&edit=1