Skip to content

Commit

Permalink
Avoid writing garbage bytes to read blobs in managed git engine
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AArnott committed Apr 7, 2021
1 parent 707e619 commit ae45375
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -49,9 +49,9 @@ public override int Read(Span<byte> buffer)
{
var currentPosition = this.cacheStream.Position;
var toRead = (int)(buffer.Length - this.cacheStream.Length + this.cacheStream.Position);
this.stream.Read(buffer.Slice(0, toRead));
int actualRead = this.stream.Read(buffer.Slice(0, toRead));
this.cacheStream.Seek(0, SeekOrigin.End);
this.cacheStream.Write(buffer.Slice(0, toRead));
this.cacheStream.Write(buffer.Slice(0, actualRead));
this.cacheStream.Seek(currentPosition, SeekOrigin.Begin);
this.DisposeStreamIfRead();
}
Expand Down

0 comments on commit ae45375

Please sign in to comment.