diff options
author | Jonathan Chambers <joncham@gmail.com> | 2017-05-11 16:30:23 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-05-11 20:23:04 +0300 |
commit | 5996adf690d021269c5b24eae58dea14fba7ac31 (patch) | |
tree | 6e2c2d0c8616c5c65ce1ad33914dee57a75f6ea1 /mcs | |
parent | 4960d5d2a28a08476ee4239e1746f04afce41c13 (diff) |
Specify Encoding.UTF8 when marshaling native runtime string. If not, string constructor accesses Encoding.Default which causes infinite recursion on Windows for codepages supported via I18N. While trying to load I18N assemblies, assembly names are marshaled in managed code now hitting this code path. Fixes Xamarin bug 43988.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Mono/RuntimeMarshal.cs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mcs/class/corlib/Mono/RuntimeMarshal.cs b/mcs/class/corlib/Mono/RuntimeMarshal.cs index 5c997cd677a..28124b21aaf 100644 --- a/mcs/class/corlib/Mono/RuntimeMarshal.cs +++ b/mcs/class/corlib/Mono/RuntimeMarshal.cs @@ -7,7 +7,20 @@ namespace Mono { internal static string PtrToUtf8String (IntPtr ptr) { unsafe { - return new String ((sbyte*)ptr); + if (ptr == IntPtr.Zero) + return string.Empty; + + byte* bytes = (byte*)ptr; + int length = 0; + + try { + while (bytes++ [0] != 0) + length++; + } catch (NullReferenceException) { + throw new ArgumentOutOfRangeException ("ptr", "Value does not refer to a valid string."); + } + + return new String ((sbyte*)ptr, 0, length, System.Text.Encoding.UTF8); } } |