Skip to content

Commit

Permalink
refactor(ZipFolder): fix zip slip issue (#4199)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Oct 5, 2021
1 parent 90e7063 commit 71f08a6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/spoon/support/compiler/ZipFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.zip.ZipInputStream;

import spoon.Launcher;
import spoon.SpoonException;
import spoon.compiler.SpoonFile;
import spoon.compiler.SpoonFolder;
import spoon.compiler.SpoonResourceHelper;
Expand Down Expand Up @@ -167,6 +168,10 @@ public void extract(File destDir) {
ZipEntry entry;
while ((entry = zipInput.getNextEntry()) != null) {
File f = new File(destDir + File.separator + entry.getName());
if (!f.toPath().normalize().startsWith(destDir.toPath())) {
// test against zip slips
throw new SpoonException("Entry is outside of the target dir: " + entry.getName());
}
if (entry.isDirectory()) { // if it's a directory, create it
f.mkdir();
continue;
Expand Down

0 comments on commit 71f08a6

Please sign in to comment.