Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_parser.cpp

Issue 2253723002: Move parser pointer to CPDF_Document (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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->GetIndirectObject(pRef->GetRefObjNum()); 270 pEncryptObj = m_pDocument->GetIndirectObjectIfValid(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
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.
985 if (pObject->IsStream()) 987 if (pObject->IsStream())
986 pObject->Release(); 988 pObject->Release();
987 return FALSE; 989 return FALSE;
988 } 990 }
989 if (!m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject)) 991 if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(pObject->m_ObjNum,
992 pObject)) {
990 return FALSE; 993 return FALSE;
994 }
991 } 995 }
992 996
993 CPDF_Stream* pStream = pObject->AsStream(); 997 CPDF_Stream* pStream = pObject->AsStream();
994 if (!pStream) 998 if (!pStream)
995 return FALSE; 999 return FALSE;
996 1000
997 CPDF_Dictionary* pDict = pStream->GetDict(); 1001 CPDF_Dictionary* pDict = pStream->GetDict();
998 *pos = pDict->GetIntegerBy("Prev"); 1002 *pos = pDict->GetIntegerBy("Prev");
999 int32_t size = pDict->GetIntegerBy("Size"); 1003 int32_t size = pDict->GetIntegerBy("Size");
1000 if (size < 0) { 1004 if (size < 0) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 } 1227 }
1224 1228
1225 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) { 1229 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) {
1226 auto it = m_ObjectStreamMap.find(objnum); 1230 auto it = m_ObjectStreamMap.find(objnum);
1227 if (it != m_ObjectStreamMap.end()) 1231 if (it != m_ObjectStreamMap.end())
1228 return it->second.get(); 1232 return it->second.get();
1229 1233
1230 if (!m_pDocument) 1234 if (!m_pDocument)
1231 return nullptr; 1235 return nullptr;
1232 1236
1233 const CPDF_Stream* pStream = ToStream(m_pDocument->GetIndirectObject(objnum)); 1237 const CPDF_Stream* pStream =
1238 ToStream(m_pDocument->GetIndirectObjectIfValid(objnum));
1234 if (!pStream) 1239 if (!pStream)
1235 return nullptr; 1240 return nullptr;
1236 1241
1237 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; 1242 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc;
1238 pStreamAcc->LoadAllData(pStream); 1243 pStreamAcc->LoadAllData(pStream);
1239 m_ObjectStreamMap[objnum].reset(pStreamAcc); 1244 m_ObjectStreamMap[objnum].reset(pStreamAcc);
1240 return pStreamAcc; 1245 return pStreamAcc;
1241 } 1246 }
1242 1247
1243 FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const { 1248 FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const {
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1676 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1672 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1677 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1673 m_LastXRefOffset = 0; 1678 m_LastXRefOffset = 0;
1674 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1679 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1675 return FORMAT_ERROR; 1680 return FORMAT_ERROR;
1676 } 1681 }
1677 1682
1678 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1683 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1679 return SUCCESS; 1684 return SUCCESS;
1680 } 1685 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698