Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure free buffer space when reading TLS messages #83480

Merged
merged 3 commits into from
Mar 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,10 @@ private async ValueTask<int> EnsureFullTlsFrameAsync<TIOAdapter>(CancellationTok
return frameSize;
}

if (frameSize < int.MaxValue)
{
_buffer.EnsureAvailableSpace(frameSize - _buffer.EncryptedLength);
}

while (_buffer.EncryptedLength < frameSize)
{
// there should be space left to read into
Debug.Assert(_buffer.AvailableLength > 0, "_buffer.AvailableBytes > 0");
// make sure we have space to read into
_buffer.EnsureAvailableSpace(Math.Min(frameSize, _buffer.Capacity) - _buffer.EncryptedLength);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there risk of growing too much if framers are keep coming. I know this is not normal case but as far as I understand the old code, we would make space for a frame, maybe more if needed.
We had EnsureAvailableSpace on line 246 so I'm wondering why that was not sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there is, I should've waited with the fix till the morning :D

We had EnsureAvailableSpace on line 246 so I'm wondering why that was not sufficient.

Not sure which one you are talking about, the closes one is in 214 and 287 and both are outside of the while loop which is receiving TLS frames


// We either don't have full frame or we don't have enough data to even determine the size.
int bytesRead = await TIOAdapter.ReadAsync(InnerStream, _buffer.AvailableMemory, cancellationToken).ConfigureAwait(false);
Expand Down