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/parser/cpdf_parser.h" | 7 #include "core/fpdfapi/parser/cpdf_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 795 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
796 if (m_pTrailer) { | 796 if (m_pTrailer) { |
797 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); | 797 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); |
798 CPDF_Reference* pRef = ToReference(pRoot); | 798 CPDF_Reference* pRef = ToReference(pRoot); |
799 if (!pRoot || | 799 if (!pRoot || |
800 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 800 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
801 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 801 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
802 auto it = pTrailer->begin(); | 802 auto it = pTrailer->begin(); |
803 while (it != pTrailer->end()) { | 803 while (it != pTrailer->end()) { |
804 const CFX_ByteString& key = it->first; | 804 const CFX_ByteString& key = it->first; |
805 CPDF_Object* pElement = it->second; | 805 CPDF_Object* pElement = it->second.get(); |
806 ++it; | 806 ++it; |
807 uint32_t dwObjNum = | 807 uint32_t dwObjNum = |
808 pElement ? pElement->GetObjNum() : 0; | 808 pElement ? pElement->GetObjNum() : 0; |
809 if (dwObjNum) { | 809 if (dwObjNum) { |
810 m_pTrailer->SetReferenceFor(key, m_pDocument, | 810 m_pTrailer->SetNewFor<CPDF_Reference>( |
811 dwObjNum); | 811 key, m_pDocument, dwObjNum); |
812 } else { | 812 } else { |
813 m_pTrailer->SetFor(key, | 813 m_pTrailer->SetFor(key, pElement->Clone()); |
814 pElement->Clone().release()); | |
815 } | 814 } |
816 } | 815 } |
817 } | 816 } |
818 } else { | 817 } else { |
819 if (pObj->IsStream()) { | 818 if (pObj->IsStream()) { |
820 m_pTrailer = ToDictionary(pTrailer->Clone()); | 819 m_pTrailer = ToDictionary(pTrailer->Clone()); |
821 } else { | 820 } else { |
822 m_pTrailer = ToDictionary(std::move(pObj)); | 821 m_pTrailer = ToDictionary(std::move(pObj)); |
823 } | 822 } |
824 | 823 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 return true; | 1067 return true; |
1069 } | 1068 } |
1070 | 1069 |
1071 CPDF_Array* CPDF_Parser::GetIDArray() { | 1070 CPDF_Array* CPDF_Parser::GetIDArray() { |
1072 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; | 1071 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; |
1073 if (!pID) | 1072 if (!pID) |
1074 return nullptr; | 1073 return nullptr; |
1075 | 1074 |
1076 if (CPDF_Reference* pRef = pID->AsReference()) { | 1075 if (CPDF_Reference* pRef = pID->AsReference()) { |
1077 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release(); | 1076 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release(); |
1078 m_pTrailer->SetFor("ID", pID); | 1077 m_pTrailer->SetFor("ID", pdfium::WrapUnique(pID)); |
1079 } | 1078 } |
1080 return ToArray(pID); | 1079 return ToArray(pID); |
1081 } | 1080 } |
1082 | 1081 |
1083 uint32_t CPDF_Parser::GetRootObjNum() { | 1082 uint32_t CPDF_Parser::GetRootObjNum() { |
1084 CPDF_Reference* pRef = | 1083 CPDF_Reference* pRef = |
1085 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); | 1084 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); |
1086 return pRef ? pRef->GetRefObjNum() : 0; | 1085 return pRef ? pRef->GetRefObjNum() : 0; |
1087 } | 1086 } |
1088 | 1087 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1569 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1571 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1570 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1572 m_LastXRefOffset = 0; | 1571 m_LastXRefOffset = 0; |
1573 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1572 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1574 return FORMAT_ERROR; | 1573 return FORMAT_ERROR; |
1575 } | 1574 } |
1576 | 1575 |
1577 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1576 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1578 return SUCCESS; | 1577 return SUCCESS; |
1579 } | 1578 } |
OLD | NEW |