@@ -272,8 +272,8 @@ public static void unzip(File zipArchive, File destinationDirectory) throws IOEx
272272 * @param destinationDirectory directory to unzip to
273273 * @throws IOException if any I/O-exception occurred
274274 */
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 {
277277 long startTimeMillis = System .currentTimeMillis ();
278278 long compressedSize = zipArchive .length ();
279279 long totalUncompressedSize = 0L ;
@@ -364,7 +364,7 @@ public static void unzip(File zipArchive, File destinationDirectory, @Nullable F
364364 logger .info (message );
365365 }
366366
367- public static void unzip2 (File zipArchive , File destinationDirectory , @ Nullable FileFilter skipFilter )
367+ public static void unzip (File zipArchive , File destinationDirectory , @ Nullable FileFilter skipFilter )
368368 throws IOException {
369369 try (net .lingala .zip4j .ZipFile zipFile = new net .lingala .zip4j .ZipFile (zipArchive )) {
370370 FileUtil .ensureDirectoryExists (destinationDirectory );
@@ -377,7 +377,7 @@ public static void unzip2(File zipArchive, File destinationDirectory, @Nullable
377377 }
378378
379379 File file = new File (destinationDirectory , fileHeader .getFileName ()).getCanonicalFile ();
380- if (!file .getAbsolutePath ().startsWith (destinationDirectory .getCanonicalPath ())) {
380+ if (!file .toPath ().normalize (). startsWith (destinationDirectory .toPath (). normalize ())) {
381381 throw new IOException ("ZIP entry tries to escape destination directory: " + fileHeader .getFileName ());
382382 }
383383
@@ -392,8 +392,12 @@ public static void unzip2(File zipArchive, File destinationDirectory, @Nullable
392392
393393 if (maxSize <= MAX_ZIP_ENTRY_SIZE ) {
394394 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 );
397401 }
398402
399403 Files .deleteIfExists (file .toPath ());
0 commit comments