iTextPdf 和 iTextSharp - 格式错误的 PDF 导致挂起
iTextPdf and iTextSharp - Malformed PDF causes hang
我最近收到一个 PDF,它导致应用程序在加载 iText Java 和 iTextSharp 时挂起。
问题是 PDF 有增量更新,附加预告片有一个 Prev 条目指向它自己的交叉引用 table。这会导致 PdfReader.ReadXref()
.
中的无限循环
我建议的解决方案如下。
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();
}
向 Whosebug 道歉,因为这实际上不是一个问题,但我没有时间来满足两行代码的拉取请求的 iText 要求。
我最近收到一个 PDF,它导致应用程序在加载 iText Java 和 iTextSharp 时挂起。
问题是 PDF 有增量更新,附加预告片有一个 Prev 条目指向它自己的交叉引用 table。这会导致 PdfReader.ReadXref()
.
我建议的解决方案如下。
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();
}
向 Whosebug 道歉,因为这实际上不是一个问题,但我没有时间来满足两行代码的拉取请求的 iText 要求。