OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/edit/editint.h" | 7 #include "core/fpdfapi/edit/editint.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 463 } |
464 m_bNewData = TRUE; | 464 m_bNewData = TRUE; |
465 // TODO(thestig): Move to Init() and check return value. | 465 // TODO(thestig): Move to Init() and check return value. |
466 if (bXRefStream) | 466 if (bXRefStream) |
467 ::PngEncode(pBuffer, size, &m_pData, &m_dwSize); | 467 ::PngEncode(pBuffer, size, &m_pData, &m_dwSize); |
468 else | 468 else |
469 ::FlateEncode(pBuffer, size, &m_pData, &m_dwSize); | 469 ::FlateEncode(pBuffer, size, &m_pData, &m_dwSize); |
470 } | 470 } |
471 | 471 |
472 CPDF_FlateEncoder::~CPDF_FlateEncoder() { | 472 CPDF_FlateEncoder::~CPDF_FlateEncoder() { |
473 if (m_bCloned && m_pDict) | 473 if (m_bCloned) |
474 m_pDict->Release(); | 474 delete m_pDict; |
475 if (m_bNewData) | 475 if (m_bNewData) |
476 FX_Free(m_pData); | 476 FX_Free(m_pData); |
477 } | 477 } |
478 | 478 |
479 class CPDF_Encryptor { | 479 class CPDF_Encryptor { |
480 public: | 480 public: |
481 CPDF_Encryptor(CPDF_CryptoHandler* pHandler, | 481 CPDF_Encryptor(CPDF_CryptoHandler* pHandler, |
482 int objnum, | 482 int objnum, |
483 uint8_t* src_data, | 483 uint8_t* src_data, |
484 uint32_t src_size); | 484 uint32_t src_size); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 m_Offset(0), | 896 m_Offset(0), |
897 m_iStage(-1), | 897 m_iStage(-1), |
898 m_dwFlags(0), | 898 m_dwFlags(0), |
899 m_Pos(nullptr), | 899 m_Pos(nullptr), |
900 m_XrefStart(0), | 900 m_XrefStart(0), |
901 m_pIDArray(nullptr), | 901 m_pIDArray(nullptr), |
902 m_FileVersion(0) {} | 902 m_FileVersion(0) {} |
903 | 903 |
904 CPDF_Creator::~CPDF_Creator() { | 904 CPDF_Creator::~CPDF_Creator() { |
905 ResetStandardSecurity(); | 905 ResetStandardSecurity(); |
906 if (m_bEncryptCloned && m_pEncryptDict) { | 906 if (m_bEncryptCloned) { |
907 m_pEncryptDict->Release(); | 907 delete m_pEncryptDict; |
908 m_pEncryptDict = nullptr; | 908 m_pEncryptDict = nullptr; |
909 } | 909 } |
910 Clear(); | 910 Clear(); |
911 } | 911 } |
912 | 912 |
913 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 913 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
914 if (!m_pXRefStream) | 914 if (!m_pXRefStream) |
915 return 1; | 915 return 1; |
916 | 916 |
917 uint32_t objnum = pObj->GetObjNum(); | 917 uint32_t objnum = pObj->GetObjNum(); |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 void CPDF_Creator::InitID(FX_BOOL bDefault) { | 1928 void CPDF_Creator::InitID(FX_BOOL bDefault) { |
1929 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; | 1929 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; |
1930 FX_BOOL bNewId = !m_pIDArray; | 1930 FX_BOOL bNewId = !m_pIDArray; |
1931 if (bNewId) { | 1931 if (bNewId) { |
1932 m_pIDArray.reset(new CPDF_Array); | 1932 m_pIDArray.reset(new CPDF_Array); |
1933 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; | 1933 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; |
1934 if (pID1) { | 1934 if (pID1) { |
1935 m_pIDArray->Add(pID1->Clone()); | 1935 m_pIDArray->Add(pID1->Clone()); |
1936 } else { | 1936 } else { |
1937 std::vector<uint8_t> buffer = | 1937 std::vector<uint8_t> buffer = |
1938 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); | 1938 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
1939 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); | 1939 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); |
1940 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); | 1940 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); |
1941 } | 1941 } |
1942 } | 1942 } |
1943 if (!bDefault) { | 1943 if (!bDefault) { |
1944 return; | 1944 return; |
1945 } | 1945 } |
1946 if (pOldIDArray) { | 1946 if (pOldIDArray) { |
1947 CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1); | 1947 CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1); |
1948 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { | 1948 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { |
1949 m_pIDArray->Add(pID2->Clone()); | 1949 m_pIDArray->Add(pID2->Clone()); |
1950 return; | 1950 return; |
1951 } | 1951 } |
1952 std::vector<uint8_t> buffer = | 1952 std::vector<uint8_t> buffer = |
1953 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); | 1953 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
1954 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); | 1954 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); |
1955 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); | 1955 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); |
1956 return; | 1956 return; |
1957 } | 1957 } |
1958 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); | 1958 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); |
1959 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { | 1959 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { |
1960 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { | 1960 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { |
1961 CFX_ByteString user_pass = m_pParser->GetPassword(); | 1961 CFX_ByteString user_pass = m_pParser->GetPassword(); |
1962 uint32_t flag = PDF_ENCRYPT_CONTENT; | 1962 uint32_t flag = PDF_ENCRYPT_CONTENT; |
1963 | 1963 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 m_pCryptoHandler = nullptr; | 2013 m_pCryptoHandler = nullptr; |
2014 } | 2014 } |
2015 void CPDF_Creator::ResetStandardSecurity() { | 2015 void CPDF_Creator::ResetStandardSecurity() { |
2016 if (!m_bLocalCryptoHandler) | 2016 if (!m_bLocalCryptoHandler) |
2017 return; | 2017 return; |
2018 | 2018 |
2019 delete m_pCryptoHandler; | 2019 delete m_pCryptoHandler; |
2020 m_pCryptoHandler = nullptr; | 2020 m_pCryptoHandler = nullptr; |
2021 m_bLocalCryptoHandler = FALSE; | 2021 m_bLocalCryptoHandler = FALSE; |
2022 } | 2022 } |
OLD | NEW |