Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 6282d0b

Browse files
committed
Limits on header stack size parsing
1 parent 89e8f72 commit 6282d0b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
1010
{
1111
public struct MemoryPoolIterator2
1212
{
13+
private const int _maxHeaderStackLength = 16384;
14+
1315
/// <summary>
1416
/// Array of "minus one" bytes of the length of SIMD operations on the current hardware. Used as an argument in the
1517
/// vector dot product that counts matching character occurrence.
@@ -549,12 +551,19 @@ public string GetAsciiString(MemoryPoolIterator2 end)
549551
return default(string);
550552
}
551553

554+
var length = GetLength(end);
555+
556+
if (length > _maxHeaderStackLength)
557+
{
558+
return GetUtf8String(end);
559+
}
560+
552561
if (end._block == _block)
553562
{
554-
return SingleBlockAsciiString(_block.Array, _index, end._index - _index);
563+
return SingleBlockAsciiString(_block.Array, _index, length);
555564
}
556565

557-
return MultiBlockAsciiString(_block, _index, GetLength(end));
566+
return MultiBlockAsciiString(_block, _index, length);
558567
}
559568

560569
public string GetUtf8String(MemoryPoolIterator2 end)
@@ -567,10 +576,10 @@ public string GetUtf8String(MemoryPoolIterator2 end)
567576
{
568577
return _utf8.GetString(_block.Array, _index, end._index - _index);
569578
}
570-
579+
571580
var decoder = _utf8.GetDecoder();
572-
573581
var length = GetLength(end);
582+
574583
var charLength = length * 2;
575584
var chars = new char[charLength];
576585
var charIndex = 0;

0 commit comments

Comments
 (0)