From 87a8d4c605ec1c43ccd092b57e1aadf1dfe595de Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 5 Oct 2016 12:41:21 -0700 Subject: Rework a redundant check when calling ConvertToIndirectObjectAt() This avoids a re-assignment that can otherwise cause a later fault. BUG=pdfium:607 Review-Url: https://codereview.chromium.org/2393953002 --- core/fpdfapi/parser/cpdf_array.cpp | 2 +- core/fpdfdoc/cpdf_annotlist.cpp | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp index e9a92eeae6..9a2dba0161 100644 --- a/core/fpdfapi/parser/cpdf_array.cpp +++ b/core/fpdfapi/parser/cpdf_array.cpp @@ -152,7 +152,7 @@ void CPDF_Array::ConvertToIndirectObjectAt(size_t i, return; CPDF_Object* pObj = m_Objects[i]; - if (!pObj || pObj->GetObjNum() != 0) + if (!pObj || pObj->IsReference()) return; uint32_t dwObjNum = pHolder->AddIndirectObject(pObj); diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index 940cf324f4..f73ace9791 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp @@ -68,20 +68,12 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) pAcroForm && pAcroForm->GetBooleanFor("NeedAppearances"); for (size_t i = 0; i < pAnnots->GetCount(); ++i) { CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); - if (!pDict) + if (!pDict || pDict->GetStringFor("Subtype") == "Popup") { + // Skip creating Popup annotations in the PDF document since PDFium + // provides its own Popup annotations. continue; - - uint32_t dwObjNum = pDict->GetObjNum(); - if (dwObjNum == 0) { - pAnnots->ConvertToIndirectObjectAt(i, m_pDocument); - pDict = pAnnots->GetDictAt(i); } - - // Skip creating Popup annotation in the PDF document since PDFium provides - // its own Popup annotations. - if (pDict->GetStringFor("Subtype") == "Popup") - continue; - + pAnnots->ConvertToIndirectObjectAt(i, m_pDocument); m_AnnotList.push_back( std::unique_ptr(new CPDF_Annot(pDict, m_pDocument, false))); if (bRegenerateAP && pDict->GetStringFor("Subtype") == "Widget" && -- cgit v1.2.3