Skip to content

Commit

Permalink
Fixed security issue with malicious zip files
Browse files Browse the repository at this point in the history
Kudos to the Snyk Security Research Team for the finding + fix.
  • Loading branch information
lvca committed May 31, 2018
1 parent c65a0ef commit 1dd7549
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,24 @@ public static List<String> compressDirectory(final String sourceFolderName, fina
public static void uncompressDirectory(final InputStream in, final String out, final OCommandOutputListener iListener)
throws IOException {
final File outdir = new File(out);
final String targetDirPath = outdir.getCanonicalPath() + File.separator;

final ZipInputStream zin = new ZipInputStream(in);
try {
ZipEntry entry;
String name, dir;
while ((entry = zin.getNextEntry()) != null) {
name = entry.getName();

if (name.startsWith("/") || name.contains(".."))
throw new IOException("Invalid name '" + name + "' in the zip file");
final File file = new File(outdir, name);
if (!file.getCanonicalPath().startsWith(targetDirPath))
throw new IOException("Expanding '" + entry.getName() + "' would create file outside of directory '" + outdir + "'");

if (entry.isDirectory()) {
mkdirs(outdir, name);
continue;
}

/*
* this part is necessary because file entry can come before directory entry where is file located i.e.: /foo/foo.txt /foo/
*/
Expand Down

0 comments on commit 1dd7549

Please sign in to comment.