summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-10-30 20:34:22 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-10-30 20:34:22 +0000
commitc94eb952f636f4553b2b18cda445c775982b657c (patch)
treebed9b59d0fc7e7e22e2837c6bc5387b503e306b9
parenta3254627c664e2b88f48f1d6dd856503ab8742b3 (diff)
downloadpdfium-c94eb952f636f4553b2b18cda445c775982b657c.tar.xz
Use CPDF_PageDataAvail to check page availability.
Change-Id: Iad67de5881481684fee605f48f9349a3be21f70b Reviewed-on: https://pdfium-review.googlesource.com/15591 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp92
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h4
2 files changed, 36 insertions, 60 deletions
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<int32_t>(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<CPDF_PageObjectAvail>(
+ 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<int32_t>(dwPage);
- m_pPageDict = m_pDocument->GetPage(safePage.ValueOrDie());
- if (!m_pPageDict) {
- ResetFirstCheck(dwPage);
- // This is XFA page.
- return DataAvailable;
- }
-
- std::vector<CPDF_Object*> 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<CPDF_Object*> 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<CPDF_PageObjectAvail>(
+ 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<CPDF_PageObjectAvail> m_pFormAvail;
std::vector<std::unique_ptr<CPDF_Object>> m_PagesArray;
uint32_t m_dwEncryptObjNum;
@@ -226,6 +223,7 @@ class CPDF_DataAvail final {
std::set<uint32_t> m_SeenPrevPositions;
std::unique_ptr<CPDF_HintTables> m_pHintTables;
bool m_bSupportHintTable;
+ std::map<uint32_t, std::unique_ptr<CPDF_PageObjectAvail>> m_PagesObjAvail;
std::map<const CPDF_Object*, std::unique_ptr<CPDF_PageObjectAvail>>
m_PagesResourcesAvail;
};