Class OutputLimits

java.lang.Object
org.apache.tika.config.OutputLimits
All Implemented Interfaces:
Serializable

public class OutputLimits extends Object implements 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 reached
  • maxXmlDepth - 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=true is set
  • If throwOnWriteLimit=true: WriteLimitReachedException is 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
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    No-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 Type
    Method
    Description
    boolean
     
    get(ParseContext context)
    Helper method to get OutputLimits from ParseContext with defaults.
    int
    Gets the maximum package entry nesting depth.
    int
    Gets the maximum XML element nesting depth.
    int
    Gets the maximum characters to write.
    long
    Gets the zip bomb ratio (maximum output:input ratio).
    long
    Gets the zip bomb threshold (characters before check activates).
    int
     
    boolean
    Gets whether to throw an exception when writeLimit is reached.
    void
    setMaxPackageEntryDepth(int maxPackageEntryDepth)
    Sets the maximum package entry nesting depth.
    void
    setMaxXmlDepth(int maxXmlDepth)
    Sets the maximum XML element nesting depth.
    void
    setThrowOnWriteLimit(boolean throwOnWriteLimit)
    Sets whether to throw an exception when writeLimit is reached.
    void
    setWriteLimit(int writeLimit)
    Sets the maximum characters to write.
    void
    setZipBombRatio(long zipBombRatio)
    Sets the zip bomb ratio (maximum output:input ratio).
    void
    setZipBombThreshold(long zipBombThreshold)
    Sets the zip bomb threshold (characters before check activates).
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • 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 reached
      maxXmlDepth - maximum XML element nesting depth
      maxPackageEntryDepth - maximum package entry nesting depth
      zipBombThreshold - characters before zip bomb check activates
      zipBombRatio - 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

      public static OutputLimits get(ParseContext context)
      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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object