|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31347 is_dir and is_file (incorrectly) return true for any string > 255 characters
Submitted: 2004-12-30 10:43 UTC Modified: 2005-12-20 15:28 UTC
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: gilad dot buzi at concatel dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5CVS, 4CVS (2005-03-06) OS: win32 only
Private report: No CVE-ID: None
 [2004-12-30 10:43 UTC] gilad dot buzi at concatel dot com
is_dir() and is_file() (incorrectly) return true for any string larger than 255 characters.

I tried this on two different machines, with the out of the box, precompiled/downloaded Windows version of php 5.0.3.  No changes were made to the standard php.ini-dist.  No extra extensions were loaded.  We are using PHP as an Apache2 module (php2apache2.dll).  We also tried the latest CVS snapshot (5CVS-2004-12-30 (dev)) and got the same results. 

We tried, and could NOT reproduce this on Linux.  It only failed on windows platforms.  

Curiously (or maybe not so curious), file_exists() DOES work fine. 

Reproduce code:
echo "myfilename is: $myfilename";
echo "<br>myfilename is ".strlen($myfilename)." characters long";
echo "<br>is_dir: ".is_dir($myfilename);
echo "<br>file_exists: ".file_exists($myfilename);
echo "<br>is_file: ".is_file($myfilename);

echo "<br><br>myfilename is: $myfilename";
echo "<br>myfilename is ".strlen($myfilename)." characters long";
echo "<br>is_dir: ".is_dir($myfilename);
echo "<br>file_exists: ".file_exists($myfilename);
echo "<br>is_file: ".is_file($myfilename);

Expected result:
is_dir() and is_file() should return false if the file or directory does not exist, regardless of the length of the string they are passed.

Actual result:
Result for above script is:
myfilename is: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccsssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccssssssssssssssssssssssssssssssssssssssssssssss
myfilename is 255 characters long

myfilename is: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccsssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccssssssssssssssssssssssssssssssssssssssssssssss
myfilename is 256 characters long
is_dir: 1
file_exists: 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-20 16:21 UTC] smith at backendmedia dot com
You can add file_exists() to the list of functions that have this error. I tested this with
 [2005-02-22 15:52 UTC]
Win32 specific bug, due to the stat() function not having handling in place for filenames >255 chars.
 [2005-10-11 05:45 UTC] nunbot at gmail dot com
I've seen this in 5.0.4 build 2600 using win32. Unfortunately the string length does not seem to matter at all on both is_dir() and is_file().
 [2005-12-20 15:28 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 21:01:29 2024 UTC