diff --git a/src/main/java/cn/springmvc/mybatis/common/utils/ZipUtil.java b/src/main/java/cn/springmvc/mybatis/common/utils/ZipUtil.java index 3bf47a3..78fbe43 100644 --- a/src/main/java/cn/springmvc/mybatis/common/utils/ZipUtil.java +++ b/src/main/java/cn/springmvc/mybatis/common/utils/ZipUtil.java @@ -33,7 +33,7 @@ public static boolean compress(List files, String zipPath, boolean isDel) } try { // ----压缩文件: - FileOutputStream stream = new FileOutputStream(zipPath); + FileOutputStream stream = new FileOutputStream(new File(zipPath)); CheckedOutputStream checkedStream = new CheckedOutputStream(stream, new CRC32());// 使用指定校验和创建输出流 ZipOutputStream zipStream = new ZipOutputStream(checkedStream); BufferedOutputStream out = new BufferedOutputStream(zipStream); @@ -98,7 +98,11 @@ public static void unZipFiles(File zipfile, String descDir) { entry = ((ZipEntry) entries.nextElement()); zipEntryName = entry.getName(); in = zf.getInputStream(entry); - out = new FileOutputStream(descDir + zipEntryName); + final File zipEntryFile = new File(descDir, zipEntryName); + if (!zipEntryFile.toPath().normalize().startsWith(descDir)) { + throw new RuntimeException("Bad zip entry"); + } + out = new FileOutputStream(zipEntryFile); buf1 = new byte[1024]; len = 0; while ((len = in.read(buf1)) > 0) {