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

Unified Diff: core/fpdfapi/fpdf_parser/cpdf_array.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_page/cpdf_image.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_array_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_parser/cpdf_array.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp
index a047b3af7ba20cc4984179acdaaaec29807b6d9b..83f99c215bc0547095ad380e26bfaab8838922b9 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp
@@ -11,10 +11,14 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
+#include "third_party/base/stl_util.h"
CPDF_Array::CPDF_Array() {}
CPDF_Array::~CPDF_Array() {
+ // Mark the object as deleted so that it will not be deleted again
+ // in case of cyclic references.
+ m_ObjNum = kInvalidObjNum;
for (auto& it : m_Objects) {
if (it)
it->Release();
@@ -37,11 +41,19 @@ const CPDF_Array* CPDF_Array::AsArray() const {
return this;
}
-CPDF_Object* CPDF_Array::Clone(FX_BOOL bDirect) const {
+CPDF_Object* CPDF_Array::Clone() const {
+ return CloneObjectNonCyclic(false);
+}
+
+CPDF_Object* CPDF_Array::CloneNonCyclic(
+ bool bDirect,
+ std::set<const CPDF_Object*>* pVisited) const {
+ pVisited->insert(this);
CPDF_Array* pCopy = new CPDF_Array();
for (size_t i = 0; i < GetCount(); i++) {
CPDF_Object* value = m_Objects.at(i);
- pCopy->m_Objects.push_back(value->Clone(bDirect));
+ if (!pdfium::ContainsKey(*pVisited, value))
+ pCopy->m_Objects.push_back(value->CloneNonCyclic(bDirect, pVisited));
}
return pCopy;
}
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_image.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_array_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698