diff --git a/CHANGELOG.md b/CHANGELOG.md index 83ecc11a5..05070afcd 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.28(2024-04-25) +# 5.8.28(2024-04-28) ### 🐣新特性 * 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee) @@ -27,6 +27,7 @@ * 【cron 】 修复CronPattern.nextMatchAfter匹配初始值问题(issue#I9FQUA@Gitee) * 【core 】 修复FileUtil.copyFile没有创建父目录导致的问题(issue#3557@Github) * 【http 】 修复HttpDownloader全局超时无效问题(issue#3556@Github) +* 【core 】 修复ZipReader.checkZipBomb遇到空目录报错问题(issue#I9K494@Gitee) ------------------------------------------------------------------------------------------------------------- # 5.8.27(2024-03-29) diff --git a/hutool-core/src/main/java/cn/hutool/core/compress/ZipReader.java b/hutool-core/src/main/java/cn/hutool/core/compress/ZipReader.java index be6edc8cd..384b6d2a7 100755 --- a/hutool-core/src/main/java/cn/hutool/core/compress/ZipReader.java +++ b/hutool-core/src/main/java/cn/hutool/core/compress/ZipReader.java @@ -252,12 +252,14 @@ public class ZipReader implements Closeable { * @return 检查后的{@link ZipEntry} */ private ZipEntry checkZipBomb(ZipEntry entry) { - if(maxSizeDiff < 0){ - return entry; - } if (null == entry) { return null; } + if(maxSizeDiff < 0 || entry.isDirectory()){ + // 目录不检查 + return entry; + } + final long compressedSize = entry.getCompressedSize(); final long uncompressedSize = entry.getSize(); if (compressedSize < 0 || uncompressedSize < 0 || diff --git a/hutool-core/src/test/java/cn/hutool/core/util/IssueI9K494Test.java b/hutool-core/src/test/java/cn/hutool/core/util/IssueI9K494Test.java new file mode 100644 index 000000000..6381366ba --- /dev/null +++ b/hutool-core/src/test/java/cn/hutool/core/util/IssueI9K494Test.java @@ -0,0 +1,25 @@ +package cn.hutool.core.util; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; + +public class IssueI9K494Test { + @Test + @Ignore + public void unzipTest() { + FileInputStream inputStream = IoUtil.toStream(FileUtil.file("d:/test/unzip5616889482468994725.zip")); + ZipUtil.unzip(inputStream, FileUtil.file("d:/test/"), StandardCharsets.UTF_8); + } + + @Test + @Ignore + public void unzipTest2() { + FileInputStream inputStream = IoUtil.toStream(FileUtil.file("d:/test/test.zip")); + ZipUtil.unzip(inputStream, FileUtil.file("d:/test/"), StandardCharsets.UTF_8); + } +}