Class ZipFileReader
java.lang.Object
com.itextpdf.commons.utils.ZipFileReader
- All Implemented Interfaces:
Closeable, AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate intprivate doubleprivate intprivate final ZipFile -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Get all file entries paths inside the reading zip file.readFromZip(String fileName) Read single file from zip.voidsetThresholdEntries(int thresholdEntries) Sets the maximum number of file entries in the archive to prevent a Zip Bomb Attack.voidsetThresholdRatio(double thresholdRatio) Sets the maximum ratio between compressed and uncompressed data to prevent a Zip Bomb Attack.voidsetThresholdSize(int thresholdSize) Sets the maximum total uncompressed data size to prevent a Zip Bomb Attack.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
zipFile
-
thresholdSize
private int thresholdSize -
thresholdEntries
private int thresholdEntries -
thresholdRatio
private double thresholdRatio
-
-
Constructor Details
-
ZipFileReader
Creates an instance for zip file reading.- Parameters:
archivePath- the path to the zip file to read- Throws:
IOException- if some I/O exception occurs
-
-
Method Details
-
getFileNames
Get all file entries paths inside the reading zip file.- Returns:
- the
Setof all file entries paths - Throws:
IOException- if some I/O exception occurs
-
readFromZip
Read single file from zip.- Parameters:
fileName- the file path inside zip to read- Returns:
- the
InputStreamrepresents read file content - Throws:
IOException- if some I/O exception occurs
-
setThresholdSize
public void setThresholdSize(int thresholdSize) Sets the maximum total uncompressed data size to prevent a Zip Bomb Attack. Default value is 1 GB (1000000000).- Parameters:
thresholdSize- the threshold for maximum total size of the uncompressed data
-
setThresholdEntries
public void setThresholdEntries(int thresholdEntries) Sets the maximum number of file entries in the archive to prevent a Zip Bomb Attack. Default value is 10000.- Parameters:
thresholdEntries- maximum number of file entries in the archive
-
setThresholdRatio
public void setThresholdRatio(double thresholdRatio) Sets the maximum ratio between compressed and uncompressed data to prevent a Zip Bomb Attack. In general the data compression ratio for most of the legit archives is 1 to 3. Default value is 10.- Parameters:
thresholdRatio- maximum ratio between compressed and uncompressed data
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-