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

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

Issue 2250533002: Fix stack overflow in object Clone() functions (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase again Created 4 years, 4 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
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_reference.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
10 #include "third_party/base/stl_util.h"
10 11
11 CPDF_Reference::CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum) 12 CPDF_Reference::CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum)
12 : m_pObjList(pDoc), m_RefObjNum(objnum) {} 13 : m_pObjList(pDoc), m_RefObjNum(objnum) {}
13 14
14 CPDF_Reference::~CPDF_Reference() {} 15 CPDF_Reference::~CPDF_Reference() {}
15 16
16 CPDF_Object::Type CPDF_Reference::GetType() const { 17 CPDF_Object::Type CPDF_Reference::GetType() const {
17 return REFERENCE; 18 return REFERENCE;
18 } 19 }
19 20
(...skipping 22 matching lines...) Expand all
42 } 43 }
43 44
44 CPDF_Reference* CPDF_Reference::AsReference() { 45 CPDF_Reference* CPDF_Reference::AsReference() {
45 return this; 46 return this;
46 } 47 }
47 48
48 const CPDF_Reference* CPDF_Reference::AsReference() const { 49 const CPDF_Reference* CPDF_Reference::AsReference() const {
49 return this; 50 return this;
50 } 51 }
51 52
52 CPDF_Object* CPDF_Reference::Clone(FX_BOOL bDirect) const { 53 CPDF_Object* CPDF_Reference::Clone() const {
54 return CloneObjectNonCyclic(false);
55 }
56
57 CPDF_Object* CPDF_Reference::CloneNonCyclic(
58 bool bDirect,
59 std::set<const CPDF_Object*>* pVisited) const {
60 pVisited->insert(this);
53 if (bDirect) { 61 if (bDirect) {
54 auto* pDirect = GetDirect(); 62 auto* pDirect = GetDirect();
55 return pDirect ? pDirect->Clone(TRUE) : nullptr; 63 return pDirect && !pdfium::ContainsKey(*pVisited, pDirect)
64 ? pDirect->CloneNonCyclic(true, pVisited)
65 : nullptr;
56 } 66 }
57 return new CPDF_Reference(m_pObjList, m_RefObjNum); 67 return new CPDF_Reference(m_pObjList, m_RefObjNum);
58 } 68 }
59 69
60 void CPDF_Reference::SetRef(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum) { 70 void CPDF_Reference::SetRef(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum) {
61 m_pObjList = pDoc; 71 m_pObjList = pDoc;
62 m_RefObjNum = objnum; 72 m_RefObjNum = objnum;
63 } 73 }
64 74
65 CPDF_Object* CPDF_Reference::GetDirect() const { 75 CPDF_Object* CPDF_Reference::GetDirect() const {
66 return m_pObjList ? m_pObjList->GetOrParseIndirectObject(m_RefObjNum) 76 return m_pObjList ? m_pObjList->GetOrParseIndirectObject(m_RefObjNum)
67 : nullptr; 77 : nullptr;
68 } 78 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_stream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698