Skip to content

Commit 001172f

Browse files
[release/7.0] Ensure free buffer space when reading TLS messages (#83574)
* Ensure free buffer space when reading TLS messages * Move buffer expansion outside of the loop to prevent unbounded grow * Fix failing tests The initial size is not enough to cover later TLS frames * Remove unwanted changes --------- Co-authored-by: Radek Zikmund <[email protected]> Co-authored-by: Radek Zikmund <[email protected]> Co-authored-by: Radek Zikmund <[email protected]>
1 parent 7cd68bc commit 001172f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libraries/System.Net.Security/src/System/Net/Security/SslStream.IO.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,16 @@ private async ValueTask<int> EnsureFullTlsFrameAsync<TIOAdapter>(CancellationTok
686686

687687
if (frameSize < int.MaxValue)
688688
{
689+
// make sure we have space for the whole frame
689690
_buffer.EnsureAvailableSpace(frameSize - _buffer.EncryptedLength);
690691
}
692+
else
693+
{
694+
// move existing data to the beginning of the buffer (they will
695+
// be couple of bytes only, otherwise we would have entire
696+
// header and know exact size)
697+
_buffer.EnsureAvailableSpace(_buffer.Capacity - _buffer.EncryptedLength);
698+
}
691699

692700
while (_buffer.EncryptedLength < frameSize)
693701
{

0 commit comments

Comments
 (0)