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

Fix Read() with count=0 exhausting MessageBodyStream #4295

Merged
merged 2 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
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 @@ -299,6 +299,11 @@ internal MessageBodyStream(Message message, string wrapperName, string wrapperNs

public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (count == 0)
{
return 0;
}

if (_reader == null)
{
if (_message.Properties.ContainsKey(BufferedReadStream.BufferedReadStreamPropertyName))
Expand Down Expand Up @@ -344,6 +349,11 @@ public override int Read(byte[] buffer, int offset, int count)
throw TraceUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.SFxInvalidStreamOffsetLength, offset + count)), _message);
}

if (count == 0)
{
return 0;
}

try
{
if (_reader == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ public static void BasicHttp_Async_Close_Proxy_WithSingleThreadedSyncContext()

private static string StreamToString(Stream stream)
{
stream.Read(Array.Empty<byte>(), 0, 0);
var reader = new StreamReader(stream, Encoding.UTF8);
return reader.ReadToEnd();
}
Expand Down