Class SecurityConfiguration

java.lang.Object
com.scroogexhtml.configuration.SecurityConfiguration
All Implemented Interfaces:
Serializable

public class SecurityConfiguration extends Object implements Serializable
Nested property which holds limits that protect the converter against malformed and adversarial RTF input.

When a limit is exceeded, the conversion fails with a ConversionException rather than consuming unbounded time or memory.

See Also:
  • Field Details

  • Constructor Details

    • SecurityConfiguration

      public SecurityConfiguration()
  • Method Details

    • isStrictMode

      public boolean isStrictMode()
      Returns whether strict mode is on.
      Returns:
      true in strict mode, false in lenient mode (the default)
      See Also:
    • setStrictMode

      public void setStrictMode(boolean strictMode)
      Sets strict or lenient handling of malformed RTF.

      In lenient mode (the default) the converter repairs or skips markup that the RTF specification does not allow (for example an unbalanced group at the end of the input, a malformed \'xx escape, table cell markup outside a table) and logs a warning once per kind of defect. In strict mode the first such defect aborts the conversion with a StructuralViolationException (a ConversionException); its getViolation() tells which defect was found.

      Strict mode also rejects an input that does not start with {\rtf, whatever setInvalidRtfHeaderAction says. The resource limits of this class apply in both modes.

      Parameters:
      strictMode - true for strict mode
    • getMaxGroupDepth

      public int getMaxGroupDepth()
      Returns the maximum allowed RTF group nesting depth.
      Returns:
      the maximum number of simultaneously open RTF groups
    • setMaxGroupDepth

      public void setMaxGroupDepth(int maxGroupDepth)
      Sets the maximum allowed RTF group nesting depth. Input that nests groups deeper than this aborts the conversion with a ConversionException.
      Parameters:
      maxGroupDepth - the new limit; must be greater than zero
      Throws:
      IllegalArgumentException - if maxGroupDepth is not positive
    • getMaxBinaryBytes

      public long getMaxBinaryBytes()
      Returns the maximum total \binN binary-data size per document.
      Returns:
      the maximum number of raw binary bytes a document may declare
    • setMaxBinaryBytes

      public void setMaxBinaryBytes(long maxBinaryBytes)
      Sets the maximum total \binN binary-data size per document. A document that declares more raw binary bytes than this aborts the conversion with a ConversionException. 0 disallows \bin data entirely.
      Parameters:
      maxBinaryBytes - the new limit; must not be negative
      Throws:
      IllegalArgumentException - if maxBinaryBytes is negative
    • getMaxPictureBytes

      public long getMaxPictureBytes()
      Returns the maximum number of bytes stored for a single embedded picture.
      Returns:
      the per-picture byte limit
    • setMaxPictureBytes

      public void setMaxPictureBytes(long maxPictureBytes)
      Sets the maximum number of bytes stored for a single embedded picture. A picture whose data exceeds this is skipped (no <img> is emitted) and a warning is logged; the conversion continues. 0 skips every embedded picture.
      Parameters:
      maxPictureBytes - the new limit; must not be negative
      Throws:
      IllegalArgumentException - if maxPictureBytes is negative
    • getMaxTableEntries

      public int getMaxTableEntries()
      Returns the maximum number of entries allowed in an RTF header table (font table or color table).
      Returns:
      the per-table entry limit
    • setMaxTableEntries

      public void setMaxTableEntries(int maxTableEntries)
      Sets the maximum number of entries allowed in an RTF header table (font table or color table). A table that declares more entries aborts the conversion with a ConversionException.
      Parameters:
      maxTableEntries - the new limit; must be greater than zero
      Throws:
      IllegalArgumentException - if maxTableEntries is not positive
    • getMaxOutputChars

      public long getMaxOutputChars()
      Returns the maximum length of the conversion result.
      Returns:
      the maximum number of characters of the converted markup
    • setMaxOutputChars

      public void setMaxOutputChars(long maxOutputChars)
      Sets the maximum length of the conversion result, in characters. A conversion whose result would be longer aborts with a ConversionException. The text taken from the RTF is counted while the document is built, so an expanding input is stopped early; the finished result, markup included, is checked once more.

      Use Long.MAX_VALUE to effectively disable the limit.

      Parameters:
      maxOutputChars - the new limit; must be greater than zero
      Throws:
      IllegalArgumentException - if maxOutputChars is not positive
    • getMaxElementCount

      public int getMaxElementCount()
      Returns the maximum number of elements created from the RTF content.
      Returns:
      the per-conversion element limit
    • setMaxElementCount

      public void setMaxElementCount(int maxElementCount)
      Sets the maximum number of elements (paragraphs, spans, table cells, list items, ...) a conversion may create from the RTF content. A document that needs more aborts the conversion with a ConversionException. Elements of the <head>, which come from HtmlHeadConfiguration, are not counted.

      Use Integer.MAX_VALUE to effectively disable the limit.

      Parameters:
      maxElementCount - the new limit; must be greater than zero
      Throws:
      IllegalArgumentException - if maxElementCount is not positive