Reputation: 71
I recently received a PDF which causes the application to hang when loading in both iText Java and iTextSharp.
Upvotes: 2
Views: 443
Reputation: 71
The problem was that the PDF had incremental updates and the additional trailer had a Prev entry pointing to its own cross-reference table. This causes an infinite loop in PdfReader.ReadXref()
.
My proposed solution is as follows.
while (true) {
PdfNumber prev = (PdfNumber)trailer2.Get(PdfName.PREV);
if (prev == null)
break;
// Add check to prevent infinite loop
if (prev.LongValue == startxref)
throw new InvalidPdfException("trailer Prev points to its own cross-reference section.");
// end added check
tokens.Seek(prev.LongValue);
trailer2 = ReadXrefSection();
}
Apologies to StackOverflow for this not actually being a question, but I can't afford the time to satisfy the iText requirements for a pull request for two lines of code.
Upvotes: 4