Top Description Fields Constructors Methods
org.apache.pdfbox.pdfparser

public Class BruteForceParser

extends COSParser
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .HashMap, .List, .Map, .Map.Entry, java.util.stream.Collectors, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSDocument, .COSName, .COSObject, .COSObjectKey, .COSStream, org.apache.pdfbox.io.RandomAccessRead, org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType, org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy, .SecurityHandler

Brute force parser to be used as last resort if a malformed pdf can't be read.

Field Summary

Modifier and TypeField and Description
private final Map<COSObjectKey, Long>
bfSearchCOSObjectKeyOffsets

Contains all found objects of a brute force search.

private boolean
private static final char[]
private static final Log
private static final long
private static final char[]
private static final char[]
OBJ_STREAM

ObjStream-marker.

private static final char[]
TRAILER_MARKER

trailer-marker.

private static final char[]
private static final char[]
Inherited from org.apache.pdfbox.pdfparser.COSParser:
fileLeninitialParseDonesecurityHandlerSYSPROP_EOFLOOKUPRANGExrefTrailerResolver

Constructor Summary

AccessConstructor and Description
public
BruteForceParser(RandomAccessRead
input representing the pdf.
source
,
COSDocument
the corresponding COS document
document
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private long
bfSearchForLastEOFMarker()

Brute force search for the last EOF marker.

private void
bfSearchForObjects()

Brute force search for every object in the pdf.

private Map<Long, COSObjectKey>

Returns:

a map of all offsets for object streams
bfSearchForObjStreamOffsets
()

Search for all offsets of object streams within the given pdf

protected void
bfSearchForObjStreams(XrefTrailerResolver
the trailer resolver of the document
trailerResolver
,
SecurityHandler<? extends ProtectionPolicy>
security handler to be used to decrypt encrypted documents
securityHandler
)

Brute force search for all objects streams of a pdf.

private boolean
bfSearchForTrailer(COSDictionary
dictionary to be used as trailer dictionary
trailer
)

Brute force search for all trailer marker.

protected long

Returns:

the offset of the xref entry
bfSearchForXRef
(long
the given offset to be searched for
xrefOffset
)

Search for the offset of the given xref table/stream among those found by a brute force search.

private List<Long>
bfSearchForXRefStreams()

Brute force search for all /XRef entries (streams).

private List<Long>
bfSearchForXRefTables()

Brute force search for all xref entries (tables).

public boolean

Returns:

true if the search was triggered
bfSearchTriggered
()

Indicates wether the brute force search for objects was triggered.

private COSObject
compareCOSObjects(COSObject newObject, Long newOffset, COSObject currentObject)

private long

Returns:

the start position of the found string
findString
(char[]
the string to be searched
string
)

Search for the given string.

protected Map<COSObjectKey, Long>

Returns:

map containing all found objects of a brute force search
getBFCOSObjectOffsets
()

Returns all found objects of a brute force search.

private boolean

Returns:

true if the given dictionary is a root dictionary
isCatalog
(COSDictionary dictionary)

Tell if the dictionary is a PDF or FDF catalog.

private boolean

Returns:

true if the given dictionary is an info dictionary
isInfo
(COSDictionary
the dictionary to be checked
dictionary
)

Tell if the dictionary is an info dictionary.

protected COSDictionary

Returns:

the rebuild trailer dictionary
rebuildTrailer
(XrefTrailerResolver
the trailer resolver of the document
trailerResolver
,
SecurityHandler<? extends ProtectionPolicy>
security handler to be used to decrypt encrypted documents
securityHandler
)

Rebuild the trailer dictionary if startxref can't be found.

private boolean

Returns:

true if the root was found, false if not.
searchForTrailerItems
(COSDictionary
dictionary to be used as trailer dictionary
trailer
)

Search for the different parts of the trailer dictionary.

private long
searchNearestValue(List<Long> values, long offset)

Inherited from org.apache.pdfbox.pdfparser.COSParser:
checkPagescreateRandomAccessReadViewdereferenceCOSObjectgetAccessPermissiongetEncryptionisLenientisStringlastIndexOfparseCOSStreamparseFDFHeaderparseObjectDynamicallyparseObjectStreamObjectparsePDFHeaderparseXrefTableprepareDecryptionresetTrailerResolverretrieveTrailersetEOFLookupRangesetLenient

Field Detail

bfSearchCOSObjectKeyOffsetsback to summary
private final Map<COSObjectKey, Long> bfSearchCOSObjectKeyOffsets

Contains all found objects of a brute force search.

bfSearchTriggeredback to summary
private boolean bfSearchTriggered
EOF_MARKERback to summary
private static final char[] EOF_MARKER

Hides org.apache.pdfbox.pdfparser.COSParser.EOF_MARKER.

EOF-marker.

LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.pdfparser.COSParser.LOG.

MINIMUM_SEARCH_OFFSETback to summary
private static final long MINIMUM_SEARCH_OFFSET

Hides org.apache.pdfbox.pdfparser.COSParser.MINIMUM_SEARCH_OFFSET.

OBJ_MARKERback to summary
private static final char[] OBJ_MARKER

Hides org.apache.pdfbox.pdfparser.COSParser.OBJ_MARKER.

obj-marker.

OBJ_STREAMback to summary
private static final char[] OBJ_STREAM

ObjStream-marker.

TRAILER_MARKERback to summary
private static final char[] TRAILER_MARKER

trailer-marker.

XREF_STREAMback to summary
private static final char[] XREF_STREAM
XREF_TABLEback to summary
private static final char[] XREF_TABLE

Hides org.apache.pdfbox.pdfparser.COSParser.XREF_TABLE.

Constructor Detail

BruteForceParserback to summary
public BruteForceParser(RandomAccessRead source, COSDocument document) throws IOException

Constructor. Triggers a brute force search for all objects of the document.

Parameters
source:RandomAccessRead

input representing the pdf.

document:COSDocument

the corresponding COS document

Exceptions
IOException:
if the source data could not be read

Method Detail

bfSearchForLastEOFMarkerback to summary
private long bfSearchForLastEOFMarker() throws IOException

Brute force search for the last EOF marker.

Exceptions
IOException:
if something went wrong
bfSearchForObjectsback to summary
private void bfSearchForObjects() throws IOException

Brute force search for every object in the pdf.

Exceptions
IOException:
if something went wrong
bfSearchForObjStreamOffsetsback to summary
private Map<Long, COSObjectKey> bfSearchForObjStreamOffsets() throws IOException

Search for all offsets of object streams within the given pdf

Returns:Map<Long, COSObjectKey>

a map of all offsets for object streams

Exceptions
IOException:
if something went wrong
bfSearchForObjStreamsback to summary
protected void bfSearchForObjStreams(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) throws IOException

Brute force search for all objects streams of a pdf.

Parameters
trailerResolver:XrefTrailerResolver

the trailer resolver of the document

securityHandler:SecurityHandler<? extends ProtectionPolicy>

security handler to be used to decrypt encrypted documents

Exceptions
IOException:
if something went wrong
bfSearchForTrailerback to summary
private boolean bfSearchForTrailer(COSDictionary trailer) throws IOException

Brute force search for all trailer marker.

Parameters
trailer:COSDictionary

dictionary to be used as trailer dictionary

Exceptions
IOException:
if something went wrong
bfSearchForXRefback to summary
protected long bfSearchForXRef(long xrefOffset) throws IOException

Search for the offset of the given xref table/stream among those found by a brute force search.

Parameters
xrefOffset:long

the given offset to be searched for

Returns:long

the offset of the xref entry

Exceptions
IOException:
if something went wrong
bfSearchForXRefStreamsback to summary
private List<Long> bfSearchForXRefStreams() throws IOException

Brute force search for all /XRef entries (streams).

Exceptions
IOException:
if something went wrong
bfSearchForXRefTablesback to summary
private List<Long> bfSearchForXRefTables() throws IOException

Brute force search for all xref entries (tables).

Exceptions
IOException:
if something went wrong
bfSearchTriggeredback to summary
public boolean bfSearchTriggered()

Indicates wether the brute force search for objects was triggered.

Returns:boolean

true if the search was triggered

compareCOSObjectsback to summary
private COSObject compareCOSObjects(COSObject newObject, Long newOffset, COSObject currentObject)
findStringback to summary
private long findString(char[] string) throws IOException

Search for the given string. The search starts at the current position and returns the start position if the string was found. -1 is returned if there isn't any further occurrence of the given string. After returning the current position is either the end of the string or the end of the input.

Parameters
string:char[]

the string to be searched

Returns:long

the start position of the found string

Exceptions
IOException:
if something went wrong
getBFCOSObjectOffsetsback to summary
protected Map<COSObjectKey, Long> getBFCOSObjectOffsets() throws IOException

Returns all found objects of a brute force search.

Returns:Map<COSObjectKey, Long>

map containing all found objects of a brute force search

Exceptions
IOException:
if something went wrong
isCatalogback to summary
private boolean isCatalog(COSDictionary dictionary)

Tell if the dictionary is a PDF or FDF catalog.

Returns:boolean

true if the given dictionary is a root dictionary

isInfoback to summary
private boolean isInfo(COSDictionary dictionary)

Tell if the dictionary is an info dictionary.

Parameters
dictionary:COSDictionary

the dictionary to be checked

Returns:boolean

true if the given dictionary is an info dictionary

rebuildTrailerback to summary
protected COSDictionary rebuildTrailer(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) throws IOException

Rebuild the trailer dictionary if startxref can't be found.

Parameters
trailerResolver:XrefTrailerResolver

the trailer resolver of the document

securityHandler:SecurityHandler<? extends ProtectionPolicy>

security handler to be used to decrypt encrypted documents

Returns:COSDictionary

the rebuild trailer dictionary

Exceptions
IOException:
if something went wrong
searchForTrailerItemsback to summary
private boolean searchForTrailerItems(COSDictionary trailer) throws IOException

Search for the different parts of the trailer dictionary.

Parameters
trailer:COSDictionary

dictionary to be used as trailer dictionary

Returns:boolean

true if the root was found, false if not.

Exceptions
IOException:
if something went wrong
searchNearestValueback to summary
private long searchNearestValue(List<Long> values, long offset)