Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/SignCheck/Microsoft.SignCheck/Verification/LZMAUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,35 @@ public static void Decompress(string sourceFile, string destinationFile)
byte[] properties = new byte[5];
byte[] fileLengthBytes = new byte[8];

#pragma warning disable CA2022 // Avoid inexact read
inFile.Read(properties, 0, 5);
inFile.Read(fileLengthBytes, 0, 8);
#pragma warning restore CA2022
ReadExactly(inFile, properties, 0, 5);
ReadExactly(inFile, fileLengthBytes, 0, 8);

long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
decoder.SetDecoderProperties(properties);

decoder.Code(inFile, outFile, inFile.Length, fileLength, progress: null);
}
}

#if NET
private static void ReadExactly(FileStream stream, byte[] buffer, int offset, int count)
{
stream.ReadExactly(buffer, offset, count);
}
#else
private static void ReadExactly(FileStream stream, byte[] buffer, int offset, int count)
{
while (count > 0)
{
int read = stream.Read(buffer, offset, count);
if (read <= 0)
{
throw new EndOfStreamException();
}
offset += read;
count -= read;
}
}
#endif
}
}
Loading