From a18536af5b32b63f795d8b5812a4303c7ee6ea97 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Wed, 18 Jul 2018 03:42:38 +0000 Subject: Make CPDF_Parser::GetTrailer const method. Use own copy of encryption dictionary within CPDF_Parser, to prevent modification of original trailer. Change-Id: I6246b872d431b94411fcec694c5176f8d85dfe26 Reviewed-on: https://pdfium-review.googlesource.com/35450 Commit-Queue: Art Snake Reviewed-by: Lei Zhang --- core/fpdfapi/parser/cpdf_parser.cpp | 14 +++++++------- core/fpdfapi/parser/cpdf_parser.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index f7846eff31..8d4d7728ab 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -185,8 +185,8 @@ bool CPDF_Parser::IsObjectFree(uint32_t objnum) const { return GetObjectType(objnum) == ObjectType::kFree; } -void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { - m_pEncryptDict = pDict; +void CPDF_Parser::SetEncryptDictionary(const CPDF_Dictionary* pDict) { + m_pEncryptDict = pDict ? ToDictionary(pDict->Clone()) : nullptr; } RetainPtr CPDF_Parser::GetFileAccess() const { @@ -338,11 +338,11 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { if (!GetTrailer()) return FORMAT_ERROR; - CPDF_Object* pEncryptObj = GetTrailer()->GetObjectFor("Encrypt"); + const CPDF_Object* pEncryptObj = GetTrailer()->GetObjectFor("Encrypt"); if (pEncryptObj) { - if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { + if (const CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { SetEncryptDictionary(pEncryptDict); - } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { + } else if (const CPDF_Reference* pRef = pEncryptObj->AsReference()) { pEncryptObj = m_pObjectsHolder->GetOrParseIndirectObject(pRef->GetRefObjNum()); if (pEncryptObj) @@ -357,7 +357,7 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { std::unique_ptr pSecurityHandler = pdfium::MakeUnique(); - if (!pSecurityHandler->OnInit(m_pEncryptDict.Get(), GetIDArray(), + if (!pSecurityHandler->OnInit(m_pEncryptDict.get(), GetIDArray(), m_Password)) return PASSWORD_ERROR; @@ -1112,7 +1112,7 @@ CPDF_Dictionary* CPDF_Parser::GetRoot() const { return obj ? obj->GetDict() : nullptr; } -CPDF_Dictionary* CPDF_Parser::GetTrailer() const { +const CPDF_Dictionary* CPDF_Parser::GetTrailer() const { return m_TrailerData->GetMainTrailer(); } diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h index c998063394..e9b2a760ea 100644 --- a/core/fpdfapi/parser/cpdf_parser.h +++ b/core/fpdfapi/parser/cpdf_parser.h @@ -64,7 +64,7 @@ class CPDF_Parser { void SetPassword(const char* password) { m_Password = password; } ByteString GetPassword() const { return m_Password; } - CPDF_Dictionary* GetTrailer() const; + const CPDF_Dictionary* GetTrailer() const; // Returns a new trailer which combines the last read trailer with the /Root // and /Info from previous ones. @@ -78,7 +78,7 @@ class CPDF_Parser { const CPDF_Array* GetIDArray() const; CPDF_Dictionary* GetRoot() const; - CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict.Get(); } + CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict.get(); } std::unique_ptr ParseIndirectObject(uint32_t objnum); @@ -159,7 +159,7 @@ class CPDF_Parser { Error LoadLinearizedMainXRefTable(); const CPDF_ObjectStream* GetObjectStream(uint32_t object_number); std::unique_ptr ParseLinearizedHeader(); - void SetEncryptDictionary(CPDF_Dictionary* pDict); + void SetEncryptDictionary(const CPDF_Dictionary* pDict); void ShrinkObjectMap(uint32_t size); // A simple check whether the cross reference table matches with // the objects. @@ -190,7 +190,7 @@ class CPDF_Parser { // m_TrailerData must be destroyed after m_pSecurityHandler due to the // ownership of the ID array data. std::unique_ptr m_TrailerData; - UnownedPtr m_pEncryptDict; + std::unique_ptr m_pEncryptDict; FX_FILESIZE m_LastXRefOffset; std::unique_ptr m_pSecurityHandler; ByteString m_Password; -- cgit v1.2.3