Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 02e499e

Browse files
davidnistephentoub
authored andcommitted
Fix #15057 MemoryStream.CopyToAsync calls Write / WriteAsync with count=0 (#15070)
1 parent 29c15a0 commit 02e499e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/mscorlib/src/System/IO/MemoryStream.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,10 @@ public override Task CopyToAsync(Stream destination, Int32 bufferSize, Cancellat
541541
Int32 pos = _position;
542542
Int32 n = InternalEmulateRead(_length - _position);
543543

544+
// If we were already at or past the end, there's no copying to do so just quit.
545+
if (n == 0)
546+
return Task.CompletedTask;
547+
544548
// If destination is not a memory stream, write there asynchronously:
545549
MemoryStream memStrDest = destination as MemoryStream;
546550
if (memStrDest == null)

0 commit comments

Comments
 (0)