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

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

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: rebase Created 4 years, 1 month 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/parser/cpdf_parser.h" 7 #include "core/fpdfapi/parser/cpdf_parser.h"
8 8
9 #include <algorithm>
10 #include <utility>
9 #include <vector> 11 #include <vector>
10 12
11 #include "core/fpdfapi/parser/cpdf_array.h" 13 #include "core/fpdfapi/parser/cpdf_array.h"
12 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" 14 #include "core/fpdfapi/parser/cpdf_crypto_handler.h"
13 #include "core/fpdfapi/parser/cpdf_dictionary.h" 15 #include "core/fpdfapi/parser/cpdf_dictionary.h"
14 #include "core/fpdfapi/parser/cpdf_document.h" 16 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fpdfapi/parser/cpdf_linearized_header.h" 17 #include "core/fpdfapi/parser/cpdf_linearized_header.h"
16 #include "core/fpdfapi/parser/cpdf_number.h" 18 #include "core/fpdfapi/parser/cpdf_number.h"
17 #include "core/fpdfapi/parser/cpdf_reference.h" 19 #include "core/fpdfapi/parser/cpdf_reference.h"
18 #include "core/fpdfapi/parser/cpdf_security_handler.h" 20 #include "core/fpdfapi/parser/cpdf_security_handler.h"
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 pStream ? pStream->GetDict() : pObj->AsDictionary()) { 797 pStream ? pStream->GetDict() : pObj->AsDictionary()) {
796 if (m_pTrailer) { 798 if (m_pTrailer) {
797 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); 799 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root");
798 CPDF_Reference* pRef = ToReference(pRoot); 800 CPDF_Reference* pRef = ToReference(pRoot);
799 if (!pRoot || 801 if (!pRoot ||
800 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && 802 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) &&
801 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { 803 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) {
802 auto it = pTrailer->begin(); 804 auto it = pTrailer->begin();
803 while (it != pTrailer->end()) { 805 while (it != pTrailer->end()) {
804 const CFX_ByteString& key = it->first; 806 const CFX_ByteString& key = it->first;
805 CPDF_Object* pElement = it->second; 807 CPDF_Object* pElement = it->second.get();
806 ++it; 808 ++it;
807 uint32_t dwObjNum = 809 uint32_t dwObjNum =
808 pElement ? pElement->GetObjNum() : 0; 810 pElement ? pElement->GetObjNum() : 0;
809 if (dwObjNum) { 811 if (dwObjNum) {
810 m_pTrailer->SetReferenceFor(key, m_pDocument, 812 m_pTrailer->SetNewFor<CPDF_Reference>(
811 dwObjNum); 813 key, m_pDocument, dwObjNum);
812 } else { 814 } else {
813 m_pTrailer->SetFor(key, 815 m_pTrailer->SetFor(key, pElement->Clone());
814 pElement->Clone().release());
815 } 816 }
816 } 817 }
817 } 818 }
818 } else { 819 } else {
819 if (pObj->IsStream()) { 820 if (pObj->IsStream()) {
820 m_pTrailer = ToDictionary(pTrailer->Clone()); 821 m_pTrailer = ToDictionary(pTrailer->Clone());
821 } else { 822 } else {
822 m_pTrailer = ToDictionary(std::move(pObj)); 823 m_pTrailer = ToDictionary(std::move(pObj));
823 } 824 }
824 825
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 return true; 1069 return true;
1069 } 1070 }
1070 1071
1071 CPDF_Array* CPDF_Parser::GetIDArray() { 1072 CPDF_Array* CPDF_Parser::GetIDArray() {
1072 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; 1073 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr;
1073 if (!pID) 1074 if (!pID)
1074 return nullptr; 1075 return nullptr;
1075 1076
1076 if (CPDF_Reference* pRef = pID->AsReference()) { 1077 if (CPDF_Reference* pRef = pID->AsReference()) {
1077 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release(); 1078 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release();
1078 m_pTrailer->SetFor("ID", pID); 1079 m_pTrailer->SetFor("ID", pdfium::WrapUnique(pID));
1079 } 1080 }
1080 return ToArray(pID); 1081 return ToArray(pID);
1081 } 1082 }
1082 1083
1083 uint32_t CPDF_Parser::GetRootObjNum() { 1084 uint32_t CPDF_Parser::GetRootObjNum() {
1084 CPDF_Reference* pRef = 1085 CPDF_Reference* pRef =
1085 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); 1086 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr);
1086 return pRef ? pRef->GetRefObjNum() : 0; 1087 return pRef ? pRef->GetRefObjNum() : 0;
1087 } 1088 }
1088 1089
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1571 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1571 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1572 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1572 m_LastXRefOffset = 0; 1573 m_LastXRefOffset = 0;
1573 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1574 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1574 return FORMAT_ERROR; 1575 return FORMAT_ERROR;
1575 } 1576 }
1576 1577
1577 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1578 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1578 return SUCCESS; 1579 return SUCCESS;
1579 } 1580 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_object_unittest.cpp ('k') | core/fpdfapi/parser/cpdf_security_handler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698