Bug #72625 [Csd]: realpath() fails on very long argument.
| From: | anrdaemon at freemail dot ru | Date: | Sat, 23 Jul 2016 23:06:05 +0000 |
| Subject: | Bug #72625 [Csd]: realpath() fails on very long argument. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202546@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72625&edit=1
ID: 72625
User updated by: anrdaemon at freemail dot ru
Reported by: anrdaemon at freemail dot ru
Summary: realpath() fails on very long argument.
Status: Closed
Type: Bug
Package: Filesystem function related
Operating System: Windows
PHP Version: 7.0.8
Assigned To: ab
Block user comment: N
Private report: N
New Comment:
Yes, the "dirname(realpath(...))" isn't completely foolproof.
I've used it as a means to show that the string length is an issue, and to not use any
questionable and hard to understand code in its place.
dirname() would cut the last element in the path, and if the original path actually exists, the
result of dirname()'ing would guarantee to exist as well, as in this specific case.
In regard to Composer, the origin of its issue is https://bugs.php.net/bug.php?id=72642
But it seems the person replying to that bug has his head way above his shoulders.
Previous Comments:
------------------------------------------------------------------------
[2016-07-23 22:55:59] cmb@php.net
Thanks, Anatol.
> Reimplementing the path canonicalization might take some time.
In my opinion, a fallback for Windows < 8.1 is not absolutely
necessary; this might simply be documented as limitation.
------------------------------------------------------------------------
[2016-07-23 20:05:18] ab@php.net
Christoph, i've fixed this exact case, and also partially the general case using teh new APIs
when available. Reimplementing the path canonicalization might take some time. The clean case is
however worky under any circumstances.
@anrdaemon just one note to your code - realpath(dirname($fn1)) seems wrong. If the path ends with
some periods, it might deliver usexpected results.
Thanks.
------------------------------------------------------------------------
[2016-07-23 19:48:19] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0f16c56262a4d1f91bc299bb47d82df1e09700f8
Log: Fixed bug #72625 realpath() fails on non canonical long path
------------------------------------------------------------------------
[2016-07-23 16:17:10] ab@php.net
@cmb, yeah, Windows API won't do any magic with \\?\ prefixed paths. I intentionally left this
part, because there is yet no API for all windows versions (starting with 8.1 there is one). Also,
that saves some memory operations. While replacing slashes wouldn't cost any memory overhead,
so probably could be done. Since this issue is related to composer, probably worth it at least.
I'll look to maybe come up with some custom PathCchCanonicalizeEx for lower Windows versions.
Thanks.
------------------------------------------------------------------------
[2016-07-21 23:02:15] cmb@php.net
The issue is FindFirstFileW(), which isn't as liberal with regard
to the \\?\ prefix as without it. POC:
#include <windows.h>
int main()
{
HANDLE h;
WIN32_FIND_DATA fd;
h = FindFirstFileW(L"C:\\Windows", &fd);
printf("%i\n", h != INVALID_HANDLE_VALUE);
h = FindFirstFileW(L"C:/Windows", &fd);
printf("%i\n", h != INVALID_HANDLE_VALUE);
h = FindFirstFileW(L"\\\\?\\C:\\Windows", &fd);
printf("%i\n", h != INVALID_HANDLE_VALUE);
h = FindFirstFileW(L"\\\\?\\C:/Windows", &fd);
printf("%i\n", h != INVALID_HANDLE_VALUE);
return 0;
}
outputs:
1
1
1
0
Neither slashes (nor dots nor double-dots) are converted, as noted
on MSDN in the section about "Maximum Path Length Limitation"[1].
It occurs to me that this conversion would have to be done by PHP
in the first place. Anatol, what do you think?
[1] <https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath>
------------------------------------------------------------------------
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=72625
--
Edit this bug report at https://bugs.php.net/bug.php?id=72625&edit=1