Code with Finding: |
class PdfReader {
protected void readPdf() throws IOException {
try {
fileLength = tokens.getFile().length();
pdfVersion = tokens.checkPdfHeader();
try {
readXref();
}
catch (Exception e) {
try {
rebuilt = true;
rebuildXref();
lastXref = -1;
}
catch (Exception ne) {
throw new InvalidPdfException(MessageLocalization.getComposedMessage("rebuild.failed.1.original.message.2", ne.getMessage(), e.getMessage()));
}
}
try {
readDocObj();
}
catch (Exception e) {
if (e instanceof BadPasswordException)
throw new BadPasswordException(e.getMessage());
if (rebuilt || encryptionError)
throw new InvalidPdfException(e.getMessage());
rebuilt = true;
encrypted = false;
try{
rebuildXref();
lastXref = -1;
readDocObj();
} catch (Exception ne){
throw new InvalidPdfException(MessageLocalization.getComposedMessage("rebuild.failed.1.original.message.2", ne.getMessage(), e.getMessage()));
}
}
strings.clear();
readPages();
eliminateSharedStreams();
removeUnusedObjects();
}
finally {
try {
tokens.close();
}
catch (Exception e) {
// empty on purpose
}
}
}
}
class PdfReader {
protected void rebuildXref() throws IOException {
hybridXref = false;
newXrefType = false;
tokens.seek(0);
long xr[][] = new long[1024][];
long top = 0;
trailer = null;
byte line[] = new byte[64];
for (;;) {
long pos = tokens.getFilePointer();
if (!tokens.readLineSegment(line))
break;
if (line[0] == 't') {
if (!PdfEncodings.convertToString(line, null).startsWith("trailer"))
continue;
tokens.seek(pos);
tokens.nextToken();
pos = tokens.getFilePointer();
try {
PdfDictionary dic = (PdfDictionary)readPRObject();
if (dic.get(PdfName.ROOT) != null)
trailer = dic;
else
tokens.seek(pos);
}
catch (Exception e) {
tokens.seek(pos);
}
}
else if (line[0] >= '0' && line[0] <= '9') {
long obj[] = PRTokeniser.checkObjectStart(line);
if (obj == null)
continue;
long num = obj[0];
long gen = obj[1];
if (num >= xr.length) {
long newLength = num * 2;
long xr2[][] = new long[(int)newLength][];
System.arraycopy(xr, 0, xr2, 0, (int)top);
xr = xr2;
}
if (num >= top)
top = num + 1;
if (xr[(int)num] == null || gen >= xr[(int)num][1]) {
obj[0] = pos;
xr[(int)num] = obj;
}
}
}
if (trailer == null)
throw new InvalidPdfException(MessageLocalization.getComposedMessage("trailer.not.found"));
xref = new long[(int)(top * 2)];
for (int k = 0; k < top; ++k) {
long obj[] = xr[k];
if (obj != null)
xref[k * 2] = obj[0];
}
}
}
|