summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.cpp14
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.h3
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp21
-rw-r--r--core/fpdfapi/parser/cpdf_document.h7
-rw-r--r--core/fpdfapi/parser/cpdf_security_handler.cpp12
5 files changed, 38 insertions, 19 deletions
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 1ede5e707a..5257a20586 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -130,7 +130,19 @@ bool CPDF_Dictionary::GetBooleanFor(const ByteString& key,
return ToBoolean(p) ? p->GetInteger() != 0 : bDefault;
}
-CPDF_Dictionary* CPDF_Dictionary::GetDictFor(const ByteString& key) const {
+const CPDF_Dictionary* CPDF_Dictionary::GetDictFor(
+ const ByteString& key) const {
+ CPDF_Object* p = GetDirectObjectFor(key);
+ if (!p)
+ return nullptr;
+ if (CPDF_Dictionary* pDict = p->AsDictionary())
+ return pDict;
+ if (CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
+ return nullptr;
+}
+
+CPDF_Dictionary* CPDF_Dictionary::GetDictFor(const ByteString& key) {
CPDF_Object* p = GetDirectObjectFor(key);
if (!p)
return nullptr;
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index df789aa7b4..5240ab3b5c 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -51,7 +51,8 @@ class CPDF_Dictionary : public CPDF_Object {
int GetIntegerFor(const ByteString& key, int default_int) const;
bool GetBooleanFor(const ByteString& key, bool bDefault = false) const;
float GetNumberFor(const ByteString& key) const;
- CPDF_Dictionary* GetDictFor(const ByteString& key) const;
+ const CPDF_Dictionary* GetDictFor(const ByteString& key) const;
+ CPDF_Dictionary* GetDictFor(const ByteString& key);
const CPDF_Stream* GetStreamFor(const ByteString& key) const;
CPDF_Stream* GetStreamFor(const ByteString& key);
const CPDF_Array* GetArrayFor(const ByteString& key) const;
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 5264d4e795..5479a06174 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -322,11 +322,16 @@ void CPDF_Document::ResetTraversal() {
m_pTreeTraversal.clear();
}
-CPDF_Dictionary* CPDF_Document::GetPagesDict() const {
+const CPDF_Dictionary* CPDF_Document::GetPagesDict() const {
const CPDF_Dictionary* pRoot = GetRoot();
return pRoot ? pRoot->GetDictFor("Pages") : nullptr;
}
+CPDF_Dictionary* CPDF_Document::GetPagesDict() {
+ CPDF_Dictionary* pRoot = GetRoot();
+ return pRoot ? pRoot->GetDictFor("Pages") : nullptr;
+}
+
bool CPDF_Document::IsPageLoaded(int iPage) const {
return !!m_PageList[iPage];
}
@@ -363,7 +368,7 @@ void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) {
m_PageList[iPage] = objNum;
}
-int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
+int CPDF_Document::FindPageIndex(const CPDF_Dictionary* pNode,
uint32_t* skip_count,
uint32_t objnum,
int* index,
@@ -379,7 +384,7 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
return -1;
}
- CPDF_Array* pKidList = pNode->GetArrayFor("Kids");
+ const CPDF_Array* pKidList = pNode->GetArrayFor("Kids");
if (!pKidList)
return -1;
@@ -395,14 +400,14 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
if (count && count == pKidList->GetCount()) {
for (size_t i = 0; i < count; i++) {
- CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i));
+ const CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i));
if (pKid && pKid->GetRefObjNum() == objnum)
return static_cast<int>(*index + i);
}
}
for (size_t i = 0; i < pKidList->GetCount(); i++) {
- CPDF_Dictionary* pKid = pKidList->GetDictAt(i);
+ const CPDF_Dictionary* pKid = pKidList->GetDictAt(i);
if (!pKid || pKid == pNode)
continue;
@@ -426,7 +431,7 @@ int CPDF_Document::GetPageIndex(uint32_t objnum) {
bSkipped = true;
}
}
- CPDF_Dictionary* pPages = GetPagesDict();
+ const CPDF_Dictionary* pPages = GetPagesDict();
if (!pPages)
return -1;
@@ -445,7 +450,7 @@ int CPDF_Document::GetPageCount() const {
return pdfium::CollectionSize<int>(m_PageList);
}
-int CPDF_Document::RetrievePageCount() const {
+int CPDF_Document::RetrievePageCount() {
CPDF_Dictionary* pPages = GetPagesDict();
if (!pPages)
return 0;
@@ -576,7 +581,7 @@ bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages,
}
bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) {
- const CPDF_Dictionary* pRoot = GetRoot();
+ CPDF_Dictionary* pRoot = GetRoot();
CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr;
if (!pPages)
return false;
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index b169175668..356d341302 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -115,10 +115,10 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
protected:
// Retrieve page count information by getting count value from the tree nodes
- int RetrievePageCount() const;
+ int RetrievePageCount();
// When this method is called, m_pTreeTraversal[level] exists.
CPDF_Dictionary* TraversePDFPages(int iPage, int* nPagesToGo, size_t level);
- int FindPageIndex(CPDF_Dictionary* pNode,
+ int FindPageIndex(const CPDF_Dictionary* pNode,
uint32_t* skip_count,
uint32_t objnum,
int* index,
@@ -126,7 +126,8 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
std::unique_ptr<CPDF_Object> ParseIndirectObject(uint32_t objnum) override;
void LoadDocInternal();
size_t CalculateEncodingDict(int charset, CPDF_Dictionary* pBaseDict);
- CPDF_Dictionary* GetPagesDict() const;
+ const CPDF_Dictionary* GetPagesDict() const;
+ CPDF_Dictionary* GetPagesDict();
CPDF_Dictionary* ProcessbCJK(
CPDF_Dictionary* pBaseDict,
int charset,
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index 7eb5c42f72..eeba53ef34 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -130,17 +130,17 @@ static bool LoadCryptInfo(const CPDF_Dictionary* pEncryptDict,
cipher = FXCIPHER_RC4;
keylen = 0;
if (Version >= 4) {
- CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDictFor("CF");
- if (!pCryptFilters) {
+ const CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDictFor("CF");
+ if (!pCryptFilters)
return false;
- }
+
if (name == "Identity") {
cipher = FXCIPHER_NONE;
} else {
- CPDF_Dictionary* pDefFilter = pCryptFilters->GetDictFor(name);
- if (!pDefFilter) {
+ const CPDF_Dictionary* pDefFilter = pCryptFilters->GetDictFor(name);
+ if (!pDefFilter)
return false;
- }
+
int nKeyBits = 0;
if (Version == 4) {
nKeyBits = pDefFilter->GetIntegerFor("Length", 0);