Skip to content

Commit

Permalink
#462 Append file separator to path check only if required
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed Aug 30, 2022
1 parent 5024127 commit 0ffcaec
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ private void assertCanonicalPathsAreSame(File outputFile, String outputPath, Fil
outputFileCanonicalPath = outputFileCanonicalPath + FILE_SEPARATOR;
}

String outputCanonicalPath = (new File(outputPath).getCanonicalPath());
if (!outputCanonicalPath.endsWith(FILE_SEPARATOR)) {
outputCanonicalPath += FILE_SEPARATOR;
}

// make sure no file is extracted outside the target directory (a.k.a. zip slip)
String outputCanonicalPath = (new File(outputPath).getCanonicalPath()) + File.separator;
if (!outputFileCanonicalPath.startsWith(outputCanonicalPath)) {
throw new ZipException("illegal file name that breaks out of the target directory: "
+ fileHeader.getFileName());
Expand Down

0 comments on commit 0ffcaec

Please sign in to comment.