Skip to content

Commit 156dee8

Browse files
authored
Fix assembly name parser to accommodate non-ASCII UTF8 strings (#103475)
1 parent fe08496 commit 156dee8

File tree

8 files changed

+46
-9
lines changed

8 files changed

+46
-9
lines changed

src/libraries/System.Reflection/tests/GetTypeTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ public void GetType_CoreAssembly()
261261
Assert.Equal(typeof(int), Type.GetType("system.int32", throwOnError: true, ignoreCase: true));
262262
}
263263

264+
[Fact]
265+
public void TestAssemblyNameWithInternationalChar()
266+
{
267+
Type testObj = typeof(Hello工程123.Program);
268+
var t = Type.GetType(testObj.AssemblyQualifiedName);
269+
Assert.NotNull(t);
270+
}
271+
264272
[Fact]
265273
[ActiveIssue("https://github.com/dotnet/runtime/issues/37871", TestRuntimes.Mono)]
266274
public void GetType_GenericTypeArgumentList()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace System.Reflection.Hello工程123
4+
{
5+
public class Program
6+
{
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="Hello工程123.cs" />
7+
</ItemGroup>
8+
</Project>

src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<ProjectReference Include="UnloadableAssembly\UnloadableAssembly.csproj" />
7777
<ProjectReference Include="TestExe\System.Reflection.TestExe.csproj" />
7878
<ProjectReference Include="TestAssembly\TestAssembly.csproj" />
79+
<ProjectReference Include="Hello工程123\Hello工程123.csproj" />
7980
</ItemGroup>
8081
<ItemGroup Condition="'$(TargetOS)' == 'browser'">
8182
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" />
@@ -86,5 +87,6 @@
8687

8788
<!-- Assemblies that should be excluded from the bundle -->
8889
<__ExcludeFromBundle Include="TestAssembly.dll" />
90+
<__ExcludeFromBundle Include="Hello工程123.dll" />
8991
</ItemGroup>
9092
</Project>

src/mono/mono/eglib/eglib-remap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
#define g_utf8_strlen monoeg_g_utf8_strlen
233233
#define g_utf8_to_utf16 monoeg_g_utf8_to_utf16
234234
#define g_utf8_to_utf16_custom_alloc monoeg_g_utf8_to_utf16_custom_alloc
235+
#define g_utf8_validate_part monoeg_g_utf8_validate_part
235236
#define g_utf8_validate monoeg_g_utf8_validate
236237
#define g_unichar_to_utf8 monoeg_g_unichar_to_utf8
237238
#define g_utf8_offset_to_pointer monoeg_g_utf8_offset_to_pointer

src/mono/mono/eglib/glib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ int g_mkdir_with_parents (const gchar *pathname, int mode);
11651165
*/
11661166
extern const guchar g_utf8_jump_table[256];
11671167

1168+
gboolean g_utf8_validate_part (const unsigned char *inptr, size_t len);
11681169
gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **end);
11691170
gunichar g_utf8_get_char_validated (const gchar *str, gssize max_len);
11701171
#define g_utf8_next_char(p) ((p) + g_utf8_jump_table[(guchar)(*p)])

src/mono/mono/eglib/gutf8.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const guchar g_utf8_jump_table[256] = {
3030
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
3131
};
3232

33-
static gboolean
34-
utf8_validate (const unsigned char *inptr, size_t len)
33+
gboolean
34+
g_utf8_validate_part (const unsigned char *inptr, size_t len)
3535
{
3636
const unsigned char *ptr = inptr + len;
3737
unsigned char c;
@@ -105,7 +105,7 @@ g_utf8_validate (const gchar *str, gssize max_len, const gchar **end)
105105
if (max_len < 0) {
106106
while (*inptr != 0) {
107107
length = g_utf8_jump_table[*inptr];
108-
if (!utf8_validate (inptr, length)) {
108+
if (!g_utf8_validate_part (inptr, length)) {
109109
valid = FALSE;
110110
break;
111111
}
@@ -124,7 +124,7 @@ g_utf8_validate (const gchar *str, gssize max_len, const gchar **end)
124124
length = g_utf8_jump_table[*inptr];
125125
min = MIN (length, GSSIZE_TO_UINT (max_len - n));
126126

127-
if (!utf8_validate (inptr, min)) {
127+
if (!g_utf8_validate_part (inptr, min)) {
128128
valid = FALSE;
129129
break;
130130
}
@@ -180,13 +180,13 @@ g_utf8_get_char_validated (const gchar *str, gssize max_len)
180180
}
181181

182182
if (max_len > 0) {
183-
if (!utf8_validate (inptr, MIN (max_len, n)))
183+
if (!g_utf8_validate_part (inptr, MIN (max_len, n)))
184184
return -1;
185185

186186
if (max_len < n)
187187
return -2;
188188
} else {
189-
if (!utf8_validate (inptr, n))
189+
if (!g_utf8_validate_part (inptr, n))
190190
return -1;
191191
}
192192

src/mono/mono/metadata/reflection.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,8 +1530,17 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p)
15301530
}
15311531
assembly->name = p;
15321532
s = p;
1533-
while (*p && (isalnum (*p) || *p == '.' || *p == '-' || *p == '_' || *p == '$' || *p == '@' || g_ascii_isspace (*p)))
1534-
p++;
1533+
guchar *inptr = (guchar *) p;
1534+
while (*p && (*p != ',') && (*p != '\0')) {
1535+
if (quoted && (*p == '"'))
1536+
break;
1537+
guint length = g_utf8_jump_table[*inptr];
1538+
if (!g_utf8_validate_part (inptr, length)) {
1539+
return 0;
1540+
}
1541+
p += length;
1542+
inptr += length;
1543+
}
15351544
if (quoted) {
15361545
if (*p != '"')
15371546
return 1;
@@ -1630,7 +1639,7 @@ assembly_name_to_aname (MonoAssemblyName *assembly, char *p)
16301639
found_sep = 1;
16311640
continue;
16321641
}
1633-
/* failed */
1642+
/* Done processing */
16341643
if (!found_sep)
16351644
return 1;
16361645
}

0 commit comments

Comments
 (0)