Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix failing tests
The initial size is not enough to cover later TLS frames
  • Loading branch information
rzikm committed Mar 16, 2023
commit 372a38682e6ef8330162cf1a1687e86a7d6790a1
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,18 @@ private async ValueTask<int> EnsureFullTlsFrameAsync<TIOAdapter>(CancellationTok
return frameSize;
}

// make sure we have space to read into, there are two cases which can happen
// - we know the exact frame size (frameSize != int.MaxValue) - we make sure we have space for the whole frame
// - we don't know the frame size (frameSize == int.MaxValue) - we move existing data to the beginning of the buffer (they will be couple of bytes only)
_buffer.EnsureAvailableSpace(Math.Min(frameSize, _buffer.Capacity) - _buffer.EncryptedLength);
if (frameSize != int.MaxValue)
{
// make sure we have space for the whole frame
_buffer.EnsureAvailableSpace(frameSize - _buffer.EncryptedLength);
}
else
{
// move existing data to the beginning of the buffer (they will
// be couple of bytes only, otherwise we would have entire
// header and know exact size)
_buffer.EnsureAvailableSpace(_buffer.Capacity - _buffer.EncryptedLength);
}

while (_buffer.EncryptedLength < frameSize)
{
Expand Down