From a45dc45bd2c58ff2911630f913f6ac06ccae9d33 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Mon, 30 Oct 2017 19:39:22 +0000 Subject: Use CPDF_PageDataAvail to check form availability. Change-Id: I31c0a74322a2299f2d0cd1f42669b1bf447a9958 Reviewed-on: https://pdfium-review.googlesource.com/13530 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_data_avail.cpp | 119 ++++++-------------------------- core/fpdfapi/parser/cpdf_data_avail.h | 13 +--- core/fpdfapi/parser/cpdf_object_avail.h | 3 +- 3 files changed, 27 insertions(+), 108 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index aac233e293..6a31cbf227 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -90,7 +90,6 @@ CPDF_DataAvail::CPDF_DataAvail( m_bufferSize = 0; m_PagesObjNum = 0; m_dwCurrentXRefSteam = 0; - m_dwAcroFormObjNum = 0; m_dwInfoObjNum = 0; m_pDocument = 0; m_dwEncryptObjNum = 0; @@ -103,11 +102,8 @@ CPDF_DataAvail::CPDF_DataAvail( m_bPagesTreeLoad = false; m_bMainXRefLoadedOK = false; m_bAnnotsLoad = false; - m_bHaveAcroForm = false; - m_bAcroFormLoad = false; m_bPageLoadedOK = false; m_bNeedDownLoadResource = false; - m_bLinearizedFormParamLoad = false; m_pTrailer = nullptr; m_pCurrentParser = nullptr; m_pPageDict = nullptr; @@ -214,53 +210,6 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( return DataAvailable; } -bool CPDF_DataAvail::CheckAcroFormSubObject() { - if (m_objs_array.empty()) { - std::vector obj_array(m_Acroforms.size()); - std::transform( - m_Acroforms.begin(), m_Acroforms.end(), obj_array.begin(), - [](const std::unique_ptr& pObj) { return pObj.get(); }); - - m_ObjectSet.clear(); - if (!AreObjectsAvailable(obj_array, false, m_objs_array)) - return false; - - 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_Acroforms.clear(); - return true; -} - -bool CPDF_DataAvail::CheckAcroForm() { - bool bExist = false; - std::unique_ptr pAcroForm = - GetObject(m_dwAcroFormObjNum, &bExist); - if (!bExist) { - m_docStatus = PDF_DATAAVAIL_PAGETREE; - return true; - } - - if (!pAcroForm) { - if (m_docStatus != PDF_DATAAVAIL_ERROR) - return false; - - m_docStatus = PDF_DATAAVAIL_LOADALLFILE; - return true; - } - - m_Acroforms.push_back(std::move(pAcroForm)); - m_docStatus = PDF_DATAAVAIL_PAGETREE; - return true; -} - bool CPDF_DataAvail::CheckDocStatus() { switch (m_docStatus) { case PDF_DATAAVAIL_HEADER: @@ -285,8 +234,6 @@ bool CPDF_DataAvail::CheckDocStatus() { return CheckRoot(); case PDF_DATAAVAIL_INFO: return CheckInfo(); - case PDF_DATAAVAIL_ACROFORM: - return CheckAcroForm(); case PDF_DATAAVAIL_PAGETREE: if (m_bTotalLoadPageTree) return CheckPages(); @@ -379,8 +326,7 @@ bool CPDF_DataAvail::CheckInfo() { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } - m_docStatus = - m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; + m_docStatus = PDF_DATAAVAIL_PAGETREE; return true; } @@ -413,19 +359,8 @@ bool CPDF_DataAvail::CheckRoot() { } m_PagesObjNum = pRef->GetRefObjNum(); - CPDF_Reference* pAcroFormRef = - ToReference(m_pRoot->GetDict()->GetObjectFor("AcroForm")); - if (pAcroFormRef) { - m_bHaveAcroForm = true; - m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); - } - if (m_dwInfoObjNum) { - m_docStatus = PDF_DATAAVAIL_INFO; - } else { - m_docStatus = - m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; - } + m_docStatus = m_dwInfoObjNum ? PDF_DATAAVAIL_INFO : PDF_DATAAVAIL_PAGETREE; return true; } @@ -1312,11 +1247,8 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( } } - if (m_bHaveAcroForm && !m_bAcroFormLoad) { - if (!CheckAcroFormSubObject()) - return DataNotAvailable; - m_bAcroFormLoad = true; - } + if (CheckAcroForm() == DocFormStatus::FormNotAvailable) + return DataNotAvailable; if (!m_bPageLoadedOK) { if (m_objs_array.empty()) { @@ -1442,10 +1374,14 @@ CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { CPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( DownloadHints* pHints) { + const HintsScope hints_scope(GetValidator().Get(), pHints); + return CheckAcroForm(); +} + +CPDF_DataAvail::DocFormStatus CPDF_DataAvail::CheckAcroForm() { if (!m_pDocument) return FormAvailable; - const HintsScope hints_scope(GetValidator().Get(), pHints); if (m_pLinearized) { DocAvailStatus nDocStatus = CheckLinearizedData(); if (nDocStatus == DataError) @@ -1454,7 +1390,7 @@ CPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( return FormNotAvailable; } - if (!m_bLinearizedFormParamLoad) { + if (!m_pFormAvail) { const CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); if (!pRoot) return FormAvailable; @@ -1463,20 +1399,20 @@ CPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( if (!pAcroForm) return FormNotExist; - m_objs_array.push_back(pAcroForm->GetDict()); - m_bLinearizedFormParamLoad = true; + m_pFormAvail = pdfium::MakeUnique( + GetValidator().Get(), m_pDocument, pAcroForm); } - - std::vector new_objs_array; - if (!AreObjectsAvailable(m_objs_array, false, new_objs_array)) { - m_objs_array = new_objs_array; - return FormNotAvailable; + switch (m_pFormAvail->CheckAvail()) { + case DocAvailStatus::DataError: + return DocFormStatus::FormError; + case DocAvailStatus::DataNotAvailable: + return DocFormStatus::FormNotAvailable; + case DocAvailStatus::DataAvailable: + return DocFormStatus::FormAvailable; + default: + NOTREACHED(); } - - m_objs_array.clear(); - if (!ValidateForm()) - return FormError; - return FormAvailable; + return DocFormStatus::FormError; } bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) { @@ -1488,17 +1424,6 @@ bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) { return obj_avail.CheckAvail() == DocAvailStatus::DataAvailable; } -bool CPDF_DataAvail::ValidateForm() { - const CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); - if (!pRoot) - return true; - CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm"); - if (!pAcroForm) - return false; - CPDF_PageObjectAvail obj_avail(GetValidator().Get(), m_pDocument, pAcroForm); - return obj_avail.CheckAvail() == DocAvailStatus::DataAvailable; -} - CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} CPDF_DataAvail::PageNode::~PageNode() {} diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 7737ec0c3a..62a0e29773 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -19,6 +19,7 @@ class CPDF_Dictionary; class CPDF_HintTables; class CPDF_IndirectObjectHolder; class CPDF_LinearizedHeader; +class CPDF_PageObjectAvail; class CPDF_Parser; class CPDF_ReadValidator; @@ -33,8 +34,6 @@ enum PDF_DATAAVAIL_STATUS { PDF_DATAAVAIL_LOADALLCROSSREF, PDF_DATAAVAIL_ROOT, PDF_DATAAVAIL_INFO, - PDF_DATAAVAIL_ACROFORM, - PDF_DATAAVAIL_ACROFORM_SUBOBJECT, PDF_DATAAVAIL_PAGETREE, PDF_DATAAVAIL_PAGE, PDF_DATAAVAIL_PAGE_LATERLOAD, @@ -140,8 +139,7 @@ class CPDF_DataAvail final { bool CheckPages(); bool CheckPage(); bool CheckResources(); - bool CheckAcroForm(); - bool CheckAcroFormSubObject(); + DocFormStatus CheckAcroForm(); bool CheckPageStatus(); bool IsLinearizedFile(uint8_t* pData, uint32_t dwLen); @@ -176,7 +174,6 @@ class CPDF_DataAvail final { bool IsFirstCheck(uint32_t dwPage); void ResetFirstCheck(uint32_t dwPage); bool ValidatePage(uint32_t dwPage); - bool ValidateForm(); FileAvail* const m_pFileAvail; RetainPtr m_pFileRead; @@ -214,15 +211,11 @@ class CPDF_DataAvail final { CPDF_Parser* m_pCurrentParser; FX_FILESIZE m_dwCurrentXRefSteam; bool m_bAnnotsLoad; - bool m_bHaveAcroForm; - uint32_t m_dwAcroFormObjNum; - bool m_bAcroFormLoad; - std::vector> m_Acroforms; CPDF_Dictionary* m_pPageDict; CPDF_Object* m_pPageResource; bool m_bNeedDownLoadResource; bool m_bPageLoadedOK; - bool m_bLinearizedFormParamLoad; + std::unique_ptr m_pFormAvail; std::vector> m_PagesArray; uint32_t m_dwEncryptObjNum; FX_FILESIZE m_dwPrevXRefOffset; diff --git a/core/fpdfapi/parser/cpdf_object_avail.h b/core/fpdfapi/parser/cpdf_object_avail.h index 040cec7252..f593ea2159 100644 --- a/core/fpdfapi/parser/cpdf_object_avail.h +++ b/core/fpdfapi/parser/cpdf_object_avail.h @@ -43,7 +43,8 @@ class CPDF_ObjectAvail { bool HasObjectParsed(uint32_t obj_num) const; UnownedPtr validator_; - UnownedPtr holder_; + // TODO(art-snake): Make it UnownedPtr<, after fix document owning issue. + CPDF_IndirectObjectHolder* holder_; MaybeOwned root_; std::set parsed_objnums_; std::stack non_parsed_objects_; -- cgit v1.2.3