Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] [mono] Use unsigned char when computing UTF8 string hashes #83303

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/ghashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ guint
g_str_hash (gconstpointer v1)
{
guint hash = 0;
char *p = (char *) v1;
unsigned char *p = (unsigned char *) v1;

while (*p++)
hash = (hash << 5) - (hash + *p);
Expand Down
3 changes: 2 additions & 1 deletion src/mono/mono/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -5386,7 +5386,8 @@ guint
mono_metadata_str_hash (gconstpointer v1)
{
/* Same as g_str_hash () in glib */
char *p = (char *) v1;
/* note: signed/unsigned char matters - we feed UTF-8 to this function, so the high bit will give diferent results if we don't match. */
unsigned char *p = (unsigned char *) v1;
guint hash = *p;

while (*p++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="repro.cs" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions src/tests/Loader/classloader/regressions/GitHub_82187/repro.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

/* Regression test for https://github.com/dotnet/runtime/issues/78638
* and https://github.com/dotnet/runtime/issues/82187 ensure AOT
* cross-compiler and AOT runtime use the same name hashing for names
* that include UTF-8 continuation bytes.
*/

[MySpecial(typeof(MeineTüre))]
public class Program
{
public static int Main()
{
var attr = (MySpecialAttribute)Attribute.GetCustomAttribute(typeof (Program), typeof(MySpecialAttribute), false);
if (attr == null)
return 101;
if (attr.Type == null)
return 102;
if (attr.Type.FullName != "MeineTüre")
return 103;
return 100;
}
}

public class MySpecialAttribute : Attribute
{
public Type Type {get; private set; }
public MySpecialAttribute(Type t) { Type = t; }
}

public class MeineTüre {}