@@ -639,20 +639,25 @@ private static void decompressTar(File archive, String directory) throws IOExcep
639639 try (TarArchiveInputStream tis = new TarArchiveInputStream (Files .newInputStream (archive .toPath ()))) {
640640 TarArchiveEntry entry ;
641641 while ((entry = tis .getNextEntry ()) != null ) {
642- File newFile = new File (directory , entry .getName ());
643- if (entry .isDirectory ()) {
644- if (!newFile .isDirectory () && !newFile .mkdirs ()) {
645- throw new IOException ("Failed to create directory " + newFile );
646- }
647- } else {
648- File parent = newFile .getParentFile ();
649- if (!parent .isDirectory () && !parent .mkdirs ()) {
650- throw new IOException ("Failed to create directory " + parent );
651- }
652- try (OutputStream out = Files .newOutputStream (newFile .toPath ())) {
653- int len ;
654- while ((len = tis .read (buffer )) != -1 ) {
655- out .write (buffer , 0 , len );
642+ if (CompressionUtils .isPathTraversal (directory , entry .getName ())){
643+ log .error (DIRECTORY_ATTACK + "{}" , entry .getName ());
644+ return ;
645+ }else {
646+ File newFile = new File (directory , entry .getName ());
647+ if (entry .isDirectory ()) {
648+ if (!newFile .isDirectory () && !newFile .mkdirs ()) {
649+ throw new IOException ("Failed to create directory " + newFile );
650+ }
651+ } else {
652+ File parent = newFile .getParentFile ();
653+ if (!parent .isDirectory () && !parent .mkdirs ()) {
654+ throw new IOException ("Failed to create directory " + parent );
655+ }
656+ try (OutputStream out = Files .newOutputStream (newFile .toPath ())) {
657+ int len ;
658+ while ((len = tis .read (buffer )) != -1 ) {
659+ out .write (buffer , 0 , len );
660+ }
656661 }
657662 }
658663 }
0 commit comments