Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Side by Side Diff: core/fpdfapi/parser/cpdf_document.cpp

Issue 2491583002: Fix receiving page, if it have not obj num. (Closed)
Patch Set: Fix receiving page, if it have not obj num. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/parser/cpdf_document.h" 7 #include "core/fpdfapi/parser/cpdf_document.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (objnum) { 485 if (objnum) {
486 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum))) 486 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum)))
487 return pDict; 487 return pDict;
488 return nullptr; 488 return nullptr;
489 } 489 }
490 490
491 CPDF_Dictionary* pPages = GetPagesDict(); 491 CPDF_Dictionary* pPages = GetPagesDict();
492 if (!pPages) 492 if (!pPages)
493 return nullptr; 493 return nullptr;
494 494
495 int nPagesToGo = iPage - m_iNextPageToTraverse + 1;
496 if (nPagesToGo <= 0) {
497 // This can happen when the page does not have an object number. On repeated
498 // calls to this function for the same page index, this condition causes
499 // TraversePDFPages() to incorrectly return nullptr.
500 // Example "testing/corpus/fx/other/jetman_std.pdf"
501 // We should restart traversing in this case.
502 // TODO(art-snake): optimize this.
503 m_pTreeTraversal.clear();
504 m_iNextPageToTraverse = 0;
505 nPagesToGo = iPage + 1;
506 }
495 if (m_pTreeTraversal.empty()) 507 if (m_pTreeTraversal.empty())
496 m_pTreeTraversal.push_back(std::make_pair(pPages, 0)); 508 m_pTreeTraversal.push_back(std::make_pair(pPages, 0));
497 int nPagesToGo = iPage - m_iNextPageToTraverse + 1;
498 CPDF_Dictionary* pPage = TraversePDFPages(iPage, &nPagesToGo, 0); 509 CPDF_Dictionary* pPage = TraversePDFPages(iPage, &nPagesToGo, 0);
499 m_iNextPageToTraverse = iPage + 1; 510 m_iNextPageToTraverse = iPage + 1;
500 return pPage; 511 return pPage;
501 } 512 }
502 513
503 void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { 514 void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) {
504 m_PageList.SetAt(iPage, objNum); 515 m_PageList.SetAt(iPage, objNum);
505 } 516 }
506 517
507 int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, 518 int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 pBBox, pLogFont->lfWeight / 5); 1048 pBBox, pLogFont->lfWeight / 5);
1038 pFontDesc->SetIntegerFor("CapHeight", capheight); 1049 pFontDesc->SetIntegerFor("CapHeight", capheight);
1039 pFontDict->SetReferenceFor("FontDescriptor", this, 1050 pFontDict->SetReferenceFor("FontDescriptor", this,
1040 AddIndirectObject(pFontDesc)); 1051 AddIndirectObject(pFontDesc));
1041 hFont = SelectObject(hDC, hFont); 1052 hFont = SelectObject(hDC, hFont);
1042 DeleteObject(hFont); 1053 DeleteObject(hFont);
1043 DeleteDC(hDC); 1054 DeleteDC(hDC);
1044 return LoadFont(pBaseDict); 1055 return LoadFont(pBaseDict);
1045 } 1056 }
1046 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 1057 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/parser/cpdf_document_unittest.cpp » ('j') | core/fpdfapi/parser/cpdf_document_unittest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698