From 36b9d031fc966943d25dadc7112eddb1ab9f7c54 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Fri, 8 Sep 2023 17:07:07 +0200 Subject: [PATCH] Invalid parsing of CMAP for some fonts --- Pdf4QtLib/sources/pdffont.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Pdf4QtLib/sources/pdffont.cpp b/Pdf4QtLib/sources/pdffont.cpp index e8a3fc5..35b9dc8 100644 --- a/Pdf4QtLib/sources/pdffont.cpp +++ b/Pdf4QtLib/sources/pdffont.cpp @@ -2117,9 +2117,31 @@ PDFFontCMap PDFFontCMap::createFromData(const QByteArray& data) std::pair from = fetchCode(token1); std::pair to = fetchCode(token2); - CID cid = fetchUnicode(token3); - entries.emplace_back(from.first, to.first, qMax(from.second, to.second), cid); + if (token3.type == PDFLexicalAnalyzer::TokenType::ArrayStart) + { + unsigned int current = from.first; + + while (true) + { + PDFLexicalAnalyzer::Token arrayToken = parser.fetch(); + + // Do we have end of array? + if (arrayToken.type == PDFLexicalAnalyzer::TokenType::ArrayEnd) + { + break; + } + + CID cid = fetchUnicode(arrayToken); + entries.emplace_back(current, current, qMax(from.second, to.second), cid); + ++current; + } + } + else + { + CID cid = fetchUnicode(token3); + entries.emplace_back(from.first, to.first, qMax(from.second, to.second), cid); + } } } else if (command == "begincidrange")