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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_parser/cpdf_reference.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_reference.cpp b/core/fpdfapi/fpdf_parser/cpdf_reference.cpp
index afda50c3248f0b7a92ac1ed4a00f27302bb85412..4e7b3786d3986634e46144831274a0fe059da3bc 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_reference.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_reference.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
+#include "third_party/base/stl_util.h"
CPDF_Reference::CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum)
: m_pObjList(pDoc), m_RefObjNum(objnum) {}
@@ -49,10 +50,19 @@ const CPDF_Reference* CPDF_Reference::AsReference() const {
return this;
}
-CPDF_Object* CPDF_Reference::Clone(FX_BOOL bDirect) const {
+CPDF_Object* CPDF_Reference::Clone() const {
+ return CloneObjectNonCyclic(false);
+}
+
+CPDF_Object* CPDF_Reference::CloneNonCyclic(
+ bool bDirect,
+ std::set<const CPDF_Object*>* pVisited) const {
+ pVisited->insert(this);
if (bDirect) {
auto* pDirect = GetDirect();
- return pDirect ? pDirect->Clone(TRUE) : nullptr;
+ return pDirect && !pdfium::ContainsKey(*pVisited, pDirect)
+ ? pDirect->CloneNonCyclic(true, pVisited)
+ : nullptr;
}
return new CPDF_Reference(m_pObjList, m_RefObjNum);
}
« 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