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_indirect_object_holder.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
12 | 11 |
13 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) | 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) |
14 : m_pParser(pParser), m_LastObjNum(0) { | 13 : m_pParser(pParser), m_LastObjNum(0) { |
15 if (pParser) | 14 if (pParser) |
16 m_LastObjNum = m_pParser->GetLastObjNum(); | 15 m_LastObjNum = m_pParser->GetLastObjNum(); |
17 } | 16 } |
18 | 17 |
19 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { | 18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { |
20 for (const auto& pair : m_IndirectObjs) | 19 for (const auto& pair : m_IndirectObjs) |
21 pair.second->Destroy(); | 20 pair.second->Destroy(); |
22 } | 21 } |
23 | 22 |
24 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { | 23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { |
25 if (objnum == 0) | 24 if (objnum == 0) |
26 return nullptr; | 25 return nullptr; |
27 | 26 |
28 CPDF_Object* result_obj = nullptr; | |
29 auto it = m_IndirectObjs.find(objnum); | 27 auto it = m_IndirectObjs.find(objnum); |
30 if (it != m_IndirectObjs.end()) { | 28 if (it != m_IndirectObjs.end()) |
31 CPDF_Object* obj = it->second; | 29 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second |
32 result_obj = | 30 : nullptr; |
33 obj->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second : nullptr; | |
34 // Xref object is not used by the pdf document itself. Some software thus | |
35 // reuse an object number for xref object. So when we get an xref object, | |
36 // try again to see whether another object with the same number is defined. | |
37 // If so, use that object instead. See chromium:596947. | |
38 CPDF_Dictionary* dict = | |
39 obj->IsStream() ? obj->GetDict() : obj->AsDictionary(); | |
40 if (!dict || dict->GetStringBy("Type") != "XRef") | |
41 return result_obj; | |
42 } | |
43 | 31 |
44 if (!m_pParser) | 32 if (!m_pParser) |
45 return nullptr; | 33 return nullptr; |
46 | 34 |
47 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); | 35 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); |
48 if (!pObj) | 36 if (!pObj) |
49 return result_obj; | 37 return nullptr; |
50 | 38 |
51 pObj->m_ObjNum = objnum; | 39 pObj->m_ObjNum = objnum; |
52 m_LastObjNum = std::max(m_LastObjNum, objnum); | 40 m_LastObjNum = std::max(m_LastObjNum, objnum); |
53 if (m_IndirectObjs[objnum]) | 41 if (m_IndirectObjs[objnum]) |
54 m_IndirectObjs[objnum]->Destroy(); | 42 m_IndirectObjs[objnum]->Destroy(); |
55 | 43 |
56 m_IndirectObjs[objnum] = pObj; | 44 m_IndirectObjs[objnum] = pObj; |
57 return pObj; | 45 return pObj; |
58 } | 46 } |
59 | 47 |
(...skipping 27 matching lines...) Expand all Loading... |
87 pObj->Destroy(); | 75 pObj->Destroy(); |
88 return FALSE; | 76 return FALSE; |
89 } | 77 } |
90 it->second->Destroy(); | 78 it->second->Destroy(); |
91 } | 79 } |
92 pObj->m_ObjNum = objnum; | 80 pObj->m_ObjNum = objnum; |
93 m_IndirectObjs[objnum] = pObj; | 81 m_IndirectObjs[objnum] = pObj; |
94 m_LastObjNum = std::max(m_LastObjNum, objnum); | 82 m_LastObjNum = std::max(m_LastObjNum, objnum); |
95 return TRUE; | 83 return TRUE; |
96 } | 84 } |
OLD | NEW |