Package org.apache.tika.config
Class OutputLimits
java.lang.Object
org.apache.tika.config.OutputLimits
- All Implemented Interfaces:
Serializable
Configuration for output and security limits.
This controls output size and various security thresholds:
writeLimit- maximum characters to write (-1 = unlimited)throwOnWriteLimit- whether to throw an exception when writeLimit is reachedmaxXmlDepth- maximum XML element nesting depth (default: 100)maxPackageEntryDepth- maximum package entry nesting depth (default: 10)zipBombThreshold- characters before zip bomb check activates (default: 1,000,000)zipBombRatio- maximum output:input ratio for zip bomb detection (default: 100)
writeLimit behavior: The writeLimit is the TOTAL characters across all documents (container + embedded). When the limit is reached:
- If
throwOnWriteLimit=false: Output is truncated,X-TIKA-writeLimitReached=trueis set - If
throwOnWriteLimit=true:WriteLimitReachedExceptionis thrown
Security limits: maxXmlDepth, maxPackageEntryDepth, and zipBomb limits always throw exceptions when exceeded (no silent truncation option).
Example configuration:
{
"parse-context": {
"output-limits": {
"writeLimit": 100000,
"throwOnWriteLimit": false,
"maxXmlDepth": 100,
"maxPackageEntryDepth": 10,
"zipBombThreshold": 1000000,
"zipBombRatio": 100
}
}
}
- Since:
- Apache Tika 4.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNo-arg constructor for Jackson deserialization.OutputLimits(int writeLimit, boolean throwOnWriteLimit, int maxXmlDepth, int maxPackageEntryDepth, long zipBombThreshold, long zipBombRatio) Constructor with all parameters. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic OutputLimitsget(ParseContext context) Helper method to get OutputLimits from ParseContext with defaults.intGets the maximum package entry nesting depth.intGets the maximum XML element nesting depth.intGets the maximum characters to write.longGets the zip bomb ratio (maximum output:input ratio).longGets the zip bomb threshold (characters before check activates).inthashCode()booleanGets whether to throw an exception when writeLimit is reached.voidsetMaxPackageEntryDepth(int maxPackageEntryDepth) Sets the maximum package entry nesting depth.voidsetMaxXmlDepth(int maxXmlDepth) Sets the maximum XML element nesting depth.voidsetThrowOnWriteLimit(boolean throwOnWriteLimit) Sets whether to throw an exception when writeLimit is reached.voidsetWriteLimit(int writeLimit) Sets the maximum characters to write.voidsetZipBombRatio(long zipBombRatio) Sets the zip bomb ratio (maximum output:input ratio).voidsetZipBombThreshold(long zipBombThreshold) Sets the zip bomb threshold (characters before check activates).toString()
-
Field Details
-
UNLIMITED
public static final int UNLIMITED- See Also:
-
-
Constructor Details
-
OutputLimits
public OutputLimits()No-arg constructor for Jackson deserialization. -
OutputLimits
public OutputLimits(int writeLimit, boolean throwOnWriteLimit, int maxXmlDepth, int maxPackageEntryDepth, long zipBombThreshold, long zipBombRatio) Constructor with all parameters.- Parameters:
writeLimit- maximum characters to write (-1 = unlimited)throwOnWriteLimit- whether to throw when write limit is reachedmaxXmlDepth- maximum XML element nesting depthmaxPackageEntryDepth- maximum package entry nesting depthzipBombThreshold- characters before zip bomb check activateszipBombRatio- maximum output:input ratio
-
-
Method Details
-
getWriteLimit
public int getWriteLimit()Gets the maximum characters to write.- Returns:
- maximum characters, or -1 for unlimited
-
setWriteLimit
public void setWriteLimit(int writeLimit) Sets the maximum characters to write.- Parameters:
writeLimit- maximum characters, or -1 for unlimited
-
isThrowOnWriteLimit
public boolean isThrowOnWriteLimit()Gets whether to throw an exception when writeLimit is reached.- Returns:
- true if an exception should be thrown
-
setThrowOnWriteLimit
public void setThrowOnWriteLimit(boolean throwOnWriteLimit) Sets whether to throw an exception when writeLimit is reached.- Parameters:
throwOnWriteLimit- true to throw an exception
-
getMaxXmlDepth
public int getMaxXmlDepth()Gets the maximum XML element nesting depth.- Returns:
- maximum XML depth
-
setMaxXmlDepth
public void setMaxXmlDepth(int maxXmlDepth) Sets the maximum XML element nesting depth.- Parameters:
maxXmlDepth- maximum XML depth
-
getMaxPackageEntryDepth
public int getMaxPackageEntryDepth()Gets the maximum package entry nesting depth.- Returns:
- maximum package entry depth
-
setMaxPackageEntryDepth
public void setMaxPackageEntryDepth(int maxPackageEntryDepth) Sets the maximum package entry nesting depth.- Parameters:
maxPackageEntryDepth- maximum package entry depth
-
getZipBombThreshold
public long getZipBombThreshold()Gets the zip bomb threshold (characters before check activates).- Returns:
- zip bomb threshold
-
setZipBombThreshold
public void setZipBombThreshold(long zipBombThreshold) Sets the zip bomb threshold (characters before check activates).- Parameters:
zipBombThreshold- zip bomb threshold
-
getZipBombRatio
public long getZipBombRatio()Gets the zip bomb ratio (maximum output:input ratio).- Returns:
- zip bomb ratio
-
setZipBombRatio
public void setZipBombRatio(long zipBombRatio) Sets the zip bomb ratio (maximum output:input ratio).- Parameters:
zipBombRatio- zip bomb ratio
-
get
Helper method to get OutputLimits from ParseContext with defaults.- Parameters:
context- the ParseContext (may be null)- Returns:
- the OutputLimits from context, or a new instance with defaults if not found
-
toString
-
equals
-
hashCode
public int hashCode()
-