Skip to content

Commit c45702d

Browse files
Fix read bug.
1 parent 6301662 commit c45702d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ImageSharp/IO/ChunkedMemoryStream.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ public override int Read(Span<byte> buffer)
124124
return 0;
125125
}
126126

127-
int bytesToRead = count;
127+
if (remaining > count)
128+
{
129+
remaining = count;
130+
}
131+
132+
// 'remaining' can be less than the provided buffer length.
133+
int bytesToRead = (int)remaining;
128134
int bytesRead = 0;
129135
while (bytesToRead > 0 && this.bufferIndex != this.memoryChunkBuffer.Length)
130136
{
@@ -422,7 +428,6 @@ public void Dispose()
422428
}
423429

424430
this.memoryChunks.Clear();
425-
426431
this.Length = 0;
427432
this.isDisposed = true;
428433
}

0 commit comments

Comments
 (0)