iText 9.6.0 API
iText.Kernel.Pdf.MemoryLimitsAwareHandler Class Reference

Enforces configurable limits intended to protect PDF reading/parsing against excessive memory consumption. More...

Public Member Functions

  MemoryLimitsAwareHandler ()
  Creates a MemoryLimitsAwareHandler to handle decompression of PDF streams and other memory-related limits during reading. More...
 
  MemoryLimitsAwareHandler (long documentSize)
  Creates a MemoryLimitsAwareHandler with calculated memory limits for decompression and xref structures based on the provided document size. More...
 
virtual iText.Kernel.Pdf.MemoryLimitsAwareHandler  CreateNewInstance ()
  Creates a new instance of MemoryLimitsAwareHandler by copying settings from this instance of MemoryLimitsAwareHandler. More...
 
virtual int  GetMaxSizeOfSingleDecompressedPdfStream ()
  Returns the maximum allowed size (in bytes) of a single decompressed PDF stream. More...
 
virtual iText.Kernel.Pdf.MemoryLimitsAwareHandler  SetMaxSizeOfSingleDecompressedPdfStream (int maxSizeOfSingleDecompressedPdfStream)
  Sets the maximum allowed size which can be occupied by a single decompressed pdf stream. More...
 
virtual long  GetMaxSizeOfDecompressedPdfStreamsSum ()
  Gets the maximum allowed size which can be occupied by all decompressed pdf streams. More...
 
virtual iText.Kernel.Pdf.MemoryLimitsAwareHandler  SetMaxSizeOfDecompressedPdfStreamsSum (long maxSizeOfDecompressedPdfStreamsSum)
  Sets the maximum allowed size which can be occupied by all decompressed pdf streams. More...
 
virtual bool  IsMemoryLimitsAwarenessRequiredOnDecompression (PdfArray filters)
  Performs a check if the PdfStream with provided setup of the filters requires memory limits awareness during decompression. More...
 
virtual int  GetMaxNumberOfElementsInXrefStructure ()
  Gets maximum number of elements in xref structure. More...
 
virtual long  GetMaxXObjectsSizePerPage ()
  Gets maximum page size. More...
 
virtual void  SetMaxXObjectsSizePerPage (long maxPageSize)
  Sets maximum page size. More...
 
virtual void  SetMaxNumberOfElementsInXrefStructure (int maxNumberOfElementsInXrefStructure)
  Sets maximum number of elements in xref structure. More...
 
virtual void  CheckIfXrefStructureExceedsTheLimit (int requestedCapacity)
  Performs a check of possible extension of xref structure. More...
 
virtual void  CheckIfPageSizeExceedsTheLimit (long totalXObjectsSize)
 

Static Package Functions

static int  CalculateMaxElementsInXref (long documentSizeInBytes)
  Calculate max number of elements allowed in xref table based on the size of the document, achieving max limit at 100MB. More...
 

Detailed Description

Enforces configurable limits intended to protect PDF reading/parsing against excessive memory consumption.

Enforces configurable limits intended to protect PDF reading/parsing against excessive memory consumption.

The handler is primarily used during decoding (decompression) of PDF streams, but also guards against other potentially unbounded structures during reading, e.g. cross-reference (xref) table growth and per-page XObject usage.

How it is configured

A configured handler can be set on ReaderProperties and will be used by PdfReader when opening a document.

See also
ReaderProperties.SetMemoryLimitsAwareHandler(MemoryLimitsAwareHandler), iText.Kernel.Exceptions.MemoryLimitsAwareException

Constructor & Destructor Documentation

◆ MemoryLimitsAwareHandler() [1/2]

iText.Kernel.Pdf.MemoryLimitsAwareHandler.MemoryLimitsAwareHandler ( )
inline

Creates a MemoryLimitsAwareHandler to handle decompression of PDF streams and other memory-related limits during reading.

◆ MemoryLimitsAwareHandler() [2/2]

iText.Kernel.Pdf.MemoryLimitsAwareHandler.MemoryLimitsAwareHandler ( long  documentSize )
inline

Creates a MemoryLimitsAwareHandler with calculated memory limits for decompression and xref structures based on the provided document size.

Parameters
documentSize the size of the document (in bytes).

Member Function Documentation

◆ CalculateMaxElementsInXref()

static int iText.Kernel.Pdf.MemoryLimitsAwareHandler.CalculateMaxElementsInXref ( long  documentSizeInBytes )
inlinestaticpackage

Calculate max number of elements allowed in xref table based on the size of the document, achieving max limit at 100MB.

Parameters
documentSizeInBytes document size in bytes.
Returns
calculated limit.

◆ CheckIfXrefStructureExceedsTheLimit()

virtual void iText.Kernel.Pdf.MemoryLimitsAwareHandler.CheckIfXrefStructureExceedsTheLimit ( int  requestedCapacity )
inlinevirtual

Performs a check of possible extension of xref structure.

Parameters
requestedCapacity capacity to which we need to expand xref array.

◆ CreateNewInstance()

virtual iText.Kernel.Pdf.MemoryLimitsAwareHandler iText.Kernel.Pdf.MemoryLimitsAwareHandler.CreateNewInstance ( )
inlinevirtual

Creates a new instance of MemoryLimitsAwareHandler by copying settings from this instance of MemoryLimitsAwareHandler.

Returns
a new instance of MemoryLimitsAwareHandler.

◆ GetMaxNumberOfElementsInXrefStructure()

virtual int iText.Kernel.Pdf.MemoryLimitsAwareHandler.GetMaxNumberOfElementsInXrefStructure ( )
inlinevirtual

Gets maximum number of elements in xref structure.

Returns
maximum number of elements in xref structure.

◆ GetMaxSizeOfDecompressedPdfStreamsSum()

virtual long iText.Kernel.Pdf.MemoryLimitsAwareHandler.GetMaxSizeOfDecompressedPdfStreamsSum ( )
inlinevirtual

Gets the maximum allowed size which can be occupied by all decompressed pdf streams.

Returns
the maximum allowed size value which streams may occupy

◆ GetMaxSizeOfSingleDecompressedPdfStream()

virtual int iText.Kernel.Pdf.MemoryLimitsAwareHandler.GetMaxSizeOfSingleDecompressedPdfStream ( )
inlinevirtual

Returns the maximum allowed size (in bytes) of a single decompressed PDF stream.

Returns
maximum allowed size of a single decompressed stream in bytes.

◆ GetMaxXObjectsSizePerPage()

virtual long iText.Kernel.Pdf.MemoryLimitsAwareHandler.GetMaxXObjectsSizePerPage ( )
inlinevirtual

Gets maximum page size.

Returns
maximum page size.

◆ IsMemoryLimitsAwarenessRequiredOnDecompression()

virtual bool iText.Kernel.Pdf.MemoryLimitsAwareHandler.IsMemoryLimitsAwarenessRequiredOnDecompression ( PdfArray  filters )
inlinevirtual

Performs a check if the PdfStream with provided setup of the filters requires memory limits awareness during decompression.

Parameters
filters is an PdfArray of names of filters
Returns
true if PDF stream is suspicious and false otherwise

◆ SetMaxNumberOfElementsInXrefStructure()

virtual void iText.Kernel.Pdf.MemoryLimitsAwareHandler.SetMaxNumberOfElementsInXrefStructure ( int  maxNumberOfElementsInXrefStructure )
inlinevirtual

Sets maximum number of elements in xref structure.

Parameters
maxNumberOfElementsInXrefStructure maximum number of elements in xref structure.

◆ SetMaxSizeOfDecompressedPdfStreamsSum()

virtual iText.Kernel.Pdf.MemoryLimitsAwareHandler iText.Kernel.Pdf.MemoryLimitsAwareHandler.SetMaxSizeOfDecompressedPdfStreamsSum ( long  maxSizeOfDecompressedPdfStreamsSum )
inlinevirtual

Sets the maximum allowed size which can be occupied by all decompressed pdf streams.

Sets the maximum allowed size which can be occupied by all decompressed pdf streams. This value can be limited by the maximum expected PDF file size when it's completely decompressed. Setting this value correlates with the maximum processing time spent on document reading

iText will throw an exception if during decompression pdf streams which were identified as requiring memory limits awareness occupy more memory than allowed.

Parameters
maxSizeOfDecompressedPdfStreamsSum he maximum allowed size which can be occupied by all decompressed pdf streams.
Returns
this MemoryLimitsAwareHandler instance.
See also
IsMemoryLimitsAwarenessRequiredOnDecompression(PdfArray)

◆ SetMaxSizeOfSingleDecompressedPdfStream()

virtual iText.Kernel.Pdf.MemoryLimitsAwareHandler iText.Kernel.Pdf.MemoryLimitsAwareHandler.SetMaxSizeOfSingleDecompressedPdfStream ( int  maxSizeOfSingleDecompressedPdfStream )
inlinevirtual

Sets the maximum allowed size which can be occupied by a single decompressed pdf stream.

Sets the maximum allowed size which can be occupied by a single decompressed pdf stream. This value correlates with maximum heap size. This value should not exceed limit of the heap size.

iText will throw an exception if during decompression a pdf stream which was identified as requiring memory limits awareness occupies more memory than allowed.

Parameters
maxSizeOfSingleDecompressedPdfStream the maximum allowed size which can be occupied by a single decompressed pdf stream.
Returns
this MemoryLimitsAwareHandler instance.
See also
IsMemoryLimitsAwarenessRequiredOnDecompression(PdfArray)

◆ SetMaxXObjectsSizePerPage()

virtual void iText.Kernel.Pdf.MemoryLimitsAwareHandler.SetMaxXObjectsSizePerPage ( long  maxPageSize )
inlinevirtual

Sets maximum page size.

Parameters
maxPageSize maximum page size.