public class ZipSecureFile
extends org.apache.commons.compress.archivers.zip.ZipFile
ZipFile
in order to check the
entries for zip bombs
while reading the archive.
The alert limits can be globally defined via setMaxEntrySize(long)
and setMinInflateRatio(double)
.
Modifier and Type | Field and Description |
---|---|
static String |
MAX_FILE_COUNT_MSG |
Constructor and Description |
---|
ZipSecureFile(File file) |
ZipSecureFile(String name) |
Modifier and Type | Method and Description |
---|---|
static long |
getGraceEntrySize()
Returns the current threshold for decompressed data in zip entries that are regarded as too small
to worry about from a Zip Bomb perspective (default is 100Kb).
|
ZipArchiveThresholdInputStream |
getInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry)
Returns an input stream for reading the contents of the specified
zip file entry.
|
static long |
getMaxEntrySize()
Returns the current maximum allowed uncompressed file size.
|
static long |
getMaxFileCount()
Returns the current maximum file count that is used.
|
static long |
getMaxTextSize()
Returns the current maximum allowed text size.
|
static double |
getMinInflateRatio()
Returns the current minimum compression rate that is used.
|
String |
getName()
Returns the path name of the ZIP file.
|
static void |
setGraceEntrySize(long graceEntrySize)
Sets the grace entry size of a single zip entry.
|
static void |
setMaxEntrySize(long maxEntrySize)
Sets the maximum file size of a single zip entry.
|
static void |
setMaxFileCount(long maxFileCount)
Sets the maximum file count that we allow inside zip files that we read -
including OOXML files like xlsx, docx, pptx, etc.
|
static void |
setMaxTextSize(long maxTextSize)
Sets the maximum number of characters of text that are
extracted before an exception is thrown during extracting
text from documents.
|
static void |
setMinInflateRatio(double ratio)
Sets the ratio between de- and inflated bytes to detect zipbomb.
|
canReadEntryData, close, closeQuietly, copyRawEntries, finalize, getContentBeforeFirstLocalFileHeader, getEncoding, getEntries, getEntries, getEntriesInPhysicalOrder, getEntriesInPhysicalOrder, getEntry, getFirstLocalFileHeaderOffset, getRawInputStream, getUnixSymlink
public static final String MAX_FILE_COUNT_MSG
public ZipSecureFile(File file) throws IOException
IOException
public ZipSecureFile(String name) throws IOException
IOException
public static void setMinInflateRatio(double ratio)
ratio
- the ratio between de- and inflated bytes to detect zipbombpublic static double getMinInflateRatio()
public static long getMaxFileCount()
public static void setMaxFileCount(long maxFileCount)
maxFileCount
- The max accepted file countpublic static void setMaxEntrySize(long maxEntrySize)
maxEntrySize
- the max. file size of a single zip entryIllegalArgumentException
- for negative maxEntrySizepublic static long getMaxEntrySize()
public static void setGraceEntrySize(long graceEntrySize)
graceEntrySize
- the grace entry size of a single zip entryIllegalArgumentException
- for negative graceEntrySizepublic static long getGraceEntrySize()
public static void setMaxTextSize(long maxTextSize)
maxTextSize
- the max. file size of a single zip entryIllegalArgumentException
- for negative maxTextSizepublic static long getMaxTextSize()
setMaxTextSize(long)
public ZipArchiveThresholdInputStream getInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry) throws IOException
Closing this ZIP file will, in turn, close all input streams that have been returned by invocations of this method.
getInputStream
in class org.apache.commons.compress.archivers.zip.ZipFile
entry
- the zip file entryIOException
- if an I/O error has occurredIllegalStateException
- if the zip file has been closedpublic String getName()