|
1 | 1 | namespace ServiceControlInstaller.Engine.FileSystem |
2 | 2 | { |
3 | 3 | using System; |
| 4 | + using System.Collections.Generic; |
4 | 5 | using System.Diagnostics; |
5 | 6 | using System.IO; |
6 | 7 | using System.IO.Compression; |
@@ -147,7 +148,25 @@ public static void UnzipToSubdirectory(string zipResourceName, string targetPath |
147 | 148 |
|
148 | 149 | internal static void UnzipToSubdirectory(Stream zipStream, string targetPath) |
149 | 150 | { |
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 | + } |
151 | 170 | } |
152 | 171 |
|
153 | 172 | static void RunWithRetries(Action action) |
|
0 commit comments