Fixed infinite loop in content stream processor

This commit is contained in:
Jakub Melka 2020-09-19 15:00:51 +02:00
parent 1ffb2f7d29
commit e417e06c6f
1 changed files with 12 additions and 0 deletions

View File

@ -456,9 +456,14 @@ void PDFPageContentProcessor::processContent(const QByteArray& content)
while (!parser.isAtEnd())
{
bool tokenFetched = false;
PDFInteger oldParserPosition = parser.pos();
try
{
PDFLexicalAnalyzer::Token token = parser.fetch();
tokenFetched = true;
switch (token.type)
{
case PDFLexicalAnalyzer::TokenType::Command:
@ -603,6 +608,13 @@ void PDFPageContentProcessor::processContent(const QByteArray& content)
}
catch (PDFException exception)
{
// If we get exception when parsing, and parser position is not advanced,
// then we must advance it manually, otherwise we get infinite loop.
if (!tokenFetched && oldParserPosition == parser.pos() && !parser.isAtEnd())
{
parser.seek(parser.pos() + 1);
}
m_operands.clear();
m_errorList.append(PDFRenderError(RenderErrorType::Error, exception.getMessage()));
}