Make GetKnownHttpScheme "safe" (#21204)
This commit is contained in:
parent
e73d0fb575
commit
8b2f8088e9
|
|
@ -430,20 +430,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
||||||
/// <param name="knownScheme">A reference to the known scheme, if the input matches any</param>
|
/// <param name="knownScheme">A reference to the known scheme, if the input matches any</param>
|
||||||
/// <returns>True when memory starts with known http or https schema</returns>
|
/// <returns>True when memory starts with known http or https schema</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe bool GetKnownHttpScheme(this Span<byte> span, out HttpScheme knownScheme)
|
public static bool GetKnownHttpScheme(this Span<byte> span, out HttpScheme knownScheme)
|
||||||
{
|
{
|
||||||
fixed (byte* data = span)
|
if (BinaryPrimitives.TryReadUInt64LittleEndian(span, out var scheme))
|
||||||
{
|
{
|
||||||
return GetKnownHttpScheme(data, span.Length, out knownScheme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
private static unsafe bool GetKnownHttpScheme(byte* location, int length, out HttpScheme knownScheme)
|
|
||||||
{
|
|
||||||
if (length >= sizeof(ulong))
|
|
||||||
{
|
|
||||||
var scheme = *(ulong*)location;
|
|
||||||
if ((scheme & _mask7Chars) == _httpSchemeLong)
|
if ((scheme & _mask7Chars) == _httpSchemeLong)
|
||||||
{
|
{
|
||||||
knownScheme = HttpScheme.Http;
|
knownScheme = HttpScheme.Http;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue