LoopbackServer.ReadAsync: Fixed data corruption bug (#34875)
authorTalAloni <tal.aloni.il@gmail.com>
Mon, 13 Apr 2020 00:34:31 +0000 (03:34 +0300)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2020 00:34:31 +0000 (20:34 -0400)
This caused the unused parts of the temp buffer to be copied to buffer, returning 0 to the caller instead of the actual data.
This caused several tests to fail when targeting .NET Standard 2.0

src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs

index 48d75c8..97a93b3 100644 (file)
@@ -447,7 +447,7 @@ namespace System.Net.Test.Common
                 int readLength = await _stream.ReadAsync(tempBuffer, 0, size).ConfigureAwait(false);
                 if (readLength > 0)
                 {
-                    tempBuffer.AsSpan(readLength).CopyTo(buffer.Span.Slice(offset, size));
+                    tempBuffer.AsSpan(0, readLength).CopyTo(buffer.Span.Slice(offset, size));
                 }
 
                 return readLength;