Class SecurityConfiguration
- All Implemented Interfaces:
Serializable
When a limit is exceeded, the conversion fails with a
ConversionException rather than consuming unbounded time or memory.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault value forgetMaxBinaryBytes(): 32 MiB.static final intDefault value forgetMaxElementCount(): about 290 times the largest sample document's element count.static final intDefault value forgetMaxGroupDepth().static final longDefault value forgetMaxOutputChars(): 64 Mi characters, about 190 times the largest sample document's output.static final longDefault value forgetMaxPictureBytes(): 16 MiB.static final intDefault value forgetMaxTableEntries(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the maximum total\binNbinary-data size per document.intReturns the maximum number of elements created from the RTF content.intReturns the maximum allowed RTF group nesting depth.longReturns the maximum length of the conversion result.longReturns the maximum number of bytes stored for a single embedded picture.intReturns the maximum number of entries allowed in an RTF header table (font table or color table).booleanReturns whether strict mode is on.voidsetMaxBinaryBytes(long maxBinaryBytes) Sets the maximum total\binNbinary-data size per document.voidsetMaxElementCount(int maxElementCount) Sets the maximum number of elements (paragraphs, spans, table cells, list items, ...) a conversion may create from the RTF content.voidsetMaxGroupDepth(int maxGroupDepth) Sets the maximum allowed RTF group nesting depth.voidsetMaxOutputChars(long maxOutputChars) Sets the maximum length of the conversion result, in characters.voidsetMaxPictureBytes(long maxPictureBytes) Sets the maximum number of bytes stored for a single embedded picture.voidsetMaxTableEntries(int maxTableEntries) Sets the maximum number of entries allowed in an RTF header table (font table or color table).voidsetStrictMode(boolean strictMode) Sets strict or lenient handling of malformed RTF.
-
Field Details
-
DEFAULT_MAX_GROUP_DEPTH
public static final int DEFAULT_MAX_GROUP_DEPTHDefault value forgetMaxGroupDepth().- See Also:
-
DEFAULT_MAX_BINARY_BYTES
public static final long DEFAULT_MAX_BINARY_BYTESDefault value forgetMaxBinaryBytes(): 32 MiB.- See Also:
-
DEFAULT_MAX_PICTURE_BYTES
public static final long DEFAULT_MAX_PICTURE_BYTESDefault value forgetMaxPictureBytes(): 16 MiB.- See Also:
-
DEFAULT_MAX_TABLE_ENTRIES
public static final int DEFAULT_MAX_TABLE_ENTRIESDefault value forgetMaxTableEntries().- See Also:
-
DEFAULT_MAX_OUTPUT_CHARS
public static final long DEFAULT_MAX_OUTPUT_CHARSDefault value forgetMaxOutputChars(): 64 Mi characters, about 190 times the largest sample document's output.- See Also:
-
DEFAULT_MAX_ELEMENT_COUNT
public static final int DEFAULT_MAX_ELEMENT_COUNTDefault value forgetMaxElementCount(): about 290 times the largest sample document's element count.- See Also:
-
-
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
\'xxescape, 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 aStructuralViolationException(aConversionException); itsgetViolation()tells which defect was found.Strict mode also rejects an input that does not start with
{\rtf, whateversetInvalidRtfHeaderActionsays. 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 aConversionException.- Parameters:
maxGroupDepth- the new limit; must be greater than zero- Throws:
IllegalArgumentException- ifmaxGroupDepthis not positive
-
getMaxBinaryBytes
public long getMaxBinaryBytes()Returns the maximum total\binNbinary-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\binNbinary-data size per document. A document that declares more raw binary bytes than this aborts the conversion with aConversionException.0disallows\bindata entirely.- Parameters:
maxBinaryBytes- the new limit; must not be negative- Throws:
IllegalArgumentException- ifmaxBinaryBytesis 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.0skips every embedded picture.- Parameters:
maxPictureBytes- the new limit; must not be negative- Throws:
IllegalArgumentException- ifmaxPictureBytesis 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 aConversionException.- Parameters:
maxTableEntries- the new limit; must be greater than zero- Throws:
IllegalArgumentException- ifmaxTableEntriesis 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 aConversionException. 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_VALUEto effectively disable the limit.- Parameters:
maxOutputChars- the new limit; must be greater than zero- Throws:
IllegalArgumentException- ifmaxOutputCharsis 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 aConversionException. Elements of the<head>, which come fromHtmlHeadConfiguration, are not counted.Use
Integer.MAX_VALUEto effectively disable the limit.- Parameters:
maxElementCount- the new limit; must be greater than zero- Throws:
IllegalArgumentException- ifmaxElementCountis not positive
-