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); |
} |