OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdf_parser/include/cpdf_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 SetEncryptDictionary(nullptr); | 260 SetEncryptDictionary(nullptr); |
261 | 261 |
262 if (!m_pTrailer) | 262 if (!m_pTrailer) |
263 return FORMAT_ERROR; | 263 return FORMAT_ERROR; |
264 | 264 |
265 CPDF_Object* pEncryptObj = m_pTrailer->GetObjectBy("Encrypt"); | 265 CPDF_Object* pEncryptObj = m_pTrailer->GetObjectBy("Encrypt"); |
266 if (pEncryptObj) { | 266 if (pEncryptObj) { |
267 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { | 267 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
268 SetEncryptDictionary(pEncryptDict); | 268 SetEncryptDictionary(pEncryptDict); |
269 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { | 269 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
270 pEncryptObj = m_pDocument->GetOrParseIndirectObject(pRef->GetRefObjNum()); | 270 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
271 if (pEncryptObj) | 271 if (pEncryptObj) |
272 SetEncryptDictionary(pEncryptObj->GetDict()); | 272 SetEncryptDictionary(pEncryptObj->GetDict()); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 if (m_pEncryptDict) { | 276 if (m_pEncryptDict) { |
277 CFX_ByteString filter = m_pEncryptDict->GetStringBy("Filter"); | 277 CFX_ByteString filter = m_pEncryptDict->GetStringBy("Filter"); |
278 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; | 278 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; |
279 Error err = HANDLER_ERROR; | 279 Error err = HANDLER_ERROR; |
280 if (filter == "Standard") { | 280 if (filter == "Standard") { |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 } | 975 } |
976 | 976 |
977 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { | 977 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { |
978 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument.get(), *pos, 0); | 978 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument.get(), *pos, 0); |
979 if (!pObject) | 979 if (!pObject) |
980 return FALSE; | 980 return FALSE; |
981 | 981 |
982 if (m_pDocument) { | 982 if (m_pDocument) { |
983 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot(); | 983 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot(); |
984 if (pRootDict && pRootDict->GetObjNum() == pObject->m_ObjNum) { | 984 if (pRootDict && pRootDict->GetObjNum() == pObject->m_ObjNum) { |
985 // If |pObject| has an objnum assigned then this will leak as Release() | |
986 // will early exit. | |
987 if (pObject->IsStream()) | 985 if (pObject->IsStream()) |
988 pObject->Release(); | 986 pObject->Release(); |
989 return FALSE; | 987 return FALSE; |
990 } | 988 } |
991 if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(pObject->m_ObjNum, | 989 if (!m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject)) |
992 pObject)) { | |
993 return FALSE; | 990 return FALSE; |
994 } | |
995 } | 991 } |
996 | 992 |
997 CPDF_Stream* pStream = pObject->AsStream(); | 993 CPDF_Stream* pStream = pObject->AsStream(); |
998 if (!pStream) | 994 if (!pStream) |
999 return FALSE; | 995 return FALSE; |
1000 | 996 |
1001 CPDF_Dictionary* pDict = pStream->GetDict(); | 997 CPDF_Dictionary* pDict = pStream->GetDict(); |
1002 *pos = pDict->GetIntegerBy("Prev"); | 998 *pos = pDict->GetIntegerBy("Prev"); |
1003 int32_t size = pDict->GetIntegerBy("Size"); | 999 int32_t size = pDict->GetIntegerBy("Size"); |
1004 if (size < 0) { | 1000 if (size < 0) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 } | 1223 } |
1228 | 1224 |
1229 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) { | 1225 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) { |
1230 auto it = m_ObjectStreamMap.find(objnum); | 1226 auto it = m_ObjectStreamMap.find(objnum); |
1231 if (it != m_ObjectStreamMap.end()) | 1227 if (it != m_ObjectStreamMap.end()) |
1232 return it->second.get(); | 1228 return it->second.get(); |
1233 | 1229 |
1234 if (!m_pDocument) | 1230 if (!m_pDocument) |
1235 return nullptr; | 1231 return nullptr; |
1236 | 1232 |
1237 const CPDF_Stream* pStream = | 1233 const CPDF_Stream* pStream = ToStream(m_pDocument->GetIndirectObject(objnum)); |
1238 ToStream(m_pDocument->GetOrParseIndirectObject(objnum)); | |
1239 if (!pStream) | 1234 if (!pStream) |
1240 return nullptr; | 1235 return nullptr; |
1241 | 1236 |
1242 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; | 1237 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; |
1243 pStreamAcc->LoadAllData(pStream); | 1238 pStreamAcc->LoadAllData(pStream); |
1244 m_ObjectStreamMap[objnum].reset(pStreamAcc); | 1239 m_ObjectStreamMap[objnum].reset(pStreamAcc); |
1245 return pStreamAcc; | 1240 return pStreamAcc; |
1246 } | 1241 } |
1247 | 1242 |
1248 FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const { | 1243 FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const { |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1671 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1677 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1672 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1678 m_LastXRefOffset = 0; | 1673 m_LastXRefOffset = 0; |
1679 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1674 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1680 return FORMAT_ERROR; | 1675 return FORMAT_ERROR; |
1681 } | 1676 } |
1682 | 1677 |
1683 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1678 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1684 return SUCCESS; | 1679 return SUCCESS; |
1685 } | 1680 } |
OLD | NEW |