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 <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "core/fpdfapi/edit/cpdf_creator.h" | 12 #include "core/fpdfapi/edit/cpdf_creator.h" |
13 #include "core/fpdfapi/parser/cpdf_array.h" | 13 #include "core/fpdfapi/parser/cpdf_array.h" |
14 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" | 14 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" |
15 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 15 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
16 #include "core/fpdfapi/parser/cpdf_document.h" | 16 #include "core/fpdfapi/parser/cpdf_document.h" |
17 #include "core/fpdfapi/parser/cpdf_name.h" | 17 #include "core/fpdfapi/parser/cpdf_name.h" |
18 #include "core/fpdfapi/parser/cpdf_number.h" | 18 #include "core/fpdfapi/parser/cpdf_number.h" |
19 #include "core/fpdfapi/parser/cpdf_parser.h" | 19 #include "core/fpdfapi/parser/cpdf_parser.h" |
20 #include "core/fpdfapi/parser/cpdf_reference.h" | 20 #include "core/fpdfapi/parser/cpdf_reference.h" |
21 #include "core/fpdfapi/parser/cpdf_security_handler.h" | 21 #include "core/fpdfapi/parser/cpdf_security_handler.h" |
22 #include "core/fpdfapi/parser/cpdf_stream.h" | 22 #include "core/fpdfapi/parser/cpdf_stream.h" |
23 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 23 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
24 #include "core/fpdfapi/parser/cpdf_string.h" | 24 #include "core/fpdfapi/parser/cpdf_string.h" |
25 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 25 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
26 #include "core/fxcrt/cfx_maybe_owned.h" | 26 #include "core/fxcrt/cfx_maybe_owned.h" |
27 #include "core/fxcrt/fx_ext.h" | 27 #include "core/fxcrt/fx_ext.h" |
| 28 #include "third_party/base/ptr_util.h" |
28 #include "third_party/base/stl_util.h" | 29 #include "third_party/base/stl_util.h" |
29 | 30 |
30 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) | 31 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) |
31 #define PDF_XREFSTREAM_MAXSIZE 10000 | 32 #define PDF_XREFSTREAM_MAXSIZE 10000 |
32 | 33 |
33 #define FX_GETBYTEOFFSET32(a) 0 | 34 #define FX_GETBYTEOFFSET32(a) 0 |
34 #define FX_GETBYTEOFFSET40(a) 0 | 35 #define FX_GETBYTEOFFSET40(a) 0 |
35 #define FX_GETBYTEOFFSET48(a) 0 | 36 #define FX_GETBYTEOFFSET48(a) 0 |
36 #define FX_GETBYTEOFFSET56(a) 0 | 37 #define FX_GETBYTEOFFSET56(a) 0 |
37 #define FX_GETBYTEOFFSET24(a) ((uint8_t)(a >> 24)) | 38 #define FX_GETBYTEOFFSET24(a) ((uint8_t)(a >> 24)) |
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 if (m_iStage == 0) { | 1440 if (m_iStage == 0) { |
1440 if (!m_pParser) { | 1441 if (!m_pParser) { |
1441 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1442 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1442 } | 1443 } |
1443 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { | 1444 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { |
1444 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1445 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1445 } | 1446 } |
1446 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 1447 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
1447 m_pMetadata = pDict ? pDict->GetDirectObjectFor("Metadata") : nullptr; | 1448 m_pMetadata = pDict ? pDict->GetDirectObjectFor("Metadata") : nullptr; |
1448 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { | 1449 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { |
1449 m_pXRefStream.reset(new CPDF_XRefStream); | 1450 m_pXRefStream = pdfium::MakeUnique<CPDF_XRefStream>(); |
1450 m_pXRefStream->Start(); | 1451 m_pXRefStream->Start(); |
1451 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { | 1452 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { |
1452 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); | 1453 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); |
1453 m_pXRefStream->m_PrevOffset = prev; | 1454 m_pXRefStream->m_PrevOffset = prev; |
1454 } | 1455 } |
1455 } | 1456 } |
1456 m_iStage = 10; | 1457 m_iStage = 10; |
1457 } | 1458 } |
1458 if (m_iStage == 10) { | 1459 if (m_iStage == 10) { |
1459 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { | 1460 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 InitID(); | 1923 InitID(); |
1923 if (flags & FPDFCREATE_PROGRESSIVE) | 1924 if (flags & FPDFCREATE_PROGRESSIVE) |
1924 return true; | 1925 return true; |
1925 return Continue(nullptr) > -1; | 1926 return Continue(nullptr) > -1; |
1926 } | 1927 } |
1927 | 1928 |
1928 void CPDF_Creator::InitID(bool bDefault) { | 1929 void CPDF_Creator::InitID(bool bDefault) { |
1929 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; | 1930 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; |
1930 bool bNewId = !m_pIDArray; | 1931 bool bNewId = !m_pIDArray; |
1931 if (bNewId) { | 1932 if (bNewId) { |
1932 m_pIDArray.reset(new CPDF_Array); | 1933 m_pIDArray = pdfium::MakeUnique<CPDF_Array>(); |
1933 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; | 1934 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; |
1934 if (pID1) { | 1935 if (pID1) { |
1935 m_pIDArray->Add(pID1->Clone()); | 1936 m_pIDArray->Add(pID1->Clone()); |
1936 } else { | 1937 } else { |
1937 std::vector<uint8_t> buffer = | 1938 std::vector<uint8_t> buffer = |
1938 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); | 1939 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
1939 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); | 1940 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); |
1940 m_pIDArray->AddNew<CPDF_String>(bsBuffer, true); | 1941 m_pIDArray->AddNew<CPDF_String>(bsBuffer, true); |
1941 } | 1942 } |
1942 } | 1943 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 m_pCryptoHandler = nullptr; | 2013 m_pCryptoHandler = nullptr; |
2013 } | 2014 } |
2014 void CPDF_Creator::ResetStandardSecurity() { | 2015 void CPDF_Creator::ResetStandardSecurity() { |
2015 if (!m_bLocalCryptoHandler) | 2016 if (!m_bLocalCryptoHandler) |
2016 return; | 2017 return; |
2017 | 2018 |
2018 delete m_pCryptoHandler; | 2019 delete m_pCryptoHandler; |
2019 m_pCryptoHandler = nullptr; | 2020 m_pCryptoHandler = nullptr; |
2020 m_bLocalCryptoHandler = false; | 2021 m_bLocalCryptoHandler = false; |
2021 } | 2022 } |
OLD | NEW |