Skip to content
Merged

Fix #95

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
10 changes: 3 additions & 7 deletions code/src/main/java/com/codeforces/commons/compress/ZipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public static void unzip(File zipArchive, File destinationDirectory, @Nullable F
}

File file = new File(destinationDirectory, fileHeader.getFileName()).getCanonicalFile();
if (!file.toPath().normalize().startsWith(destinationDirectory.toPath().normalize())) {
if (!file.getAbsolutePath().startsWith(destinationDirectory.getCanonicalPath())) {
throw new IOException("ZIP entry tries to escape destination directory: " + fileHeader.getFileName());
}

Expand All @@ -392,12 +392,8 @@ public static void unzip(File zipArchive, File destinationDirectory, @Nullable F

if (maxSize <= MAX_ZIP_ENTRY_SIZE) {
File parentDir = file.getParentFile();

try {
Files.createDirectories(parentDir.toPath());
} catch (Exception e) {
throw new IOException("Failed to create parent directory: '"
+ parentDir.getAbsolutePath() + "'.", e);
if (!parentDir.exists() && !parentDir.mkdirs()) {
throw new IOException("Failed to create parent directory: " + parentDir.getAbsolutePath());
}

Files.deleteIfExists(file.toPath());
Expand Down
Loading