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

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

Issue 2361303002: Avoid collisions in CPDF_IndirectObjectHolder::AddIndirectObject() (Closed)
Patch Set: back to old solution. Created 4 years, 3 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 | no next file » | 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_object.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h"
(...skipping 29 matching lines...) Expand all
40 40
41 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) { 41 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) {
42 return nullptr; 42 return nullptr;
43 } 43 }
44 44
45 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { 45 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
46 if (pObj->m_ObjNum) 46 if (pObj->m_ObjNum)
47 return pObj->m_ObjNum; 47 return pObj->m_ObjNum;
48 48
49 m_LastObjNum++; 49 m_LastObjNum++;
50 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak.
50 m_IndirectObjs[m_LastObjNum].reset(pObj); 51 m_IndirectObjs[m_LastObjNum].reset(pObj);
51 pObj->m_ObjNum = m_LastObjNum; 52 pObj->m_ObjNum = m_LastObjNum;
52 return m_LastObjNum; 53 return m_LastObjNum;
53 } 54 }
54 55
55 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( 56 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration(
56 uint32_t objnum, 57 uint32_t objnum,
57 CPDF_Object* pObj) { 58 CPDF_Object* pObj) {
58 if (!objnum || !pObj) 59 if (!objnum || !pObj)
59 return false; 60 return false;
60 61
61 CPDF_Object* pOldObj = GetIndirectObject(objnum); 62 CPDF_Object* pOldObj = GetIndirectObject(objnum);
62 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) { 63 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) {
63 delete pObj; 64 delete pObj;
64 return false; 65 return false;
65 } 66 }
66 pObj->m_ObjNum = objnum; 67 pObj->m_ObjNum = objnum;
67 m_IndirectObjs[objnum].reset(pObj); 68 m_IndirectObjs[objnum].reset(pObj);
68 m_LastObjNum = std::max(m_LastObjNum, objnum); 69 m_LastObjNum = std::max(m_LastObjNum, objnum);
69 return true; 70 return true;
70 } 71 }
71 72
72 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { 73 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) {
73 CPDF_Object* pObj = GetIndirectObject(objnum); 74 CPDF_Object* pObj = GetIndirectObject(objnum);
74 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) 75 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
75 return; 76 return;
76 77
77 m_IndirectObjs.erase(objnum); 78 m_IndirectObjs.erase(objnum);
78 } 79 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698