zip炸弹

  故障系统有人提了zip炸弹的故障,了解了一些关于zip炸弹的常识。 

       42.zip 是很有名的zip炸弹。一个42KB的文件,解压完其实是个4.5PB的“炸弹”。

       更有甚者,一个叫做 droste.zip 的大小为 28 KB 的文件,一旦被打开了以后,就会无限解压缩生成一份同样的文件,直到永远。

       zip炸弹文件中有大量刻意重复的数据,这种重复数据在压缩的时候是可以被丢弃的,这也就是压缩后的文件其实并不大的原因。

       可以看一下 https://blog.csdn.net/j2IaYU7Y/article/details/82321082

 

  

    How can I protect myself from a zip bomb?

       https://stackoverflow.com/questions/1459080/how-can-i-protect-myself-from-a-zip-bomb#

       文中没有具体的解决方案,但是我觉得2个思路是挺不错的:

        1. a robust solution is to stream the data out, and stop when you have had enough. In Java, use ZipInputStream rather than ZipFile. The latter also requires you to store the data in a temporary file, which is also not the greatest of ideas.

        尝试解压,超过设定的最大字节数后就报错

       2.Deny any compressed files that contain compressed files. Use ZipFile.entries() to retrieve a list of files, then ZipEntry.getName() to find the file extension.

         压缩文件中如果还包含压缩文件则拒绝,内部的压缩文件可以考虑前几个字节的魔数来判断,没有实际验证过。正常的压缩文件类型都应该以固定的文件头标识开始。

         

        各类文件的文件头标志:  https://blog.csdn.net/rrrfff/article/details/7484109

       

posted on 2019-11-11 22:14  lnlvinso  阅读(10062)  评论(0编辑  收藏  举报