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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 m_Offset(0), | 895 m_Offset(0), |
896 m_iStage(-1), | 896 m_iStage(-1), |
897 m_dwFlags(0), | 897 m_dwFlags(0), |
898 m_Pos(nullptr), | 898 m_Pos(nullptr), |
899 m_XrefStart(0), | 899 m_XrefStart(0), |
900 m_pIDArray(nullptr), | 900 m_pIDArray(nullptr), |
901 m_FileVersion(0) {} | 901 m_FileVersion(0) {} |
902 | 902 |
903 CPDF_Creator::~CPDF_Creator() { | 903 CPDF_Creator::~CPDF_Creator() { |
904 ResetStandardSecurity(); | 904 ResetStandardSecurity(); |
905 if (m_bEncryptCloned && m_pEncryptDict) { | 905 if (m_bEncryptCloned) { |
906 m_pEncryptDict->Release(); | 906 delete m_pEncryptDict; |
907 m_pEncryptDict = nullptr; | 907 m_pEncryptDict = nullptr; |
908 } | 908 } |
909 Clear(); | 909 Clear(); |
910 } | 910 } |
911 | 911 |
912 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 912 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
913 if (!m_pXRefStream) | 913 if (!m_pXRefStream) |
914 return 1; | 914 return 1; |
915 | 915 |
916 uint32_t objnum = pObj->GetObjNum(); | 916 uint32_t objnum = pObj->GetObjNum(); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 bObjStm) { | 1240 bObjStm) { |
1241 CPDF_Object* pObj = m_pDocument->GetOrParseIndirectObject(objnum); | 1241 CPDF_Object* pObj = m_pDocument->GetOrParseIndirectObject(objnum); |
1242 if (!pObj) { | 1242 if (!pObj) { |
1243 m_ObjectOffset[objnum] = 0; | 1243 m_ObjectOffset[objnum] = 0; |
1244 return 0; | 1244 return 0; |
1245 } | 1245 } |
1246 if (WriteIndirectObj(pObj)) { | 1246 if (WriteIndirectObj(pObj)) { |
1247 return -1; | 1247 return -1; |
1248 } | 1248 } |
1249 if (!bExistInMap) { | 1249 if (!bExistInMap) { |
1250 m_pDocument->ReleaseIndirectObject(objnum); | 1250 m_pDocument->DeleteIndirectObject(objnum); |
1251 } | 1251 } |
1252 } else { | 1252 } else { |
1253 uint8_t* pBuffer; | 1253 uint8_t* pBuffer; |
1254 uint32_t size; | 1254 uint32_t size; |
1255 m_pParser->GetIndirectBinary(objnum, pBuffer, size); | 1255 m_pParser->GetIndirectBinary(objnum, pBuffer, size); |
1256 if (!pBuffer) { | 1256 if (!pBuffer) { |
1257 return 0; | 1257 return 0; |
1258 } | 1258 } |
1259 if (object_type == 2) { | 1259 if (object_type == 2) { |
1260 if (m_pXRefStream) { | 1260 if (m_pXRefStream) { |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 void CPDF_Creator::InitID(bool bDefault) { | 1927 void CPDF_Creator::InitID(bool bDefault) { |
1928 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; | 1928 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; |
1929 bool bNewId = !m_pIDArray; | 1929 bool bNewId = !m_pIDArray; |
1930 if (bNewId) { | 1930 if (bNewId) { |
1931 m_pIDArray.reset(new CPDF_Array); | 1931 m_pIDArray.reset(new CPDF_Array); |
1932 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; | 1932 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; |
1933 if (pID1) { | 1933 if (pID1) { |
1934 m_pIDArray->Add(pID1->Clone()); | 1934 m_pIDArray->Add(pID1->Clone()); |
1935 } else { | 1935 } else { |
1936 std::vector<uint8_t> buffer = | 1936 std::vector<uint8_t> buffer = |
1937 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); | 1937 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
1938 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); | 1938 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); |
1939 m_pIDArray->Add(new CPDF_String(bsBuffer, true)); | 1939 m_pIDArray->Add(new CPDF_String(bsBuffer, true)); |
1940 } | 1940 } |
1941 } | 1941 } |
1942 if (!bDefault) { | 1942 if (!bDefault) { |
1943 return; | 1943 return; |
1944 } | 1944 } |
1945 if (pOldIDArray) { | 1945 if (pOldIDArray) { |
1946 CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1); | 1946 CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1); |
1947 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { | 1947 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { |
1948 m_pIDArray->Add(pID2->Clone()); | 1948 m_pIDArray->Add(pID2->Clone()); |
1949 return; | 1949 return; |
1950 } | 1950 } |
1951 std::vector<uint8_t> buffer = | 1951 std::vector<uint8_t> buffer = |
1952 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); | 1952 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
1953 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); | 1953 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); |
1954 m_pIDArray->Add(new CPDF_String(bsBuffer, true)); | 1954 m_pIDArray->Add(new CPDF_String(bsBuffer, true)); |
1955 return; | 1955 return; |
1956 } | 1956 } |
1957 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); | 1957 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); |
1958 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { | 1958 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { |
1959 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { | 1959 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { |
1960 CFX_ByteString user_pass = m_pParser->GetPassword(); | 1960 CFX_ByteString user_pass = m_pParser->GetPassword(); |
1961 uint32_t flag = PDF_ENCRYPT_CONTENT; | 1961 uint32_t flag = PDF_ENCRYPT_CONTENT; |
1962 | 1962 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 m_pCryptoHandler = nullptr; | 2012 m_pCryptoHandler = nullptr; |
2013 } | 2013 } |
2014 void CPDF_Creator::ResetStandardSecurity() { | 2014 void CPDF_Creator::ResetStandardSecurity() { |
2015 if (!m_bLocalCryptoHandler) | 2015 if (!m_bLocalCryptoHandler) |
2016 return; | 2016 return; |
2017 | 2017 |
2018 delete m_pCryptoHandler; | 2018 delete m_pCryptoHandler; |
2019 m_pCryptoHandler = nullptr; | 2019 m_pCryptoHandler = nullptr; |
2020 m_bLocalCryptoHandler = false; | 2020 m_bLocalCryptoHandler = false; |
2021 } | 2021 } |
OLD | NEW |