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" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
11 | 12 |
12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) | 13 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) |
13 : m_pParser(pParser), m_LastObjNum(0) { | 14 : m_pParser(pParser), m_LastObjNum(0) { |
14 if (pParser) | 15 if (pParser) |
15 m_LastObjNum = m_pParser->GetLastObjNum(); | 16 m_LastObjNum = m_pParser->GetLastObjNum(); |
16 } | 17 } |
17 | 18 |
18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { | 19 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { |
19 for (const auto& pair : m_IndirectObjs) | 20 for (const auto& pair : m_IndirectObjs) |
20 pair.second->Destroy(); | 21 pair.second->Destroy(); |
21 } | 22 } |
22 | 23 |
23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { | 24 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { |
24 if (objnum == 0) | 25 if (objnum == 0) |
25 return nullptr; | 26 return nullptr; |
26 | 27 |
| 28 CPDF_Object* result_obj = nullptr; |
27 auto it = m_IndirectObjs.find(objnum); | 29 auto it = m_IndirectObjs.find(objnum); |
28 if (it != m_IndirectObjs.end()) | 30 if (it != m_IndirectObjs.end()) { |
29 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second | 31 CPDF_Object* obj = it->second; |
30 : nullptr; | 32 result_obj = |
| 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 } |
31 | 43 |
32 if (!m_pParser) | 44 if (!m_pParser) |
33 return nullptr; | 45 return nullptr; |
34 | 46 |
35 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); | 47 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); |
36 if (!pObj) | 48 if (!pObj) |
37 return nullptr; | 49 return result_obj; |
38 | 50 |
39 pObj->m_ObjNum = objnum; | 51 pObj->m_ObjNum = objnum; |
40 m_LastObjNum = std::max(m_LastObjNum, objnum); | 52 m_LastObjNum = std::max(m_LastObjNum, objnum); |
41 if (m_IndirectObjs[objnum]) | 53 if (m_IndirectObjs[objnum]) |
42 m_IndirectObjs[objnum]->Destroy(); | 54 m_IndirectObjs[objnum]->Destroy(); |
43 | 55 |
44 m_IndirectObjs[objnum] = pObj; | 56 m_IndirectObjs[objnum] = pObj; |
45 return pObj; | 57 return pObj; |
46 } | 58 } |
47 | 59 |
(...skipping 27 matching lines...) Expand all Loading... |
75 pObj->Destroy(); | 87 pObj->Destroy(); |
76 return FALSE; | 88 return FALSE; |
77 } | 89 } |
78 it->second->Destroy(); | 90 it->second->Destroy(); |
79 } | 91 } |
80 pObj->m_ObjNum = objnum; | 92 pObj->m_ObjNum = objnum; |
81 m_IndirectObjs[objnum] = pObj; | 93 m_IndirectObjs[objnum] = pObj; |
82 m_LastObjNum = std::max(m_LastObjNum, objnum); | 94 m_LastObjNum = std::max(m_LastObjNum, objnum); |
83 return TRUE; | 95 return TRUE; |
84 } | 96 } |
OLD | NEW |