Skip to content

Commit 08183d1

Browse files
authored
Merge commit from fork
1 parent f7ce52f commit 08183d1

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎plugins/org.eclipse.embedcdt.debug.gdbjtag.core/src/org/eclipse/embedcdt/debug/gdbjtag/core/datamodel/SvdUtils.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,16 @@ public static Leaf getTree(IPath path) throws CoreException {
437437
// This is the signature of ZIP files.
438438
try (ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file))) {
439439
// Get the zipped file list entry
440+
File destRoot = PacksStorage.getCacheFolder().getCanonicalFile();
440441
ZipEntry zipEntry = zipInput.getNextEntry();
441442
while (zipEntry != null) {
442443
if (!zipEntry.isDirectory()) {
443444
String fileName = zipEntry.getName();
444445

445-
File outFile = PacksStorage.getCachedFileObject(fileName);
446+
File outFile = PacksStorage.getCachedFileObject(fileName).getCanonicalFile();
447+
if (!outFile.toPath().startsWith(destRoot.toPath())) {
448+
throw new IOException("Zip entry outside target dir, aborting extraction: " + fileName);
449+
}
446450
if (!outFile.getParentFile().exists()) {
447451
outFile.getParentFile().mkdirs();
448452
}

‎plugins/org.eclipse.embedcdt.packs.core/META-INF/MANIFEST.MF‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %bundle.name
44
Bundle-SymbolicName: org.eclipse.embedcdt.packs.core;singleton:=true
5-
Bundle-Version: 3.1.4.qualifier
5+
Bundle-Version: 3.2.0.qualifier
66
Bundle-Activator: org.eclipse.embedcdt.internal.packs.core.Activator
77
Bundle-RequiredExecutionEnvironment: JavaSE-11
88
Bundle-ActivationPolicy: lazy

‎plugins/org.eclipse.embedcdt.packs.core/src/org/eclipse/embedcdt/packs/core/data/PacksStorage.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ public static File getCachedFileObject(String name) throws IOException {
8282
return file; // Cannot return null
8383
}
8484

85+
/**
86+
* @since 3.2
87+
*/
88+
public static File getCacheFolder() throws IOException {
89+
IPath path = getFolderPath().append(CACHE_FOLDER);
90+
File file = path.toFile();
91+
if (file == null) {
92+
throw new IOException(CACHE_FOLDER + " File object null.");
93+
}
94+
return file; // Cannot return null
95+
}
96+
8597
public static File getPackageFileObject(String vendor, String packageName, String version, String name)
8698
throws IOException {
8799

‎plugins/org.eclipse.embedcdt.packs.core/src/org/eclipse/embedcdt/packs/core/jobs/InstallJob.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ private boolean copyFile(URL sourceUrl, File destinationFile) throws IOException
328328

329329
private boolean unzip(File archiveFile, IPath destRelativePath) throws IOException {
330330

331+
File destRoot = PacksStorage.getFileObject(destRelativePath.toString()).getCanonicalFile();
331332
fOut.println("Unzipping \"" + archiveFile + "\"...");
332333

333334
boolean result = true;
@@ -346,8 +347,11 @@ private boolean unzip(File archiveFile, IPath destRelativePath) throws IOExcepti
346347

347348
String fileName = zipEntry.getName();
348349

349-
IPath path = destRelativePath.append(fileName);
350-
File outFile = PacksStorage.getFileObject(path.toString());
350+
File outFile = new File(destRoot, fileName).getCanonicalFile();
351+
if (!outFile.toPath().startsWith(destRoot.toPath())) {
352+
throw new IOException("Zip entry outside target dir, aborting extraction: " + fileName);
353+
}
354+
351355
if (!outFile.getParentFile().exists()) {
352356
outFile.getParentFile().mkdirs();
353357
}

0 commit comments

Comments
 (0)