Skip to content

Commit

Permalink
Add unit test for variable length encoding HTTP/3 (#60766)
Browse files Browse the repository at this point in the history
Fixes #51519
  • Loading branch information
pedrobsaila authored Nov 9, 2021
1 parent 26c045b commit 6d5f59b
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static bool TryWrite(Span<byte> buffer, long longToEncode, out int bytesW
Debug.Assert(longToEncode >= 0);
Debug.Assert(longToEncode <= EightByteLimit);

if (longToEncode < OneByteLimit)
if (longToEncode <= OneByteLimit)
{
if (buffer.Length != 0)
{
Expand All @@ -158,15 +158,15 @@ public static bool TryWrite(Span<byte> buffer, long longToEncode, out int bytesW
return true;
}
}
else if (longToEncode < TwoByteLimit)
else if (longToEncode <= TwoByteLimit)
{
if (BinaryPrimitives.TryWriteUInt16BigEndian(buffer, (ushort)((uint)longToEncode | TwoByteLengthMask)))
{
bytesWritten = 2;
return true;
}
}
else if (longToEncode < FourByteLimit)
else if (longToEncode <= FourByteLimit)
{
if (BinaryPrimitives.TryWriteUInt32BigEndian(buffer, (uint)longToEncode | FourByteLengthMask))
{
Expand Down Expand Up @@ -200,9 +200,9 @@ public static int GetByteCount(long value)
Debug.Assert(value <= EightByteLimit);

return
value < OneByteLimit ? 1 :
value < TwoByteLimit ? 2 :
value < FourByteLimit ? 4 :
value <= OneByteLimit ? 1 :
value <= TwoByteLimit ? 2 :
value <= FourByteLimit ? 4 :
8; // EightByteLimit
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/tests/Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
Link="Common\System\Net\Http\aspnetcore\Http2\Hpack\H2StaticTable.Http2.cs" />
<Compile Include="$(CommonPath)System\Net\Http\aspnetcore\Http2\Hpack\StatusCodes.cs"
Link="Common\System\Net\Http\aspnetcore\Http2\Hpack\StatusCodes.cs" />
<Compile Include="$(CommonPath)System\Net\Http\aspnetcore\Http3\Helpers\VariableLengthIntegerHelper.cs"
Link="Common\System\Net\Http\aspnetcore\Http3\Helpers\VariableLengthIntegerHelper.cs" />
<Compile Include="$(CommonPath)System\Text\SimpleRegex.cs"
Link="Common\System\Text\SimpleRegex.cs" />
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Expand Down Expand Up @@ -95,6 +97,7 @@
<Compile Include="Tests\System\Net\aspnetcore\Http2\HPackDecoderTest.cs" />
<Compile Include="Tests\System\Net\aspnetcore\Http2\HPackIntegerTest.cs" />
<Compile Include="Tests\System\Net\aspnetcore\Http2\HuffmanDecodingTests.cs" />
<Compile Include="Tests\System\Net\aspnetcore\Http3\VariableLengthIntegerHelperTests.cs" />
<Compile Include="System\Net\Sockets\Fletcher32.cs"
Link="System\Net\Sockets\Fletcher32.cs" />
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
Expand Down
Loading

0 comments on commit 6d5f59b

Please sign in to comment.