Skip to content

Commit cc564ef

Browse files
MihaZupanMiha Zupan
andauthored
Remove Uri length limits (#117287)
* Remove Uri length limits * Update uri test * Add HTTP test * Lower uri length for browser http test * Rename enum value name --------- Co-authored-by: Miha Zupan <mizupan@microsoft.com>
1 parent 3e5f80e commit cc564ef

File tree

13 files changed

+344
-269
lines changed

13 files changed

+344
-269
lines changed

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,5 +2342,36 @@ public enum HeaderType
23422342
Content,
23432343
Cookie
23442344
}
2345+
2346+
[Fact]
2347+
public async Task LargeUriAndHeaders_Works()
2348+
{
2349+
int length =
2350+
IsWinHttpHandler ? 65_000 :
2351+
PlatformDetection.IsBrowser ? 4_000 :
2352+
10_000_000;
2353+
2354+
string longPath = "/" + new string('X', length);
2355+
string longHeaderName = new string('Y', length);
2356+
string longHeaderValue = new string('Z', length);
2357+
2358+
await LoopbackServerFactory.CreateClientAndServerAsync(
2359+
async uri =>
2360+
{
2361+
using HttpClient client = CreateHttpClient();
2362+
2363+
HttpRequestMessage request = CreateRequest(HttpMethod.Get, new UriBuilder(uri) { Path = longPath }.Uri, UseVersion);
2364+
request.Headers.Add(longHeaderName, longHeaderValue);
2365+
2366+
await client.SendAsync(request);
2367+
},
2368+
async server =>
2369+
{
2370+
HttpRequestData requestData = await server.HandleRequestAsync();
2371+
2372+
Assert.Equal(longPath, requestData.Path);
2373+
Assert.Equal(longHeaderValue, requestData.GetSingleHeaderValue(longHeaderName));
2374+
});
2375+
}
23452376
}
23462377
}

src/libraries/Common/tests/System/Net/Http/QPackTestDecoder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ public static (int bytesConsumed, int value) DecodeInteger(ReadOnlySpan<byte> he
9292

9393
ulong extra = 0;
9494
int length = 1;
95-
ulong b;
95+
byte b;
9696

9797
do
9898
{
9999
// https://http2.github.io/http2-spec/compression.html#integer.representation
100100
// HPack encodes integers from the least significant byte to the most.
101101
// Every 7-bits of the next byte is shifted by (7 * index) and added to the result.
102-
b = (ulong)headerBlock[length++];
103-
extra = checked(b << (7 * (length - 2))) | extra;
102+
b = headerBlock[length++];
103+
extra = checked((ulong)(b & 0x7F) << (7 * (length - 2))) | extra;
104104
}
105105
while ((b & 0b10000000) != 0);
106106

src/libraries/System.Private.Uri/src/Resources/Strings.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@
168168
<data name="net_uri_PortOutOfRange" xml:space="preserve">
169169
<value>A derived type '{0}' has reported an invalid value for the Uri port '{1}'.</value>
170170
</data>
171-
<data name="net_uri_SizeLimit" xml:space="preserve">
172-
<value>Invalid URI: The Uri string is too long.</value>
173-
</data>
174171
<data name="net_uri_UserDrivenParsing" xml:space="preserve">
175172
<value>A derived type '{0}' is responsible for parsing this Uri instance. The base implementation must not be used.</value>
176173
</data>

src/libraries/System.Private.Uri/src/System/IriHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ internal static bool CheckIsReserved(char ch, UriComponents component)
8888
//
8989
internal static unsafe string EscapeUnescapeIri(char* pInput, int start, int end, UriComponents component)
9090
{
91+
Debug.Assert(end >= 0 && start >= 0 && start <= end);
92+
9193
int size = end - start;
9294
var dest = size <= Uri.StackallocThreshold
9395
? new ValueStringBuilder(stackalloc char[Uri.StackallocThreshold])

0 commit comments

Comments
 (0)