diff options
author | art-snake <art-snake@yandex-team.ru> | 2016-11-09 15:20:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-09 15:20:59 -0800 |
commit | c0a47773d6dadeb8a39a6ced4ebbb1795e2e411f (patch) | |
tree | 79efdd2dd00f19294a44a3b4fe5e851221ea5dc0 /core/fpdfapi/parser/cpdf_document.cpp | |
parent | 335cf093231c984a23cb9ea113148ea1f19621ba (diff) | |
download | pdfium-c0a47773d6dadeb8a39a6ced4ebbb1795e2e411f.tar.xz |
Fix receiving page, if it have not obj num.
In some PDF's the page may not have the obj num.
For example: testing\corpus\fx\other\jetman_std.pdf in pdfium repository.
And CPDF_Document::GetPage failed on second call for this page.
Restart the traversing of pages, to fix this
Also added test.
Review-Url: https://codereview.chromium.org/2491583002
Diffstat (limited to 'core/fpdfapi/parser/cpdf_document.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 1c73ce1015..6788394118 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -492,9 +492,18 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { if (!pPages) return nullptr; + if (iPage - m_iNextPageToTraverse + 1 <= 0) { + // This can happen when the page does not have an object number. On repeated + // calls to this function for the same page index, this condition causes + // TraversePDFPages() to incorrectly return nullptr. + // Example "testing/corpus/fx/other/jetman_std.pdf" + // We should restart traversing in this case. + // TODO(art-snake): optimize this. + ResetTraversal(); + } + int nPagesToGo = iPage - m_iNextPageToTraverse + 1; if (m_pTreeTraversal.empty()) m_pTreeTraversal.push_back(std::make_pair(pPages, 0)); - int nPagesToGo = iPage - m_iNextPageToTraverse + 1; CPDF_Dictionary* pPage = TraversePDFPages(iPage, &nPagesToGo, 0); m_iNextPageToTraverse = iPage + 1; return pPage; |