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

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: change due to rebase 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
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..0613c0d7819327498a16ad3133e2f1a26339cfc5 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
@@ -44,10 +44,21 @@ 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 CloneDeRef(false);
+}
+
+CPDF_Object* CPDF_Dictionary::CloneWithCheck(
+ 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) {
+ auto value = it.second;
Lei Zhang 2016/08/18 15:16:44 auto* ?
Wei Li 2016/08/18 22:02:30 Changed to actual type
+ if (!pdfium::ContainsKey(*pVisited, value))
dsinclair 2016/08/18 14:04:31 nit: add {}'s
Wei Li 2016/08/18 22:02:30 Done.
+ pCopy->m_Map.insert(
+ std::make_pair(it.first, value->CloneWithCheck(bDirect, pVisited)));
+ }
return pCopy;
}

Powered by Google App Engine
This is Rietveld 408576698