QuickParser presented in
PDFBOX-1104 by Jeremy Villalobos.
| Modifier and Type | Field and Description |
|---|---|
| private AccessPermission | |
| private BruteForceParser | |
| private final Map | decompressedObjects
Intermediate cache. |
| private static final int | DEFAULT_TRAIL_BYTECOUNT
How many trailing bytes to read for EOF marker. |
| private PDEncryption | |
| private static final byte[] | |
| private static final byte[] | |
| protected static final char[] | EOF_MARKER
EOF-marker. |
| private static final String | |
| private static final String | |
| protected long | fileLen
file length. |
| protected boolean | |
| private boolean | isLenient
is parser using auto healing capacity ? |
| private String | |
| private InputStream | |
| private static final Log | |
| private static final long | |
| protected static final char[] | OBJ_MARKER
obj-marker. |
| private String | |
| private static final String | |
| private static final String | |
| private int | readTrailBytes
how many trailing bytes to read for EOF marker. |
| protected SecurityHandler | securityHandler
The security handler. |
| private static final char[] | |
| private final byte[] | |
| private static final int | |
| public static final String | SYSPROP_EOFLOOKUPRANGE
The range within the %%EOF marker will be searched. |
| private boolean | |
| private static final int | |
| private static final char[] | |
| protected XrefTrailerResolver | xrefTrailerResolver
Collects all Xref/trailer objects and resolves them into single object using startxref reference. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | COSParser(RandomAccessRead
input representing the pdf. source, String password to be used for decryption. password, InputStream key store to be used for decryption when using public key security keyStore, String alias to be used for decryption when using public key security keyAlias)Constructor for encrypted pdfs. |
| public | COSParser(RandomAccessRead
input representing the pdf. source, String password to be used for decryption. password, InputStream key store to be used for decryption when using public key security keyStore, String alias to be used for decryption when using public key security keyAlias, RandomAccessStreamCache.a function to create an instance of the stream cache streamCacheCreateFunctionConstructor for encrypted pdfs. |
| Modifier and Type | Method and Description |
|---|---|
| private long | Returns: the fixed offsetthe given offset where to look at objectOffset)Try to find a fixed offset for the given xref table/stream. |
| protected void | checkPages(COSDictionary
the root dictionary of the pdf root)Check if all entries of the pages dictionary are present. |
| private int | |
| private long | Returns: the revised offsetCheck if the cross reference table/stream can be found at the current offset. |
| private void | checkXrefOffsets()
Check the XRef table by dereferencing all objects and fixing the offset if necessary. |
| private boolean | Returns: the revised offsetthe expected start offset of the XRef stream startXRefOffset)Check if the cross reference stream can be found at the current offset. |
| public RandomAccessReadView | createRandomAccessReadView(long
start position within the underlying random access read startPosition, long stream length streamLength)Implements org. Creates a random access read view starting at the given position with the given length. |
| public COSBase | dereferenceCOSObject(COSObject
the COSObject which references the COSBase object to be dereferenced. obj)Implements org. Dereference the COSBase object which is referenced by the given COSObject. |
| private COSObjectKey | Returns: returns the found/fixed object keythe key of object we are looking for objectKey, long the offset where to look offset, Map<COSObjectKey, Long> a map with with all known xref entries xrefOffset)Check if the given object can be found at the given offset. |
| protected AccessPermission | Returns: The access permission of document that was parsed.This will get the AccessPermission. |
| private BruteForceParser | |
| protected PDEncryption | Returns: The encryption dictionary of the document that was parsed.This will get the encryption dictionary. |
| private COSNumber | |
| private Long | |
| private long | |
| private void | |
| public boolean | |
| private boolean | Returns: true if the bytes are in place, false if notthe bytes of the string to look for string)Checks if the given string can be found at the current offset. |
| protected boolean | Returns: true if the bytes are in place, false if notthe bytes of the string to look for string)Checks if the given string can be found at the current offset. |
| protected int | Returns: start offset of pattern within buffer or-1 if pattern could not be foundpattern to search for pattern, final byte[] buffer to search pattern in buf, final int offset (exclusive) where lookup starts at endOff)Searches last appearance of pattern within buffer. |
| protected COSStream | Returns: parsed pdf stream.dictionary that goes with this stream. dic)This will read a COSStream from the input stream using length attribute within dictionary. |
| protected boolean | |
| private COSBase | |
| private boolean | |
| protected synchronized COSBase | Returns: the parsed object (which is also added to document object)key of object to be parsed objKey, boolean if requireExistingNotCompressedObj)true the object to be parsed must be defined in xref
(comment: null objects may be missing from xref) and it must not be a compressed object within object stream
(this is used to circumvent being stuck in a loop in a malicious PDF)Parse the object for the given object key. |
| protected COSBase | Returns: the parsed objectthe number of the offset stream objstmObjNr, COSObjectKey the key of the object to be parsed key)Parse the object with the given key from the object stream with the given number. |
| protected boolean | |
| private long | Returns: the startxref value or -1 on parsing errorThis will parse the startxref section from the stream. |
| private boolean | Returns: false on parsing errorThis will parse the trailer from the stream and add it to the state. |
| private COSDictionary | Returns: the trailer dictionarystart offset of the first table startXRefOffset)Parses cross reference tables. |
| private long | Returns: value of PREV item in dictionary or-1 if no such item existsParses an xref object stream starting with indirect object id. |
| protected boolean | Returns: false on parsing errorthe offset to start at startByteOffset)This will parse the xref table from the stream and add it to the state The XrefTable contents are ignored. |
| protected void | |
| private long | readUntilEndStream(final EndstreamFilterStream
stream we write out to. out)This method will read through the current stream object until we find the keyword "endstream" meaning we're at the end of this object. |
| protected boolean | Returns: true if the xref trailer resolver should be resetIndicates whether the xref trailer resolver should be reset or not. |
| protected COSDictionary | Returns: a COSDictionary containing the trailer informationRead the trailer information and provide a COSDictionary containing the trailer information. |
| public void | setEOFLookupRange(int
number of trailing bytes byteCount)Sets how many trailing bytes of PDF file are searched for EOF marker and 'startxref' marker. |
| protected void | |
| private boolean | |
| private boolean |
| accessPermission | back to summary |
|---|---|
| private AccessPermission accessPermission | |
| bruteForceParser | back to summary |
|---|---|
| private BruteForceParser bruteForceParser | |
| decompressedObjects | back to summary |
|---|---|
| private final Map<Long, Map<COSObjectKey, COSBase>> decompressedObjects Intermediate cache. Contains all objects of already read compressed object streams. Objects are removed after dereferencing them. | |
| DEFAULT_TRAIL_BYTECOUNT | back to summary |
|---|---|
| private static final int DEFAULT_TRAIL_BYTECOUNT How many trailing bytes to read for EOF marker. | |
| encryption | back to summary |
|---|---|
| private PDEncryption encryption | |
| ENDOBJ | back to summary |
|---|---|
| private static final byte[] ENDOBJ | |
| ENDSTREAM | back to summary |
|---|---|
| private static final byte[] ENDSTREAM | |
| EOF_MARKER | back to summary |
|---|---|
| protected static final char[] EOF_MARKER EOF-marker. | |
| FDF_DEFAULT_VERSION | back to summary |
|---|---|
| private static final String FDF_DEFAULT_VERSION | |
| FDF_HEADER | back to summary |
|---|---|
| private static final String FDF_HEADER | |
| fileLen | back to summary |
|---|---|
| protected long fileLen file length. | |
| initialParseDone | back to summary |
|---|---|
| protected boolean initialParseDone | |
| isLenient | back to summary |
|---|---|
| private boolean isLenient is parser using auto healing capacity ? | |
| keyAlias | back to summary |
|---|---|
| private String keyAlias | |
| keyStoreInputStream | back to summary |
|---|---|
| private InputStream keyStoreInputStream | |
| LOG | back to summary |
|---|---|
| private static final Log LOG | |
| MINIMUM_SEARCH_OFFSET | back to summary |
|---|---|
| private static final long MINIMUM_SEARCH_OFFSET | |
| OBJ_MARKER | back to summary |
|---|---|
| protected static final char[] OBJ_MARKER obj-marker. | |
| password | back to summary |
|---|---|
private String password
| |
| PDF_DEFAULT_VERSION | back to summary |
|---|---|
| private static final String PDF_DEFAULT_VERSION | |
| PDF_HEADER | back to summary |
|---|---|
| private static final String PDF_HEADER | |
| readTrailBytes | back to summary |
|---|---|
| private int readTrailBytes how many trailing bytes to read for EOF marker. | |
| securityHandler | back to summary |
|---|---|
| protected SecurityHandler<? extends ProtectionPolicy> securityHandler The security handler. | |
| STARTXREF | back to summary |
|---|---|
| private static final char[] STARTXREF | |
| strmBuf | back to summary |
|---|---|
| private final byte[] strmBuf | |
| STRMBUFLEN | back to summary |
|---|---|
| private static final int STRMBUFLEN | |
| SYSPROP_EOFLOOKUPRANGE | back to summary |
|---|---|
| public static final String SYSPROP_EOFLOOKUPRANGE The range within the %%EOF marker will be searched. Useful if there are additional characters after %%EOF within the PDF. | |
| trailerWasRebuild | back to summary |
|---|---|
| private boolean trailerWasRebuild | |
| X | back to summary |
|---|---|
| private static final int X | |
| XREF_TABLE | back to summary |
|---|---|
| private static final char[] XREF_TABLE | |
| xrefTrailerResolver | back to summary |
|---|---|
| protected XrefTrailerResolver xrefTrailerResolver Collects all Xref/trailer objects and resolves them into single object using startxref reference. | |
| COSParser | back to summary |
|---|---|
| public COSParser(RandomAccessRead source) throws IOException Default constructor.
| |
| COSParser | back to summary |
|---|---|
| public COSParser(RandomAccessRead source, String password, InputStream keyStore, String keyAlias) throws IOException Constructor for encrypted pdfs.
| |
| COSParser | back to summary |
|---|---|
| public COSParser(RandomAccessRead source, String password, InputStream keyStore, String keyAlias, RandomAccessStreamCache. Constructor for encrypted pdfs.
| |
| calculateXRefFixedOffset | back to summary |
|---|---|
| private long calculateXRefFixedOffset(long objectOffset) throws IOException Try to find a fixed offset for the given xref table/stream.
| |
| checkPages | back to summary |
|---|---|
| protected void checkPages(COSDictionary root) throws IOException Check if all entries of the pages dictionary are present. Those which can't be dereferenced are removed.
| |
| checkPagesDictionary | back to summary |
|---|---|
| private int checkPagesDictionary(COSDictionary pagesDict, Set<COSObject> set) | |
| checkXRefOffset | back to summary |
|---|---|
| private long checkXRefOffset(long startXRefOffset) throws IOException Check if the cross reference table/stream can be found at the current offset.
| |
| checkXrefOffsets | back to summary |
|---|---|
| private void checkXrefOffsets() throws IOException Check the XRef table by dereferencing all objects and fixing the offset if necessary.
| |
| checkXRefStreamOffset | back to summary |
|---|---|
| private boolean checkXRefStreamOffset(long startXRefOffset) throws IOException Check if the cross reference stream can be found at the current offset.
| |
| createRandomAccessReadView | back to summary |
|---|---|
| public RandomAccessReadView createRandomAccessReadView(long startPosition, long streamLength) throws IOException Implements org. Doc from org. Creates a random access read view starting at the given position with the given length.
| |
| dereferenceCOSObject | back to summary |
|---|---|
| public COSBase dereferenceCOSObject(COSObject obj) throws IOException Implements org. Doc from org. Dereference the COSBase object which is referenced by the given COSObject.
| |
| findObjectKey | back to summary |
|---|---|
| private COSObjectKey findObjectKey(COSObjectKey objectKey, long offset, Map<COSObjectKey, Long> xrefOffset) throws IOException Check if the given object can be found at the given offset. Returns the provided object key if everything is ok. If the generation number differs it will be fixed and a new object key is returned.
| |
| getAccessPermission | back to summary |
|---|---|
| protected AccessPermission getAccessPermission() throws IOException This will get the AccessPermission. The document must be parsed before this is called.
| |
| getBruteForceParser | back to summary |
|---|---|
| private BruteForceParser getBruteForceParser() throws IOException | |
| getEncryption | back to summary |
|---|---|
| protected PDEncryption getEncryption() throws IOException This will get the encryption dictionary. The document must be parsed before this is called.
| |
| getLength | back to summary |
|---|---|
| private COSNumber getLength(final COSBase lengthBaseObj) throws IOException Returns length value referred to or defined in given object. | |
| getObjectOffset | back to summary |
|---|---|
| private Long getObjectOffset(COSObjectKey objKey, boolean requireExistingNotCompressedObj) throws IOException | |
| getStartxrefOffset | back to summary |
|---|---|
| private long getStartxrefOffset() throws IOException Looks for and parses startxref. We first look for last '%%EOF' marker (within last
| |
| init | back to summary |
|---|---|
| private void init(RandomAccessStreamCache. | |
| isLenient | back to summary |
|---|---|
| public boolean isLenient() Return true if parser is lenient. Meaning auto healing capacity of the parser are used.
| |
| isString | back to summary |
|---|---|
| private boolean isString(byte[] string) throws IOException Checks if the given string can be found at the current offset.
| |
| isString | back to summary |
|---|---|
| protected boolean isString(char[] string) throws IOException Checks if the given string can be found at the current offset.
| |
| lastIndexOf | back to summary |
|---|---|
| protected int lastIndexOf(final char[] pattern, final byte[] buf, final int endOff) Searches last appearance of pattern within buffer. Lookup before _lastOff and goes back until 0.
| |
| parseCOSStream | back to summary |
|---|---|
| protected COSStream parseCOSStream(COSDictionary dic) throws IOException This will read a COSStream from the input stream using length attribute within dictionary. If length attribute is a indirect reference it is first resolved to get the stream length. This means we copy stream data without testing for 'endstream' or 'endobj' and thus it is no problem if these keywords occur within stream. We require 'endstream' to be found after stream data is read.
| |
| parseFDFHeader | back to summary |
|---|---|
| protected boolean parseFDFHeader() throws IOException Parse the header of a fdf.
| |
| parseFileObject | back to summary |
|---|---|
| private COSBase parseFileObject(Long objOffset, final COSObjectKey objKey) throws IOException | |
| parseHeader | back to summary |
|---|---|
| private boolean parseHeader(String headerMarker, String defaultVersion) throws IOException | |
| parseObjectDynamically | back to summary |
|---|---|
| protected synchronized COSBase parseObjectDynamically(COSObjectKey objKey, boolean requireExistingNotCompressedObj) throws IOException Parse the object for the given object key.
| |
| parseObjectStreamObject | back to summary |
|---|---|
| protected COSBase parseObjectStreamObject(long objstmObjNr, COSObjectKey key) throws IOException Parse the object with the given key from the object stream with the given number.
| |
| parsePDFHeader | back to summary |
|---|---|
| protected boolean parsePDFHeader() throws IOException Parse the header of a pdf.
| |
| parseStartXref | back to summary |
|---|---|
| private long parseStartXref() throws IOException This will parse the startxref section from the stream. The startxref value is ignored.
| |
| parseTrailer | back to summary |
|---|---|
| private boolean parseTrailer() throws IOException This will parse the trailer from the stream and add it to the state.
| |
| parseXref | back to summary |
|---|---|
| private COSDictionary parseXref(long startXRefOffset) throws IOException Parses cross reference tables.
| |
| parseXrefObjStream | back to summary |
|---|---|
| private long parseXrefObjStream(long objByteOffset, boolean isStandalone) throws IOException Parses an xref object stream starting with indirect object id.
| |
| parseXrefTable | back to summary |
|---|---|
| protected boolean parseXrefTable(long startByteOffset) throws IOException This will parse the xref table from the stream and add it to the state The XrefTable contents are ignored.
| |
| prepareDecryption | back to summary |
|---|---|
| protected void prepareDecryption() throws IOException Prepare for decryption.
| |
| readUntilEndStream | back to summary |
|---|---|
| private long readUntilEndStream(final EndstreamFilterStream out) throws IOException This method will read through the current stream object until we find the keyword "endstream" meaning we're at the end of this object. Some pdf files, however, forget to write some endstream tags and just close off objects with an "endobj" tag so we have to handle this case as well. This method is optimized using buffered IO and reduced number of byte compare operations.
| |
| resetTrailerResolver | back to summary |
|---|---|
| protected boolean resetTrailerResolver() Indicates whether the xref trailer resolver should be reset or not. Should be overwritten if the xref trailer resolver is needed after the initial parsing.
| |
| retrieveTrailer | back to summary |
|---|---|
| protected COSDictionary retrieveTrailer() throws IOException Read the trailer information and provide a COSDictionary containing the trailer information.
| |
| setEOFLookupRange | back to summary |
|---|---|
| public void setEOFLookupRange(int byteCount) Sets how many trailing bytes of PDF file are searched for EOF marker and 'startxref' marker. If not set we use
default value We check that new value is at least 16. However for practical use cases this value should not be lower than 1000; even 2000 was found to not be enough in some cases where some trailing garbage like HTML snippets followed the EOF marker.
In case system property
| |
| setLenient | back to summary |
|---|---|
| protected void setLenient(boolean lenient) Change the parser leniency flag. This method can only be called before the parsing of the file.
| |
| validateStreamLength | back to summary |
|---|---|
| private boolean validateStreamLength(long streamLength) throws IOException | |
| validateXrefOffsets | back to summary |
|---|---|
| private boolean validateXrefOffsets(Map<COSObjectKey, Long> xrefOffset) throws IOException | |