From c94eb952f636f4553b2b18cda445c775982b657c Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Mon, 30 Oct 2017 20:34:22 +0000 Subject: Use CPDF_PageDataAvail to check page availability. Change-Id: Iad67de5881481684fee605f48f9349a3be21f70b Reviewed-on: https://pdfium-review.googlesource.com/15591 Commit-Queue: Art Snake Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_data_avail.cpp | 92 +++++++++++++-------------------- core/fpdfapi/parser/cpdf_data_avail.h | 4 +- 2 files changed, 36 insertions(+), 60 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 0cdaed22ed..549ed75425 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -101,11 +101,8 @@ CPDF_DataAvail::CPDF_DataAvail( m_bPagesLoad = false; m_bPagesTreeLoad = false; m_bMainXRefLoadedOK = false; - m_bAnnotsLoad = false; - m_bPageLoadedOK = false; m_pTrailer = nullptr; m_pCurrentParser = nullptr; - m_pPageDict = nullptr; m_docStatus = PDF_DATAAVAIL_HEADER; m_bTotalLoadPageTree = false; m_bCurPageDictLoadOK = false; @@ -1173,11 +1170,6 @@ bool CPDF_DataAvail::CheckPageAnnots(uint32_t dwPage) { CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( uint32_t dwPage) { - if (!m_bAnnotsLoad) { - if (!CheckPageAnnots(dwPage)) - return DataNotAvailable; - m_bAnnotsLoad = true; - } if (!ValidatePage(dwPage)) return DataError; return DataAvailable; @@ -1189,12 +1181,17 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( if (!m_pDocument) return DataError; + const FX_SAFE_INT32 safePage = pdfium::base::checked_cast(dwPage); + if (!safePage.IsValid()) + return DataError; + + if (safePage.ValueOrDie() >= m_pDocument->GetPageCount()) { + // This is XFA page. + return DataAvailable; + } + if (IsFirstCheck(dwPage)) { m_bCurPageDictLoadOK = false; - m_bPageLoadedOK = false; - m_bAnnotsLoad = false; - m_objs_array.clear(); - m_ObjectSet.clear(); } if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) @@ -1204,10 +1201,18 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( if (m_pLinearized) { if (dwPage == m_pLinearized->GetFirstPageNo()) { - DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage); - if (nRet == DataAvailable) - m_pagesLoadState.insert(dwPage); - return nRet; + CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); + if (!pPageDict) + return DataError; + + auto page_num_obj = std::make_pair( + dwPage, pdfium::MakeUnique( + GetValidator().Get(), m_pDocument, pPageDict)); + + CPDF_PageObjectAvail* page_obj_avail = + m_PagesObjAvail.insert(std::move(page_num_obj)).first->second.get(); + // TODO(art-snake): Check resources. + return page_obj_avail->CheckAvail(); } DocAvailStatus nResult = CheckLinearizedData(); @@ -1247,61 +1252,34 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( if (CheckAcroForm() == DocFormStatus::FormNotAvailable) return DataNotAvailable; - if (!m_bPageLoadedOK) { - if (m_objs_array.empty()) { - m_ObjectSet.clear(); - - FX_SAFE_INT32 safePage = pdfium::base::checked_cast(dwPage); - m_pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); - if (!m_pPageDict) { - ResetFirstCheck(dwPage); - // This is XFA page. - return DataAvailable; - } - - std::vector obj_array; - obj_array.push_back(m_pPageDict); - if (!AreObjectsAvailable(obj_array, true, m_objs_array)) - return DataNotAvailable; - - m_objs_array.clear(); - } else { - std::vector new_objs_array; - if (!AreObjectsAvailable(m_objs_array, false, new_objs_array)) { - m_objs_array = new_objs_array; - return DataNotAvailable; - } - } - m_objs_array.clear(); - m_bPageLoadedOK = true; - } + CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); + if (!pPageDict) + return DataError; - if (!m_bAnnotsLoad) { - if (!CheckPageAnnots(dwPage)) - return DataNotAvailable; - m_bAnnotsLoad = true; + { + auto page_num_obj = std::make_pair( + dwPage, pdfium::MakeUnique( + GetValidator().Get(), m_pDocument, pPageDict)); + CPDF_PageObjectAvail* page_obj_avail = + m_PagesObjAvail.insert(std::move(page_num_obj)).first->second.get(); + const DocAvailStatus status = page_obj_avail->CheckAvail(); + if (status != DocAvailStatus::DataAvailable) + return status; } - const DocAvailStatus resources_status = CheckResources(m_pPageDict); + const DocAvailStatus resources_status = CheckResources(pPageDict); if (resources_status != DocAvailStatus::DataAvailable) return resources_status; - m_bPageLoadedOK = false; - m_bAnnotsLoad = false; m_bCurPageDictLoadOK = false; - ResetFirstCheck(dwPage); m_pagesLoadState.insert(dwPage); - if (!ValidatePage(dwPage)) - return DataError; return DataAvailable; } CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckResources( const CPDF_Dictionary* page) { - if (!page) - return DocAvailStatus::DataAvailable; - + ASSERT(page); const CPDF_ReadValidator::Session read_session(GetValidator().Get()); const CPDF_Object* resources = GetResourceObject(page); if (GetValidator()->has_read_problems()) diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index f7c502ff77..a887d94901 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -211,9 +211,6 @@ class CPDF_DataAvail final { bool m_bPagesLoad; CPDF_Parser* m_pCurrentParser; FX_FILESIZE m_dwCurrentXRefSteam; - bool m_bAnnotsLoad; - CPDF_Dictionary* m_pPageDict; - bool m_bPageLoadedOK; std::unique_ptr m_pFormAvail; std::vector> m_PagesArray; uint32_t m_dwEncryptObjNum; @@ -226,6 +223,7 @@ class CPDF_DataAvail final { std::set m_SeenPrevPositions; std::unique_ptr m_pHintTables; bool m_bSupportHintTable; + std::map> m_PagesObjAvail; std::map> m_PagesResourcesAvail; }; -- cgit v1.2.3