From ac56cb6f8c954b75f820030987fde41df1ba20ae Mon Sep 17 00:00:00 2001 From: fanyang-mono Date: Wed, 12 Jun 2024 14:18:51 -0400 Subject: [PATCH 1/5] Fix assembly name parser --- src/mono/mono/metadata/reflection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index 1539b020a1b6b..7b579cfdeec7b 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -1548,7 +1548,7 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p) } assembly->name = p; s = p; - while (*p && (isalnum (*p) || *p == '.' || *p == '-' || *p == '_' || *p == '$' || *p == '@' || g_ascii_isspace (*p))) + while (*p && (*p != ',')) p++; if (quoted) { if (*p != '"') @@ -1648,7 +1648,7 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p) found_sep = 1; continue; } - /* failed */ + /* Done processing */ if (!found_sep) return 1; } From f06e4787666e4775c18cddee80ffd417e46189a7 Mon Sep 17 00:00:00 2001 From: fanyang-mono Date: Thu, 13 Jun 2024 00:28:51 -0400 Subject: [PATCH 2/5] Handle quoted case --- src/mono/mono/metadata/reflection.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index 7b579cfdeec7b..5cadde3f1613a 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -1548,8 +1548,12 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p) } assembly->name = p; s = p; - while (*p && (*p != ',')) - p++; + guchar *inptr = (guchar *) p; + while (*p && (*p != ',')) { + if (quoted && (*p == '"')) + break; + p += g_utf8_jump_table[*inptr]; + } if (quoted) { if (*p != '"') return 1; From 2909346671a3111b75102d7babe15f44676a2bb4 Mon Sep 17 00:00:00 2001 From: fanyang-mono Date: Thu, 13 Jun 2024 11:44:01 -0400 Subject: [PATCH 3/5] Add utf8 validation --- src/mono/mono/eglib/eglib-remap.h | 1 + src/mono/mono/eglib/glib.h | 1 + src/mono/mono/eglib/gutf8.c | 8 ++++---- src/mono/mono/metadata/reflection.c | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/eglib/eglib-remap.h b/src/mono/mono/eglib/eglib-remap.h index 3f42bd8308afc..1834554d8b177 100644 --- a/src/mono/mono/eglib/eglib-remap.h +++ b/src/mono/mono/eglib/eglib-remap.h @@ -219,6 +219,7 @@ #define g_wtf8_to_utf16 monoeg_g_wtf8_to_utf16 #define g_utf8_to_utf16_custom_alloc monoeg_g_utf8_to_utf16_custom_alloc #define g_utf8_to_utf16le_custom_alloc monoeg_g_utf8_to_utf16le_custom_alloc +#define g_utf8_validate_part monoeg_g_utf8_validate_part #define g_utf8_validate monoeg_g_utf8_validate #define g_vasprintf monoeg_g_vasprintf #define g_assertion_disable_global monoeg_assertion_disable_global diff --git a/src/mono/mono/eglib/glib.h b/src/mono/mono/eglib/glib.h index ae0dd994db235..0471f98f71786 100644 --- a/src/mono/mono/eglib/glib.h +++ b/src/mono/mono/eglib/glib.h @@ -1067,6 +1067,7 @@ g_async_safe_printf (gchar const *format, ...) */ extern const guchar g_utf8_jump_table[256]; +gboolean g_utf8_validate_part (const unsigned char *inptr, size_t len); gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **end); glong g_utf8_strlen (const gchar *str, gssize max); diff --git a/src/mono/mono/eglib/gutf8.c b/src/mono/mono/eglib/gutf8.c index 569d55fa3bd66..1fa83d08dbaca 100644 --- a/src/mono/mono/eglib/gutf8.c +++ b/src/mono/mono/eglib/gutf8.c @@ -30,8 +30,8 @@ const guchar g_utf8_jump_table[256] = { 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1 }; -static gboolean -utf8_validate (const unsigned char *inptr, size_t len) +gboolean +g_utf8_validate_part (const unsigned char *inptr, size_t len) { const unsigned char *ptr = inptr + len; unsigned char c; @@ -105,7 +105,7 @@ g_utf8_validate (const gchar *str, gssize max_len, const gchar **end) if (max_len < 0) { while (*inptr != 0) { length = g_utf8_jump_table[*inptr]; - if (!utf8_validate (inptr, length)) { + if (!g_utf8_validate_part (inptr, length)) { valid = FALSE; break; } @@ -124,7 +124,7 @@ g_utf8_validate (const gchar *str, gssize max_len, const gchar **end) length = g_utf8_jump_table[*inptr]; min = MIN (length, GSSIZE_TO_UINT (max_len - n)); - if (!utf8_validate (inptr, min)) { + if (!g_utf8_validate_part (inptr, min)) { valid = FALSE; break; } diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index 5cadde3f1613a..0255c3f8ce1f6 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -1552,7 +1552,11 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p) while (*p && (*p != ',')) { if (quoted && (*p == '"')) break; - p += g_utf8_jump_table[*inptr]; + guint length = g_utf8_jump_table[*inptr]; + if (!g_utf8_validate_part (inptr, length)) { + return 0; + } + p += length; } if (quoted) { if (*p != '"') From 1b7d5c7141b4902bb1427415307eba3a7afc689d Mon Sep 17 00:00:00 2001 From: fanyang-mono Date: Thu, 13 Jun 2024 14:14:53 -0400 Subject: [PATCH 4/5] Update inptr and handle end of string character --- src/mono/mono/metadata/reflection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index 0255c3f8ce1f6..70e114a191999 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -1549,7 +1549,7 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p) assembly->name = p; s = p; guchar *inptr = (guchar *) p; - while (*p && (*p != ',')) { + while (*p && (*p != ',') && (*p != '\0')) { if (quoted && (*p == '"')) break; guint length = g_utf8_jump_table[*inptr]; @@ -1557,6 +1557,7 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p) return 0; } p += length; + inptr += length; } if (quoted) { if (*p != '"') From c5e6a0b3a96477f445da4489212f9ba2f505c7ba Mon Sep 17 00:00:00 2001 From: fanyang-mono Date: Thu, 13 Jun 2024 16:24:03 -0400 Subject: [PATCH 5/5] Add test --- .../tests/System.Reflection.Tests/GetTypeTests.cs | 8 ++++++++ .../Hello\345\267\245\347\250\213123.cs" | 8 ++++++++ .../Hello\345\267\245\347\250\213123.csproj" | 8 ++++++++ .../System.Reflection.Tests.csproj | 2 ++ 4 files changed, 26 insertions(+) create mode 100644 "src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.cs" create mode 100644 "src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.csproj" diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/GetTypeTests.cs b/src/libraries/System.Runtime/tests/System.Reflection.Tests/GetTypeTests.cs index ba1cb8a203c4c..b034a56c0972f 100644 --- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/GetTypeTests.cs +++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/GetTypeTests.cs @@ -300,6 +300,14 @@ public void TestTypeIdentifierAttribute() Assert.Equal(42, mi.Invoke(null, args)); } + [Fact] + public void TestAssemblyNameWithInternationalChar() + { + Type testObj = typeof(Hello工程123.Program); + var t = Type.GetType(testObj.AssemblyQualifiedName); + Assert.NotNull(t); + } + [Fact] public void IgnoreLeadingDotForTypeNamesWithoutNamespace() { diff --git "a/src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.cs" "b/src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.cs" new file mode 100644 index 0000000000000..64ac6b4c7c059 --- /dev/null +++ "b/src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.cs" @@ -0,0 +1,8 @@ +using System; + +namespace System.Reflection.Hello工程123 +{ + public class Program + { + } +} \ No newline at end of file diff --git "a/src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.csproj" "b/src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.csproj" new file mode 100644 index 0000000000000..f5e314a6ef200 --- /dev/null +++ "b/src/libraries/System.Runtime/tests/System.Reflection.Tests/Hello\345\267\245\347\250\213123/Hello\345\267\245\347\250\213123.csproj" @@ -0,0 +1,8 @@ + + + $(NetCoreAppCurrent) + + + + + \ No newline at end of file diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/System.Reflection.Tests.csproj b/src/libraries/System.Runtime/tests/System.Reflection.Tests/System.Reflection.Tests.csproj index 9c380a90bfbd2..a5cf23579908e 100644 --- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/System.Reflection.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/System.Reflection.Tests.csproj @@ -77,6 +77,7 @@ + @@ -87,5 +88,6 @@ <__ExcludeFromBundle Include="TestAssembly.dll" /> + <__ExcludeFromBundle Include="Hello工程123.dll" />