@@ -272,8 +272,8 @@ public static void unzip(File zipArchive, File destinationDirectory) throws IOEx
272
272
* @param destinationDirectory directory to unzip to
273
273
* @throws IOException if any I/O-exception occurred
274
274
*/
275
- public static void unzip (File zipArchive , File destinationDirectory , @ Nullable FileFilter skipFilter )
276
- throws IOException {
275
+ public static void unzipUseZipInputStream (File zipArchive , File destinationDirectory ,
276
+ @ Nullable FileFilter skipFilter ) throws IOException {
277
277
long startTimeMillis = System .currentTimeMillis ();
278
278
long compressedSize = zipArchive .length ();
279
279
long totalUncompressedSize = 0L ;
@@ -364,7 +364,7 @@ public static void unzip(File zipArchive, File destinationDirectory, @Nullable F
364
364
logger .info (message );
365
365
}
366
366
367
- public static void unzip2 (File zipArchive , File destinationDirectory , @ Nullable FileFilter skipFilter )
367
+ public static void unzip (File zipArchive , File destinationDirectory , @ Nullable FileFilter skipFilter )
368
368
throws IOException {
369
369
try (net .lingala .zip4j .ZipFile zipFile = new net .lingala .zip4j .ZipFile (zipArchive )) {
370
370
FileUtil .ensureDirectoryExists (destinationDirectory );
@@ -377,7 +377,7 @@ public static void unzip2(File zipArchive, File destinationDirectory, @Nullable
377
377
}
378
378
379
379
File file = new File (destinationDirectory , fileHeader .getFileName ()).getCanonicalFile ();
380
- if (!file .getAbsolutePath ().startsWith (destinationDirectory .getCanonicalPath ())) {
380
+ if (!file .toPath ().normalize (). startsWith (destinationDirectory .toPath (). normalize ())) {
381
381
throw new IOException ("ZIP entry tries to escape destination directory: " + fileHeader .getFileName ());
382
382
}
383
383
@@ -392,8 +392,12 @@ public static void unzip2(File zipArchive, File destinationDirectory, @Nullable
392
392
393
393
if (maxSize <= MAX_ZIP_ENTRY_SIZE ) {
394
394
File parentDir = file .getParentFile ();
395
- if (!parentDir .exists () && !parentDir .mkdirs ()) {
396
- throw new IOException ("Failed to create parent directory: " + parentDir .getAbsolutePath ());
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 );
397
401
}
398
402
399
403
Files .deleteIfExists (file .toPath ());
0 commit comments