Bug #73877 [Com]: readlink() returns garbage for UTF paths

From: Date: Fri, 06 Jan 2017 20:34:06 +0000
Subject: Bug #73877 [Com]: readlink() returns garbage for UTF paths
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206334@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73877&edit=1 ID: 73877 Comment by: kulakov74 at yandex dot ru Reported by: kulakov74 at yandex dot ru Summary: readlink() returns garbage for UTF paths Status: Feedback Type: Bug Package: Filesystem function related Operating System: Windows 8.1 PHP Version: 7.1.0 Block user comment: N Private report: N New Comment: A follow-up: I tried the test script with various directories and the returned string always has the last directory cut about halfway, but at the same time the 1st half that is returned is correct (not garbage). So it looks like the problem is merely in allocating enough length for the result string. Previous Comments: ------------------------------------------------------------------------ [2017-01-06 20:24:18] kulakov74 at yandex dot ru Yes, thank you, but in this particular case it doesn't matter - everything works the same way with "\\". And sorry, I didn't make it quite clear: in my case, the directory is NOT a link, so readlink() should return the dir, not a target, but it DOESN'T, so my script thinks it IS A LINK. So no mklink command had been used. I use ini_set('default_charset', 'UTF-8'); and then I get the dir from opendir()/readdir(), so it should be UTF-8. ------------------------------------------------------------------------ [2017-01-06 19:51:08] ab@php.net Thanks for the report. Double quotes will lead to the backslash extrapolation, backslash need to be escaped therefore. Need also to know, what kind of link is that? Also - is the string passed UTF-8 encoded? Could you provide maybe an exact mklink command or alike, to get the reproducer? I've just tried with a junction and see no issue. Thanks. ------------------------------------------------------------------------ [2017-01-05 23:42:41] kulakov74 at yandex dot ru Description: ------------ I work in CLI on Windows. After they finally 'Fixed UTF-8 and long path support on Windows' in PHP 7.1.0 I installed it and after changing default_charset to UTF-8 things seem to work, but when I call readlink() with Cyrillic paths it returns the same path cut somewhere near the end with a garbage character added. For example: "C:\Users\Серёжка" -> "C:\Users\Сер�" readlink() is supposed to return the same path for regular directories, which it does for ones not having UTF characters. Test script: --------------- $FullName="C:\Users\Серёжка"; echo(readlink($FullName)); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73877&edit=1

« previous php.bugs (#206334) next »