From a759dcedcb9b95492b4d2a388d98019f994f59bd Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Mon, 30 Oct 2017 20:05:32 +0000 Subject: Use CPDF_PageDataAvail to check page resources availability. Change-Id: Idbb30122c113ffce421c8d471551f619f4ab7576 Reviewed-on: https://pdfium-review.googlesource.com/15590 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_data_avail.cpp | 57 +++++++++++++++------------------ core/fpdfapi/parser/cpdf_data_avail.h | 7 ++-- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 6a31cbf227..0cdaed22ed 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -33,13 +33,13 @@ namespace { // static -CPDF_Object* GetResourceObject(CPDF_Dictionary* pDict) { +const CPDF_Object* GetResourceObject(const CPDF_Dictionary* pDict) { constexpr size_t kMaxHierarchyDepth = 64; size_t depth = 0; - CPDF_Dictionary* dictionary_to_check = pDict; + const CPDF_Dictionary* dictionary_to_check = pDict; while (dictionary_to_check) { - CPDF_Object* result = dictionary_to_check->GetObjectFor("Resources"); + const CPDF_Object* result = dictionary_to_check->GetObjectFor("Resources"); if (result) return result; const CPDF_Object* parent = dictionary_to_check->GetObjectFor("Parent"); @@ -103,11 +103,9 @@ CPDF_DataAvail::CPDF_DataAvail( m_bMainXRefLoadedOK = false; m_bAnnotsLoad = false; m_bPageLoadedOK = false; - m_bNeedDownLoadResource = false; m_pTrailer = nullptr; m_pCurrentParser = nullptr; m_pPageDict = nullptr; - m_pPageResource = nullptr; m_docStatus = PDF_DATAAVAIL_HEADER; m_bTotalLoadPageTree = false; m_bCurPageDictLoadOK = false; @@ -1195,7 +1193,6 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( m_bCurPageDictLoadOK = false; m_bPageLoadedOK = false; m_bAnnotsLoad = false; - m_bNeedDownLoadResource = false; m_objs_array.clear(); m_ObjectSet.clear(); } @@ -1285,16 +1282,9 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( m_bAnnotsLoad = true; } - if (m_pPageDict && !m_bNeedDownLoadResource) { - m_pPageResource = GetResourceObject(m_pPageDict); - m_bNeedDownLoadResource = !!m_pPageResource; - } - - if (m_bNeedDownLoadResource) { - if (!CheckResources()) - return DataNotAvailable; - m_bNeedDownLoadResource = false; - } + const DocAvailStatus resources_status = CheckResources(m_pPageDict); + if (resources_status != DocAvailStatus::DataAvailable) + return resources_status; m_bPageLoadedOK = false; m_bAnnotsLoad = false; @@ -1307,23 +1297,26 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( return DataAvailable; } -bool CPDF_DataAvail::CheckResources() { - if (m_objs_array.empty()) { - std::vector obj_array; - obj_array.push_back(m_pPageResource); - if (!AreObjectsAvailable(obj_array, true, m_objs_array)) - return false; +CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckResources( + const CPDF_Dictionary* page) { + if (!page) + return DocAvailStatus::DataAvailable; - m_objs_array.clear(); - return true; - } - std::vector new_objs_array; - if (!AreObjectsAvailable(m_objs_array, false, new_objs_array)) { - m_objs_array = new_objs_array; - return false; - } - m_objs_array.clear(); - return true; + const CPDF_ReadValidator::Session read_session(GetValidator().Get()); + const CPDF_Object* resources = GetResourceObject(page); + if (GetValidator()->has_read_problems()) + return DocAvailStatus::DataNotAvailable; + + if (!resources) + return DocAvailStatus::DataAvailable; + + CPDF_PageObjectAvail* resource_avail = + m_PagesResourcesAvail + .insert(std::make_pair( + resources, pdfium::MakeUnique( + GetValidator().Get(), m_pDocument, resources))) + .first->second.get(); + return resource_avail->CheckAvail(); } RetainPtr CPDF_DataAvail::GetFileRead() const { diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 62a0e29773..f7c502ff77 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFAPI_PARSER_CPDF_DATA_AVAIL_H_ #define CORE_FPDFAPI_PARSER_CPDF_DATA_AVAIL_H_ +#include #include #include #include @@ -138,7 +139,7 @@ class CPDF_DataAvail final { bool CheckInfo(); bool CheckPages(); bool CheckPage(); - bool CheckResources(); + DocAvailStatus CheckResources(const CPDF_Dictionary* page); DocFormStatus CheckAcroForm(); bool CheckPageStatus(); @@ -212,8 +213,6 @@ class CPDF_DataAvail final { FX_FILESIZE m_dwCurrentXRefSteam; bool m_bAnnotsLoad; CPDF_Dictionary* m_pPageDict; - CPDF_Object* m_pPageResource; - bool m_bNeedDownLoadResource; bool m_bPageLoadedOK; std::unique_ptr m_pFormAvail; std::vector> m_PagesArray; @@ -227,6 +226,8 @@ class CPDF_DataAvail final { std::set m_SeenPrevPositions; std::unique_ptr m_pHintTables; bool m_bSupportHintTable; + std::map> + m_PagesResourcesAvail; }; #endif // CORE_FPDFAPI_PARSER_CPDF_DATA_AVAIL_H_ -- cgit v1.2.3