Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/main/java/org/myrobotlab/io/Zip.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,23 @@ static public void unzip(String zipFile, String newPath) throws ZipException, IO
new File(newPath).mkdir();
Enumeration<?> zipFileEntries = zip.entries();

File canonicalNewPath = new File(newPath).getCanonicalFile();

// Process each entry
while (zipFileEntries.hasMoreElements()) {
// grab a zip file entry
ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
String currentEntry = entry.getName();
File destFile = new File(newPath, currentEntry);

// Canonicalize the destination file path
File canonicalDestFile = destFile.getCanonicalFile();

// Check if the canonical destination path starts with the canonical newPath
if (!canonicalDestFile.getPath().startsWith(canonicalNewPath.getPath())) {
throw new IOException("Attempt to write outside of the target directory: " + currentEntry);
}

// destFile = new File(newPath, destFile.getName());
File destinationParent = destFile.getParentFile();

Expand Down