| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 uint8_t* m_pData; | 397 uint8_t* m_pData; |
| 398 uint32_t m_dwSize; | 398 uint32_t m_dwSize; |
| 399 CPDF_Dictionary* m_pDict; | 399 CPDF_Dictionary* m_pDict; |
| 400 bool m_bCloned; | 400 bool m_bCloned; |
| 401 bool m_bNewData; | 401 bool m_bNewData; |
| 402 CPDF_StreamAcc m_Acc; | 402 CPDF_StreamAcc m_Acc; |
| 403 }; | 403 }; |
| 404 | 404 |
| 405 void CPDF_FlateEncoder::CloneDict() { | 405 void CPDF_FlateEncoder::CloneDict() { |
| 406 if (!m_bCloned) { | 406 if (!m_bCloned) { |
| 407 m_pDict = ToDictionary(m_pDict->Clone()); | 407 m_pDict = ToDictionary(m_pDict->Clone().release()); |
| 408 ASSERT(m_pDict); | 408 ASSERT(m_pDict); |
| 409 m_bCloned = true; | 409 m_bCloned = true; |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 | 412 |
| 413 CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode) | 413 CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode) |
| 414 : m_pData(nullptr), | 414 : m_pData(nullptr), |
| 415 m_dwSize(0), | 415 m_dwSize(0), |
| 416 m_pDict(nullptr), | 416 m_pDict(nullptr), |
| 417 m_bCloned(false), | 417 m_bCloned(false), |
| 418 m_bNewData(false) { | 418 m_bNewData(false) { |
| 419 m_Acc.LoadAllData(pStream, true); | 419 m_Acc.LoadAllData(pStream, true); |
| 420 if ((pStream && pStream->GetDict() && | 420 if ((pStream && pStream->GetDict() && |
| 421 pStream->GetDict()->KeyExist("Filter")) || | 421 pStream->GetDict()->KeyExist("Filter")) || |
| 422 !bFlateEncode) { | 422 !bFlateEncode) { |
| 423 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { | 423 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { |
| 424 CPDF_StreamAcc destAcc; | 424 CPDF_StreamAcc destAcc; |
| 425 destAcc.LoadAllData(pStream); | 425 destAcc.LoadAllData(pStream); |
| 426 m_dwSize = destAcc.GetSize(); | 426 m_dwSize = destAcc.GetSize(); |
| 427 m_pData = (uint8_t*)destAcc.DetachData(); | 427 m_pData = (uint8_t*)destAcc.DetachData(); |
| 428 m_pDict = ToDictionary(pStream->GetDict()->Clone()); | 428 m_pDict = ToDictionary(pStream->GetDict()->Clone().release()); |
| 429 m_pDict->RemoveFor("Filter"); | 429 m_pDict->RemoveFor("Filter"); |
| 430 m_bNewData = true; | 430 m_bNewData = true; |
| 431 m_bCloned = true; | 431 m_bCloned = true; |
| 432 } else { | 432 } else { |
| 433 m_pData = (uint8_t*)m_Acc.GetData(); | 433 m_pData = (uint8_t*)m_Acc.GetData(); |
| 434 m_dwSize = m_Acc.GetSize(); | 434 m_dwSize = m_Acc.GetSize(); |
| 435 m_pDict = pStream->GetDict(); | 435 m_pDict = pStream->GetDict(); |
| 436 } | 436 } |
| 437 return; | 437 return; |
| 438 } | 438 } |
| 439 | 439 |
| 440 m_bNewData = true; | 440 m_bNewData = true; |
| 441 m_bCloned = true; | 441 m_bCloned = true; |
| 442 // TODO(thestig): Move to Init() and check return value. | 442 // TODO(thestig): Move to Init() and check return value. |
| 443 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), &m_pData, &m_dwSize); | 443 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), &m_pData, &m_dwSize); |
| 444 m_pDict = ToDictionary(pStream->GetDict()->Clone()); | 444 m_pDict = ToDictionary(pStream->GetDict()->Clone().release()); |
| 445 m_pDict->SetIntegerFor("Length", m_dwSize); | 445 m_pDict->SetIntegerFor("Length", m_dwSize); |
| 446 m_pDict->SetNameFor("Filter", "FlateDecode"); | 446 m_pDict->SetNameFor("Filter", "FlateDecode"); |
| 447 m_pDict->RemoveFor("DecodeParms"); | 447 m_pDict->RemoveFor("DecodeParms"); |
| 448 } | 448 } |
| 449 | 449 |
| 450 CPDF_FlateEncoder::CPDF_FlateEncoder(const uint8_t* pBuffer, | 450 CPDF_FlateEncoder::CPDF_FlateEncoder(const uint8_t* pBuffer, |
| 451 uint32_t size, | 451 uint32_t size, |
| 452 bool bFlateEncode, | 452 bool bFlateEncode, |
| 453 bool bXRefStream) | 453 bool bXRefStream) |
| 454 : m_pData(nullptr), | 454 : m_pData(nullptr), |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1924 return Continue(nullptr) > -1; | 1924 return Continue(nullptr) > -1; |
| 1925 } | 1925 } |
| 1926 | 1926 |
| 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().release()); |
| 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().release()); |
| 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().release()); |
| 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 |
| 1963 CPDF_SecurityHandler handler; | 1963 CPDF_SecurityHandler handler; |
| 1964 handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(), | 1964 handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(), |
| 1965 user_pass.GetLength(), flag); | 1965 user_pass.GetLength(), flag); |
| 1966 if (m_bLocalCryptoHandler) | 1966 if (m_bLocalCryptoHandler) |
| 1967 delete m_pCryptoHandler; | 1967 delete m_pCryptoHandler; |
| (...skipping 44 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 |