summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp57
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h7
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<CPDF_Object*> 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<CPDF_Object*> 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<CPDF_PageObjectAvail>(
+ GetValidator().Get(), m_pDocument, resources)))
+ .first->second.get();
+ return resource_avail->CheckAvail();
}
RetainPtr<IFX_SeekableReadStream> 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 <map>
#include <memory>
#include <set>
#include <vector>
@@ -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<CPDF_PageObjectAvail> m_pFormAvail;
std::vector<std::unique_ptr<CPDF_Object>> m_PagesArray;
@@ -227,6 +226,8 @@ class CPDF_DataAvail final {
std::set<uint32_t> m_SeenPrevPositions;
std::unique_ptr<CPDF_HintTables> m_pHintTables;
bool m_bSupportHintTable;
+ std::map<const CPDF_Object*, std::unique_ptr<CPDF_PageObjectAvail>>
+ m_PagesResourcesAvail;
};
#endif // CORE_FPDFAPI_PARSER_CPDF_DATA_AVAIL_H_