diff --git a/GVFS/GVFS.Common/Git/GitRepo.cs b/GVFS/GVFS.Common/Git/GitRepo.cs index d88ebbd89..6f01922e4 100644 --- a/GVFS/GVFS.Common/Git/GitRepo.cs +++ b/GVFS/GVFS.Common/Git/GitRepo.cs @@ -153,7 +153,7 @@ private static bool ReadLooseObjectHeader(Stream input, out long size) size = 0; byte[] buffer = new byte[5]; - input.Read(buffer, 0, buffer.Length); + input.ReadExactly(buffer, 0, buffer.Length); if (!Enumerable.SequenceEqual(buffer, LooseBlobHeader)) { return false; diff --git a/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs b/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs index a2f83afd4..5dbe7c335 100644 --- a/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs +++ b/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs @@ -196,7 +196,7 @@ internal static int GetIndexFileCount(GVFSEnlistment enlistment, PhysicalFileSys * the 4 bytes at offsets 8-11 of the index file. */ indexFile.Position = 8; var bytes = new byte[4]; - indexFile.Read( + indexFile.ReadExactly( bytes, // Destination buffer offset: 0, // Offset in destination buffer, not in indexFile count: 4); diff --git a/GVFS/GVFS.UnitTests/Mock/ReusableMemoryStream.cs b/GVFS/GVFS.UnitTests/Mock/ReusableMemoryStream.cs index 5afa60627..dfd70a943 100644 --- a/GVFS/GVFS.UnitTests/Mock/ReusableMemoryStream.cs +++ b/GVFS/GVFS.UnitTests/Mock/ReusableMemoryStream.cs @@ -67,7 +67,7 @@ public string ReadAt(long position, long length) this.Position = position; byte[] bytes = new byte[length]; - this.Read(bytes, 0, (int)length); + this.ReadExactly(bytes, 0, (int)length); this.Position = lastPosition; diff --git a/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs b/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs index 382a05945..4f83ff0fd 100644 --- a/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs +++ b/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs @@ -391,7 +391,11 @@ private FileSystemTaskResult ParseIndex( private void ReadNextPage() { + // Last page may be smaller than PageSize; partial fill is safe because + // the parser stops after entryCount entries and never reads stale bytes. +#pragma warning disable CA2022 // Avoid inexact read this.indexStream.Read(this.page, 0, PageSize); +#pragma warning restore CA2022 this.nextByteIndex = 0; }