Skip to content

Commit 82c6887

Browse files
committed
Throw if 3rd-party security software removes a dependency during install
1 parent 98e15e1 commit 82c6887

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/ServiceControlInstaller.Engine/FileSystem/FileUtils.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace ServiceControlInstaller.Engine.FileSystem
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Diagnostics;
56
using System.IO;
67
using System.IO.Compression;
@@ -147,7 +148,25 @@ public static void UnzipToSubdirectory(string zipResourceName, string targetPath
147148

148149
internal static void UnzipToSubdirectory(Stream zipStream, string targetPath)
149150
{
150-
ZipFile.ExtractToDirectory(zipStream, targetPath, overwriteFiles: true);
151+
using var archive = new ZipArchive(zipStream, ZipArchiveMode.Read, leaveOpen: true, entryNameEncoding: null);
152+
archive.ExtractToDirectory(targetPath, overwriteFiles: true);
153+
154+
// Validate 3rd-party security software didn't delete any of the files, but first, a small delay
155+
// so that any tool out there has a chance to remove the file before prematurely declaring victory
156+
Thread.Sleep(500);
157+
foreach (var entry in archive.Entries)
158+
{
159+
var pathParts = entry.FullName.Split('/', '\\');
160+
var allParts = new string[pathParts.Length + 1];
161+
allParts[0] = targetPath;
162+
Array.Copy(pathParts, 0, allParts, 1, pathParts.Length);
163+
var destinationPath = Path.Combine(allParts);
164+
var fileInfo = new FileInfo(destinationPath);
165+
if (!fileInfo.Exists || fileInfo.Length != entry.Length)
166+
{
167+
throw new Exception($"The following file was removed after install, perhaps due to a false positive in a 3rd-party security tool. Add an exception for the path in the tool's configuration and try again: " + destinationPath);
168+
}
169+
}
151170
}
152171

153172
static void RunWithRetries(Action action)

0 commit comments

Comments
 (0)