Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[Release/3.1] Fix infinite loop when end of stream is reached #42938

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Changes from all commits
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 @@ -103,9 +103,16 @@ private async Task<int> ReadInternal(byte[] buffer, int offset, int count, Cance
// Account for split packets
while (readBytes < TdsEnums.HEADER_LEN)
{
readBytes += async ?
var readBytesForHeader = async ?
await _stream.ReadAsync(packetData, readBytes, TdsEnums.HEADER_LEN - readBytes, token).ConfigureAwait(false) :
_stream.Read(packetData, readBytes, TdsEnums.HEADER_LEN - readBytes);

if (readBytesForHeader == 0)
{
throw new EndOfStreamException("End of stream reached");
}

readBytes += readBytesForHeader;
}

_packetBytes = (packetData[TdsEnums.HEADER_LEN_FIELD_OFFSET] << 8) | packetData[TdsEnums.HEADER_LEN_FIELD_OFFSET + 1];
Expand Down