Skip to content

Commit ae45375

Browse files
committed
Avoid writing garbage bytes to read blobs in managed git engine
In the case of this bug, the `Stream.Read` method read fewer bytes than was requested. This is totally allowed, but the caller did not expect it and assumed the entire buffer was initialized rather than a subset of it. Fixes #580
1 parent 707e619 commit ae45375

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/NerdBank.GitVersioning/ManagedGit/GitPackMemoryCacheStream.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public override int Read(Span<byte> buffer)
4949
{
5050
var currentPosition = this.cacheStream.Position;
5151
var toRead = (int)(buffer.Length - this.cacheStream.Length + this.cacheStream.Position);
52-
this.stream.Read(buffer.Slice(0, toRead));
52+
int actualRead = this.stream.Read(buffer.Slice(0, toRead));
5353
this.cacheStream.Seek(0, SeekOrigin.End);
54-
this.cacheStream.Write(buffer.Slice(0, toRead));
54+
this.cacheStream.Write(buffer.Slice(0, actualRead));
5555
this.cacheStream.Seek(currentPosition, SeekOrigin.Begin);
5656
this.DisposeStreamIfRead();
5757
}

0 commit comments

Comments
 (0)