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/9.0] Merge RC2 changes into 9.0 #108677

Merged
merged 21 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f5456c7
Port fix for GetParts from .NETFramework
ericstj Aug 26, 2024
7019cc2
Fix regression in ExtensionEqualityComparer
ericstj Aug 27, 2024
de38a83
Remove 'Culture' from OrdinalCultureIgnoreCase
carlossanlop Sep 17, 2024
10507ab
ZipArchive: Improve performance of removing extra fields
ericstj Sep 17, 2024
5bb9659
Validate performance counter data
steveharter Sep 17, 2024
750a230
Use Marvin32 instead of xxHash32 in COSE hash codes
bartonjs Sep 17, 2024
7ca789e
Microsoft.Extensions.Caching.Memory: use Marvin for keys on down-leve…
Sep 17, 2024
49109fd
Typo typo
carlossanlop Sep 17, 2024
66366ab
Address feedback
ericstj Sep 17, 2024
ce19143
Merge commit 'fc781c3e2e12b521805c5993e7fd1517856a6576'
Sep 17, 2024
b4ccde4
Merged PR 42110: Packaging-9.0: Port fix for GetParts from .NETFramework
ericstj Sep 17, 2024
1f18b70
Merge commit '7688892cb57404127c5adac71caf1188581610c3'
Sep 17, 2024
17830f8
Merge commit 'c478b2a273193afb05c82129ba8494b65bc39878'
Sep 18, 2024
2dc643f
Merge commit '25e7a899b0640981c387f51f2121cf754925365f'
Sep 19, 2024
fe77f43
Fix Random.GetItems observably breaking change in produced sequence (…
github-actions[bot] Sep 19, 2024
327e087
Merge commit 'fe77f43b7dd624028c3d210e2eecd9265566d2dc'
Sep 19, 2024
55c018f
[release/9.0-rc2] [browser] Fix custom icu fingerprinting. (#108025)
github-actions[bot] Sep 21, 2024
002e894
Merge commit '55c018f4580a149514e5b28b820da44ffd3d24e8'
Sep 21, 2024
200d05e
[release/9.0-rc2] dont try to capture threadId for NativeAOT (#108091)
github-actions[bot] Sep 23, 2024
990ebf5
Merge commit '200d05e41fc2212ff8c98ed79ebe9043bfed58aa'
Sep 23, 2024
55f9b28
Merge tag 'v9.0.0-rc.2.24473.5' of https://github.com/dotnet/runtime …
ericstj Oct 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;

Expand All @@ -13,6 +14,17 @@ internal static partial class Advapi32
internal struct PERF_COUNTER_BLOCK
{
internal int ByteLength;

internal static readonly int SizeOf = Marshal.SizeOf<PERF_COUNTER_BLOCK>();

public readonly void Validate(int bufferSize)
{
if (ByteLength < SizeOf ||
ByteLength > bufferSize)
{
ThrowInvalidOperationException(typeof(PERF_COUNTER_BLOCK));
}
}
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -28,6 +40,20 @@ internal struct PERF_COUNTER_DEFINITION
internal int CounterType;
internal int CounterSize;
internal int CounterOffset;

internal static readonly int SizeOf = Marshal.SizeOf<PERF_COUNTER_DEFINITION>();

public readonly void Validate(int bufferSize)
{
if (ByteLength < SizeOf ||
ByteLength > bufferSize ||
CounterSize < 0 ||
CounterOffset < 0 ||
CounterOffset > bufferSize)
{
ThrowInvalidOperationException(typeof(PERF_COUNTER_DEFINITION));
}
}
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -49,6 +75,23 @@ internal struct PERF_DATA_BLOCK
internal long PerfTime100nSec;
internal int SystemNameLength;
internal int SystemNameOffset;

internal const int Signature1Int = (int)'P' + ('E' << 16);
internal const int Signature2Int = (int)'R' + ('F' << 16);
internal static readonly int SizeOf = Marshal.SizeOf<PERF_DATA_BLOCK>();

public readonly void Validate(int bufferSize)
{
if (Signature1 != Signature1Int ||
Signature2 != Signature2Int ||
TotalByteLength < SizeOf ||
TotalByteLength > bufferSize ||
HeaderLength < SizeOf ||
HeaderLength > TotalByteLength)
{
ThrowInvalidOperationException(typeof(PERF_DATA_BLOCK));
}
}
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -61,9 +104,23 @@ internal struct PERF_INSTANCE_DEFINITION
internal int NameOffset;
internal int NameLength;

internal static readonly int SizeOf = Marshal.SizeOf<PERF_INSTANCE_DEFINITION>();

internal static ReadOnlySpan<char> GetName(in PERF_INSTANCE_DEFINITION instance, ReadOnlySpan<byte> data)
=> (instance.NameLength == 0) ? default
: MemoryMarshal.Cast<byte, char>(data.Slice(instance.NameOffset, instance.NameLength - sizeof(char))); // NameLength includes the null-terminator

public readonly void Validate(int bufferSize)
{
if (ByteLength < SizeOf ||
ByteLength > bufferSize ||
NameOffset < 0 ||
NameLength < 0 ||
checked (NameOffset + NameLength) > ByteLength)
{
ThrowInvalidOperationException(typeof(PERF_INSTANCE_DEFINITION));
}
}
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -83,6 +140,29 @@ internal struct PERF_OBJECT_TYPE
internal int CodePage;
internal long PerfTime;
internal long PerfFreq;

internal static readonly int SizeOf = Marshal.SizeOf<PERF_OBJECT_TYPE>();

public readonly void Validate(int bufferSize)
{
if (HeaderLength < SizeOf ||
HeaderLength > TotalByteLength ||
HeaderLength > DefinitionLength ||
DefinitionLength < SizeOf ||
DefinitionLength > TotalByteLength ||
TotalByteLength > bufferSize ||
NumCounters < 0 ||
checked
(
// This is a simple check, not exact, since it depends on how instances are specified.
(NumInstances <= 0 ? 0 : NumInstances * PERF_INSTANCE_DEFINITION.SizeOf) +
NumCounters * PERF_COUNTER_DEFINITION.SizeOf
) > bufferSize
)
{
ThrowInvalidOperationException(typeof(PERF_OBJECT_TYPE));
}
}
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -106,4 +186,8 @@ public override string ToString()
}
}
}

[DoesNotReturn]
public static void ThrowInvalidOperationException(Type type) =>
throw new InvalidOperationException(SR.Format(SR.InvalidPerfData, type.Name));
}
32 changes: 7 additions & 25 deletions src/libraries/Common/src/System/HashCodeRandomization.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using System.Security.Cryptography;

namespace System
{
// Contains helpers for calculating randomized hash codes of common types.
Expand All @@ -21,32 +24,11 @@ public static int GetRandomizedOrdinalHashCode(this string value)

return value.GetHashCode();
#else
// Downlevel, we need to perform randomization ourselves. There's still
// the potential for limited collisions ("Hello!" and "Hello!\0"), but
// this shouldn't be a problem in practice. If we need to address it,
// we can mix the string length into the accumulator before running the
// string contents through.
//
// We'll pull out pairs of chars and write 32 bits at a time.
// Downlevel, we need to perform randomization ourselves.

HashCode hashCode = default;
int pair = 0;
for (int i = 0; i < value.Length; i++)
{
int ch = value[i];
if ((i & 1) == 0)
{
pair = ch << 16; // first member of pair
}
else
{
pair |= ch; // second member of pair
hashCode.Add(pair); // write pair as single unit
pair = 0;
}
}
hashCode.Add(pair); // flush any leftover data (could be 0 or 1 chars)
return hashCode.ToHashCode();
ReadOnlySpan<char> charSpan = value.AsSpan();
ReadOnlySpan<byte> byteSpan = MemoryMarshal.AsBytes(charSpan);
return Marvin.ComputeHash32(byteSpan, Marvin.DefaultSeed);
#endif
}

Expand Down
Loading
Loading