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/src/fpdfapi/fpdf_edit/editint.h" | 7 #include "core/src/fpdfapi/fpdf_edit/editint.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && | 957 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && |
958 m_pParser->m_ObjVersion[objnum] > 0) { | 958 m_pParser->m_ObjVersion[objnum] > 0) { |
959 return 1; | 959 return 1; |
960 } | 960 } |
961 | 961 |
962 if (pObj->IsNumber()) | 962 if (pObj->IsNumber()) |
963 return 1; | 963 return 1; |
964 | 964 |
965 CPDF_Dictionary* pDict = pObj->GetDict(); | 965 CPDF_Dictionary* pDict = pObj->GetDict(); |
966 if (pObj->IsStream()) { | 966 if (pObj->IsStream()) { |
967 if (pDict && pDict->GetString("Type") == "XRef") | 967 if (pDict && pDict->GetStringBy("Type") == "XRef") |
968 return 0; | 968 return 0; |
969 return 1; | 969 return 1; |
970 } | 970 } |
971 | 971 |
972 if (pDict) { | 972 if (pDict) { |
973 if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict) | 973 if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict) |
974 return 1; | 974 return 1; |
975 if (IsSignatureDict(pDict)) | 975 if (IsSignatureDict(pDict)) |
976 return 1; | 976 return 1; |
977 if (pDict->GetString("Type") == "Page") | 977 if (pDict->GetStringBy("Type") == "Page") |
978 return 1; | 978 return 1; |
979 } | 979 } |
980 | 980 |
981 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 981 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
982 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 982 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
983 return -1; | 983 return -1; |
984 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 984 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) |
985 return 0; | 985 return 0; |
986 if (!m_pXRefStream->End(this)) | 986 if (!m_pXRefStream->End(this)) |
987 return -1; | 987 return -1; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 FX_DWORD objnum, | 1032 FX_DWORD objnum, |
1033 CPDF_CryptoHandler* pCrypto) { | 1033 CPDF_CryptoHandler* pCrypto) { |
1034 CPDF_FlateEncoder encoder; | 1034 CPDF_FlateEncoder encoder; |
1035 encoder.Initialize(const_cast<CPDF_Stream*>(pStream->AsStream()), | 1035 encoder.Initialize(const_cast<CPDF_Stream*>(pStream->AsStream()), |
1036 pStream == m_pMetadata ? FALSE : m_bCompress); | 1036 pStream == m_pMetadata ? FALSE : m_bCompress); |
1037 CPDF_Encryptor encryptor; | 1037 CPDF_Encryptor encryptor; |
1038 if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData, | 1038 if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData, |
1039 encoder.m_dwSize)) { | 1039 encoder.m_dwSize)) { |
1040 return -1; | 1040 return -1; |
1041 } | 1041 } |
1042 if ((FX_DWORD)encoder.m_pDict->GetInteger("Length") != encryptor.m_dwSize) { | 1042 if ((FX_DWORD)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { |
1043 encoder.CloneDict(); | 1043 encoder.CloneDict(); |
1044 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1044 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
1045 } | 1045 } |
1046 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1046 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
1047 return -1; | 1047 return -1; |
1048 } | 1048 } |
1049 int len = m_File.AppendString("stream\r\n"); | 1049 int len = m_File.AppendString("stream\r\n"); |
1050 if (len < 0) { | 1050 if (len < 0) { |
1051 return -1; | 1051 return -1; |
1052 } | 1052 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 m_Offset += len; | 1148 m_Offset += len; |
1149 break; | 1149 break; |
1150 } | 1150 } |
1151 case CPDF_Object::STREAM: { | 1151 case CPDF_Object::STREAM: { |
1152 CPDF_FlateEncoder encoder; | 1152 CPDF_FlateEncoder encoder; |
1153 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), | 1153 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), |
1154 m_bCompress); | 1154 m_bCompress); |
1155 CPDF_Encryptor encryptor; | 1155 CPDF_Encryptor encryptor; |
1156 CPDF_CryptoHandler* pHandler = m_pCryptoHandler; | 1156 CPDF_CryptoHandler* pHandler = m_pCryptoHandler; |
1157 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); | 1157 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); |
1158 if ((FX_DWORD)encoder.m_pDict->GetInteger("Length") != | 1158 if ((FX_DWORD)encoder.m_pDict->GetIntegerBy("Length") != |
1159 encryptor.m_dwSize) { | 1159 encryptor.m_dwSize) { |
1160 encoder.CloneDict(); | 1160 encoder.CloneDict(); |
1161 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1161 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
1162 } | 1162 } |
1163 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1163 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
1164 return -1; | 1164 return -1; |
1165 } | 1165 } |
1166 if ((len = m_File.AppendString("stream\r\n")) < 0) { | 1166 if ((len = m_File.AppendString("stream\r\n")) < 0) { |
1167 return -1; | 1167 return -1; |
1168 } | 1168 } |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 return; | 2008 return; |
2009 } | 2009 } |
2010 std::vector<uint8_t> buffer = | 2010 std::vector<uint8_t> buffer = |
2011 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum); | 2011 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum); |
2012 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); | 2012 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
2013 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 2013 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
2014 return; | 2014 return; |
2015 } | 2015 } |
2016 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); | 2016 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); |
2017 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { | 2017 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { |
2018 if (m_pEncryptDict->GetString("Filter") == "Standard") { | 2018 if (m_pEncryptDict->GetStringBy("Filter") == "Standard") { |
2019 CPDF_StandardSecurityHandler handler; | 2019 CPDF_StandardSecurityHandler handler; |
2020 CFX_ByteString user_pass = m_pParser->GetPassword(); | 2020 CFX_ByteString user_pass = m_pParser->GetPassword(); |
2021 FX_DWORD flag = PDF_ENCRYPT_CONTENT; | 2021 FX_DWORD flag = PDF_ENCRYPT_CONTENT; |
2022 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, | 2022 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, |
2023 user_pass.GetLength(), flag); | 2023 user_pass.GetLength(), flag); |
2024 if (m_bNewCrypto) { | 2024 if (m_bNewCrypto) { |
2025 delete m_pCryptoHandler; | 2025 delete m_pCryptoHandler; |
2026 } | 2026 } |
2027 m_pCryptoHandler = new CPDF_StandardCryptoHandler; | 2027 m_pCryptoHandler = new CPDF_StandardCryptoHandler; |
2028 m_pCryptoHandler->Init(m_pEncryptDict, &handler); | 2028 m_pCryptoHandler->Init(m_pEncryptDict, &handler); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 m_bNewCrypto = FALSE; | 2078 m_bNewCrypto = FALSE; |
2079 if (!m_bStandardSecurity) { | 2079 if (!m_bStandardSecurity) { |
2080 return; | 2080 return; |
2081 } | 2081 } |
2082 if (m_pEncryptDict) { | 2082 if (m_pEncryptDict) { |
2083 m_pEncryptDict->Release(); | 2083 m_pEncryptDict->Release(); |
2084 m_pEncryptDict = NULL; | 2084 m_pEncryptDict = NULL; |
2085 } | 2085 } |
2086 m_bStandardSecurity = FALSE; | 2086 m_bStandardSecurity = FALSE; |
2087 } | 2087 } |
OLD | NEW |