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

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

Issue 1946693002: Revert of Relax a couple checks to allow certain non-standard PDF files. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_parser/cpdf_parser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_parser/cpdf_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698