php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42096 is_dir() truncates dirs when using UNC paths
Submitted: 2007-07-25 08:48 UTC Modified: 2009-12-24 01:00 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: michael202 at gmx dot de Assigned: pajoye (profile)
Status: No Feedback Package: Streams related
PHP Version: 5.2* OS: win32 only - Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-07-25 08:48 UTC] michael202 at gmx dot de
Description:
------------
calling is_dir() with an UNC path truncates each part of the path. The last character is missing.

This results in unnecessary errors (on the host side) and slowdowns (on client side).


Reproduce code:
---------------
windows only (php 5.2.3, Windows XP with cmd.exe) and linux host.

<?php
$p = '\\hostA\volumeB\dirC';
echo(is_dir($p) . "\n");

and then trace network IO for service/port SMB.

Beware of posssible side effects though caching of SMB connections

Expected result:
----------------
no error messages in /var/log/messages on 'hostA'

Actual result:
--------------
I traced these SMB Commands sent over the network:

Connect AndX Request \\hostA\IPC$
Connect AndX Request \\hostA\volume -> STATUS_BAD_NETWORK_NAME
FindFirst2, Pattern: \dir

these are in /var/log/messages in 'hostA'
  ... smbd/service.c:make_connection(252)
  ... couldn't find service volume




I think this is another problem with tsrm_virtual_cwd.c where around line 500 state_cwd_length is set to 2 if a slash is found at the beginning. Perhaps the existence of UNC paths is not checked for.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-25 14:43 UTC] michael202 at gmx dot de
tested with php5.2-win32-latest.zip
from today morning 2007-07-25 08h08

error is still in there
 [2007-08-08 09:09 UTC] michael202 at gmx dot de
running a script that makes a few thousand accesses to a samba server (that is used by approx. 30 other hosts) causes this server to "crash" and dismount the samba share.
 [2007-08-31 10:04 UTC] jani@php.net
As is_dir() uses stat to check whether passed path is directory or not I doubt this can really be any PHP bug, just another limitiation of Windows. Try doing the same using something else than PHP and I bet the result is the same.

And this is totally bogus: echo(is_dir($p) . "\n");
Proto for the function http://php.net/is_dir is:

bool is_dir ( string $filename )

"Returns TRUE if the filename exists and is a directory, FALSE  otherwise."
 [2009-11-27 17:18 UTC] michael202 at gmx dot de
First I gave up on this issue and switched to drive letters.
Now I tested php 5.3.1 and this bug is fixed !

It must have been an issue with php, because:

I have two parallel installations of php (5.2.6 and 5.3.1) on the same computer.
If I switch between these I can produce the bug with 5.2.6 and I don't have it with 5.3.1.

Again: for each access to a file with a UNC path, something truncates the last character of the share name (here import -> impor) resulting in hundreds of these error messages (/var/log/samba/log.smbd):

[2009/11/27 18:07:44, 0] smbd/service.c:make_connection(794)
  pro (1.2.7.1) couldn't find service impor

AND resulting in a very high load and a server hard reset.

Thanks !
 [2009-11-27 17:21 UTC] pajoye@php.net
I have to verify with UNC path and 5.2.
 [2009-11-27 22:33 UTC] pajoye@php.net
Can't reproduce it here. Please provide a script to reproduce this problem, like the UNC path you use as well as which Windows version.
 [2009-12-05 01:00 UTC] 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".
 [2009-12-14 15:40 UTC] roelvs at hotmail dot com
The bug is still in 5.2.11 on windows 2008 x64. We use a Windows fileserver (DFS), fastcgi.


the results in a slowdown of traffic, and what seems to be unnecessary load for the PHP server.

the UNC paths used look like \\NASdepart.acad.kahosl.be\home

in a sniffing session this results in 
\\NASdepart.acad.kahosl.be\hom 
and the described error. (status_bad_network_name)

After this error, it looks like PHP tries to recover using a time-consuming iterative directory lookup.

If necessary, I can provide a screenshot showing the problem, although I am not an SMB protocol specialist...
 [2009-12-14 20:05 UTC] roelvs at hotmail dot com
To help you isolate the problem, a sample code snippet producing the SMB trouble:

$filename="test.dat";	
$dataFile = fopen( $filename, "r" ) ;
	if($dataFile) {
		while (!feof($dataFile)) {
			$buffer = fgets($dataFile, 4096);
	   }
	   fclose($dataFile);
	}
	else {
	   die( "fopen failed for $filename" ) ;
	}


/*(to be executed from smb share!)*/
 [2009-12-15 12:10 UTC] pajoye@php.net
Ok, I was able to reproduce a similar problem. It looks like it fails to detect the UNC path. I have to analyze further to see why it fails now.
 [2009-12-16 10:49 UTC] pajoye@php.net
I tested it again and it works smoothly. My initial has a mistake in the PATH \\ instead of \\\\ :)

Tested using win7/2k8/2k3/xp with win7 and 2k8 as file server, works.

Please provide:
- a script to reproduce this problem:
  $path ='....'; var_dump(is_dir($path));
  for example, with actual value for $path
- Which fileserver do you use?


 [2009-12-24 01:00 UTC] 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".
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC