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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_dictionary.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, 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 | « core/fpdfapi/fpdf_parser/cpdf_boolean.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_name.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_dictionary.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" 9 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
16 #include "third_party/base/stl_util.h" 16 #include "third_party/base/stl_util.h"
17 17
18 CPDF_Dictionary::CPDF_Dictionary() {} 18 CPDF_Dictionary::CPDF_Dictionary() {}
19 19
20 CPDF_Dictionary::~CPDF_Dictionary() { 20 CPDF_Dictionary::~CPDF_Dictionary() {
21 m_ObjNum = kInvalidObjNum;
21 for (const auto& it : m_Map) 22 for (const auto& it : m_Map)
22 it.second->Release(); 23 it.second->Release();
23 } 24 }
24 25
25 CPDF_Object::Type CPDF_Dictionary::GetType() const { 26 CPDF_Object::Type CPDF_Dictionary::GetType() const {
26 return DICTIONARY; 27 return DICTIONARY;
27 } 28 }
28 29
29 CPDF_Dictionary* CPDF_Dictionary::GetDict() const { 30 CPDF_Dictionary* CPDF_Dictionary::GetDict() const {
30 // The method should be made non-const if we want to not be const. 31 // The method should be made non-const if we want to not be const.
31 // See bug #234. 32 // See bug #234.
32 return const_cast<CPDF_Dictionary*>(this); 33 return const_cast<CPDF_Dictionary*>(this);
33 } 34 }
34 35
35 bool CPDF_Dictionary::IsDictionary() const { 36 bool CPDF_Dictionary::IsDictionary() const {
36 return true; 37 return true;
37 } 38 }
38 39
39 CPDF_Dictionary* CPDF_Dictionary::AsDictionary() { 40 CPDF_Dictionary* CPDF_Dictionary::AsDictionary() {
40 return this; 41 return this;
41 } 42 }
42 43
43 const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const { 44 const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const {
44 return this; 45 return this;
45 } 46 }
46 47
47 CPDF_Object* CPDF_Dictionary::Clone(FX_BOOL bDirect) const { 48 CPDF_Object* CPDF_Dictionary::Clone() const {
49 return CloneObjectNonCyclic(false);
50 }
51
52 CPDF_Object* CPDF_Dictionary::CloneNonCyclic(
53 bool bDirect,
54 std::set<const CPDF_Object*>* pVisited) const {
55 pVisited->insert(this);
48 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); 56 CPDF_Dictionary* pCopy = new CPDF_Dictionary();
49 for (const auto& it : *this) 57 for (const auto& it : *this) {
50 pCopy->m_Map.insert(std::make_pair(it.first, it.second->Clone(bDirect))); 58 CPDF_Object* value = it.second;
59 if (!pdfium::ContainsKey(*pVisited, value)) {
60 pCopy->m_Map.insert(
61 std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited)));
62 }
63 }
51 return pCopy; 64 return pCopy;
52 } 65 }
53 66
54 CPDF_Object* CPDF_Dictionary::GetObjectBy(const CFX_ByteString& key) const { 67 CPDF_Object* CPDF_Dictionary::GetObjectBy(const CFX_ByteString& key) const {
55 auto it = m_Map.find(key); 68 auto it = m_Map.find(key);
56 return it != m_Map.end() ? it->second : nullptr; 69 return it != m_Map.end() ? it->second : nullptr;
57 } 70 }
58 71
59 CPDF_Object* CPDF_Dictionary::GetDirectObjectBy( 72 CPDF_Object* CPDF_Dictionary::GetDirectObjectBy(
60 const CFX_ByteString& key) const { 73 const CFX_ByteString& key) const {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 const CFX_Matrix& matrix) { 249 const CFX_Matrix& matrix) {
237 CPDF_Array* pArray = new CPDF_Array; 250 CPDF_Array* pArray = new CPDF_Array;
238 pArray->AddNumber(matrix.a); 251 pArray->AddNumber(matrix.a);
239 pArray->AddNumber(matrix.b); 252 pArray->AddNumber(matrix.b);
240 pArray->AddNumber(matrix.c); 253 pArray->AddNumber(matrix.c);
241 pArray->AddNumber(matrix.d); 254 pArray->AddNumber(matrix.d);
242 pArray->AddNumber(matrix.e); 255 pArray->AddNumber(matrix.e);
243 pArray->AddNumber(matrix.f); 256 pArray->AddNumber(matrix.f);
244 SetAt(key, pArray); 257 SetAt(key, pArray);
245 } 258 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_boolean.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_name.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698