Skip to content

Commit 27fee73

Browse files
Merge pull request #95 from Codeforces/dev-mikemirzayanov
Fix
2 parents 6e4d88d + 08175ca commit 27fee73

File tree

1 file changed

+3
-7
lines changed
  • code/src/main/java/com/codeforces/commons/compress

1 file changed

+3
-7
lines changed

code/src/main/java/com/codeforces/commons/compress/ZipUtil.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public static void unzip(File zipArchive, File destinationDirectory, @Nullable F
377377
}
378378

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

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

393393
if (maxSize <= MAX_ZIP_ENTRY_SIZE) {
394394
File parentDir = file.getParentFile();
395-
396-
try {
397-
Files.createDirectories(parentDir.toPath());
398-
} catch (Exception e) {
399-
throw new IOException("Failed to create parent directory: '"
400-
+ parentDir.getAbsolutePath() + "'.", e);
395+
if (!parentDir.exists() && !parentDir.mkdirs()) {
396+
throw new IOException("Failed to create parent directory: " + parentDir.getAbsolutePath());
401397
}
402398

403399
Files.deleteIfExists(file.toPath());

0 commit comments

Comments
 (0)