Bug 11778 - UnixPath.ReadLink() does not work for non-ASCII results
Summary: UnixPath.ReadLink() does not work for non-ASCII results
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.POSIX ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-04-14 10:04 UTC by Steffen Kieß
Modified: 2013-09-18 12:50 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Steffen Kieß 2013-04-14 10:04:13 UTC
When calling UnixPath.ReadLink() on a link which points to a non-ascii path it will throw an Exception.

Steps to reproduce:
cat > ReadLink.cs <<EOF
using System;
using Mono.Unix;
class ReadLink {
  public static void Main () {
    Console.WriteLine (UnixPath.ReadLink ("link"));
gmcs ReadLink.cs -r:Mono.Posix
ln -s ä link
mono ReadLink.exe

Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
  at System.Text.StringBuilder.ToString (Int32 startIndex, Int32 length) [0x00000] in <filename unknown>:0 
  at Mono.Unix.UnixPath.ReadSymbolicLink (System.String path, Mono.Unix.Native.Errno& errno) [0x00000] in <filename unknown>:0 
  at Mono.Unix.UnixPath.ReadLink (System.String path) [0x00000] in <filename unknown>:0 
  at ReadLink.Main () [0x00000] in <filename unknown>:0 

The problem is that the return value of Syscall.readlink() is in bytes but UnixPath.ReadSymbolicLink() assumes that it is in chars.

UnixSymbolicLinkInfo.TryReadLink() is also affected (but that method is also affected by #9611).
Comment 1 Steffen Kieß 2013-07-13 14:53:13 UTC
See https://github.com/mono/mono/pull/701 for a fix
Comment 2 Jonathan Pryor 2013-09-18 12:50:34 UTC
Fixed in mono/eb13855b.