diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-12 16:50:51 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-13 06:00:01 +0000 |
commit | e0b592236db902e3e8cbca7ec64f8e2b192e1935 (patch) | |
tree | c77a5264e2a2f35c454471941045d3ccb0fe1172 /core/fpdfapi/edit | |
parent | d20e3880234a35a558237316cac5d70fff4224bc (diff) | |
download | pdfium-e0b592236db902e3e8cbca7ec64f8e2b192e1935.tar.xz |
Refcount CPDF_CryptoHandlerchromium/3076chromium/3075chromium/3074chromium/3073chromium/3072
Avoid tracking ownership via m_bLocalCryptoHandler.
Also remove m_bEncryptCloned, as it is always false.
Replace some methods with direct calls to underlying code.
Change-Id: Ifa9d6f721c59d07e3b8e258f76832ca9f2ea0fc9
Reviewed-on: https://pdfium-review.googlesource.com/4111
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r-- | core/fpdfapi/edit/cpdf_creator.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/edit/fpdf_edit_create.cpp | 36 |
2 files changed, 10 insertions, 32 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.h b/core/fpdfapi/edit/cpdf_creator.h index 0045a5929f..d3f18a82ab 100644 --- a/core/fpdfapi/edit/cpdf_creator.h +++ b/core/fpdfapi/edit/cpdf_creator.h @@ -44,7 +44,6 @@ class CPDF_Creator { friend class CPDF_XRefStream; bool Create(uint32_t flags); - void ResetStandardSecurity(); void Clear(); void InitOldObjNumOffsets(); @@ -80,10 +79,7 @@ class CPDF_Creator { bool m_bSecurityChanged; CPDF_Dictionary* m_pEncryptDict; uint32_t m_dwEncryptObjNum; - bool m_bEncryptCloned; - CPDF_CryptoHandler* m_pCryptoHandler; - // Whether this owns the crypto handler |m_pCryptoHandler|. - bool m_bLocalCryptoHandler; + CFX_RetainPtr<CPDF_CryptoHandler> m_pCryptoHandler; CPDF_Object* m_pMetadata; std::unique_ptr<CPDF_XRefStream> m_pXRefStream; int32_t m_ObjectStreamSize; diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp index d08e4b5302..f643d3f24e 100644 --- a/core/fpdfapi/edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/edit/fpdf_edit_create.cpp @@ -577,7 +577,7 @@ FX_FILESIZE CPDF_ObjectStream::End(CPDF_Creator* pCreator) { tempBuffer << m_Buffer; CPDF_FlateEncoder encoder(tempBuffer.GetBuffer(), tempBuffer.GetLength(), true, false); - CPDF_Encryptor encryptor(pCreator->m_pCryptoHandler, m_dwObjNum, + CPDF_Encryptor encryptor(pCreator->m_pCryptoHandler.Get(), m_dwObjNum, encoder.m_pData.Get(), encoder.m_dwSize); if ((len = pFile->AppendDWord(encryptor.m_dwSize)) < 0) { return -1; @@ -880,9 +880,7 @@ CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) m_bSecurityChanged(false), m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr), m_dwEncryptObjNum(0), - m_bEncryptCloned(false), m_pCryptoHandler(m_pParser ? m_pParser->GetCryptoHandler() : nullptr), - m_bLocalCryptoHandler(false), m_pMetadata(nullptr), m_ObjectStreamSize(200), m_dwLastObjNum(m_pDocument->GetLastObjNum()), @@ -896,11 +894,6 @@ CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) m_FileVersion(0) {} CPDF_Creator::~CPDF_Creator() { - ResetStandardSecurity(); - if (m_bEncryptCloned) { - delete m_pEncryptDict; - m_pEncryptDict = nullptr; - } Clear(); } @@ -1025,7 +1018,7 @@ int32_t CPDF_Creator::WriteIndirectObj(uint32_t objnum, m_Offset += len; if (pObj->IsStream()) { CPDF_CryptoHandler* pHandler = - pObj != m_pMetadata ? m_pCryptoHandler : nullptr; + pObj != m_pMetadata ? m_pCryptoHandler.Get() : nullptr; if (WriteStream(pObj, objnum, pHandler) < 0) return -1; } else { @@ -1086,8 +1079,8 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, m_Offset += len; break; } - CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(), - str.GetLength()); + CPDF_Encryptor encryptor(m_pCryptoHandler.Get(), objnum, + (uint8_t*)str.c_str(), str.GetLength()); CFX_ByteString content = PDF_EncodeString( CFX_ByteString((const char*)encryptor.m_pData, encryptor.m_dwSize), bHex); @@ -1100,8 +1093,8 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, case CPDF_Object::STREAM: { CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()), true); - CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData.Get(), - encoder.m_dwSize); + CPDF_Encryptor encryptor(m_pCryptoHandler.Get(), objnum, + encoder.m_pData.Get(), encoder.m_dwSize); if (static_cast<uint32_t>(encoder.m_pDict->GetIntegerFor("Length")) != encryptor.m_dwSize) { encoder.CloneDict(); @@ -1860,11 +1853,8 @@ void CPDF_Creator::InitID(bool bDefault) { CPDF_SecurityHandler handler; handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(), user_pass.GetLength(), flag); - if (m_bLocalCryptoHandler) - delete m_pCryptoHandler; - m_pCryptoHandler = new CPDF_CryptoHandler; + m_pCryptoHandler = pdfium::MakeRetain<CPDF_CryptoHandler>(); m_pCryptoHandler->Init(m_pEncryptDict, &handler); - m_bLocalCryptoHandler = true; m_bSecurityChanged = true; } } @@ -1902,17 +1892,9 @@ bool CPDF_Creator::SetFileVersion(int32_t fileVersion) { m_FileVersion = fileVersion; return true; } + void CPDF_Creator::RemoveSecurity() { - ResetStandardSecurity(); + m_pCryptoHandler.Reset(); m_bSecurityChanged = true; m_pEncryptDict = nullptr; - m_pCryptoHandler = nullptr; -} -void CPDF_Creator::ResetStandardSecurity() { - if (!m_bLocalCryptoHandler) - return; - - delete m_pCryptoHandler; - m_pCryptoHandler = nullptr; - m_bLocalCryptoHandler = false; } |