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

Unified 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, 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
index 78b88a1b2f1a84027057b72047a41b871f4fd162..8fef074d4bd184ded1d831f406f4ec470b85cbf1 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
@@ -18,6 +18,7 @@
CPDF_Dictionary::CPDF_Dictionary() {}
CPDF_Dictionary::~CPDF_Dictionary() {
+ m_ObjNum = kInvalidObjNum;
for (const auto& it : m_Map)
it.second->Release();
}
@@ -44,10 +45,22 @@ const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const {
return this;
}
-CPDF_Object* CPDF_Dictionary::Clone(FX_BOOL bDirect) const {
+CPDF_Object* CPDF_Dictionary::Clone() const {
+ return CloneObjectNonCyclic(false);
+}
+
+CPDF_Object* CPDF_Dictionary::CloneNonCyclic(
+ bool bDirect,
+ std::set<const CPDF_Object*>* pVisited) const {
+ pVisited->insert(this);
CPDF_Dictionary* pCopy = new CPDF_Dictionary();
- for (const auto& it : *this)
- pCopy->m_Map.insert(std::make_pair(it.first, it.second->Clone(bDirect)));
+ for (const auto& it : *this) {
+ CPDF_Object* value = it.second;
+ if (!pdfium::ContainsKey(*pVisited, value)) {
+ pCopy->m_Map.insert(
+ std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited)));
+ }
+ }
return pCopy;
}
« 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