Skip to content

Reverted back to use unzip based on net.lingala.zip4j #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
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
16 changes: 10 additions & 6 deletions code/src/main/java/com/codeforces/commons/compress/ZipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public static void unzip(File zipArchive, File destinationDirectory) throws IOEx
* @param destinationDirectory directory to unzip to
* @throws IOException if any I/O-exception occurred
*/
public static void unzip(File zipArchive, File destinationDirectory, @Nullable FileFilter skipFilter)
throws IOException {
public static void unzipUseZipInputStream(File zipArchive, File destinationDirectory,
@Nullable FileFilter skipFilter) throws IOException {
long startTimeMillis = System.currentTimeMillis();
long compressedSize = zipArchive.length();
long totalUncompressedSize = 0L;
Expand Down Expand Up @@ -364,7 +364,7 @@ public static void unzip(File zipArchive, File destinationDirectory, @Nullable F
logger.info(message);
}

public static void unzip2(File zipArchive, File destinationDirectory, @Nullable FileFilter skipFilter)
public static void unzip(File zipArchive, File destinationDirectory, @Nullable FileFilter skipFilter)
throws IOException {
try (net.lingala.zip4j.ZipFile zipFile = new net.lingala.zip4j.ZipFile(zipArchive)) {
FileUtil.ensureDirectoryExists(destinationDirectory);
Expand All @@ -377,7 +377,7 @@ public static void unzip2(File zipArchive, File destinationDirectory, @Nullable
}

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

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

if (maxSize <= MAX_ZIP_ENTRY_SIZE) {
File parentDir = file.getParentFile();
if (!parentDir.exists() && !parentDir.mkdirs()) {
throw new IOException("Failed to create parent directory: " + parentDir.getAbsolutePath());

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

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