Fix #15057 MemoryStream.CopyToAsync calls Write / WriteAsync with count=0 (#15070)
authorDavid Nissimoff <davidni@microsoft.com>
Sat, 18 Nov 2017 15:11:06 +0000 (07:11 -0800)
committerStephen Toub <stoub@microsoft.com>
Sat, 18 Nov 2017 15:11:06 +0000 (10:11 -0500)
src/mscorlib/src/System/IO/MemoryStream.cs

index d2fd83d..6039dc7 100644 (file)
@@ -541,6 +541,10 @@ namespace System.IO
             Int32 pos = _position;
             Int32 n = InternalEmulateRead(_length - _position);
 
+            // If we were already at or past the end, there's no copying to do so just quit.
+            if (n == 0)
+                return Task.CompletedTask;
+
             // If destination is not a memory stream, write there asynchronously:
             MemoryStream memStrDest = destination as MemoryStream;
             if (memStrDest == null)