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

Unified Diff: core/fpdfapi/fpdf_parser/include/cpdf_object.h

Issue 2250533002: Fix stack overflow in object Clone() functions (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments 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/include/cpdf_object.h
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_object.h b/core/fpdfapi/fpdf_parser/include/cpdf_object.h
index 86f3879ce1fffa3243c01cf6c59f04512d72c198..ee280aee46b84ba9aaea00dcc68a0cd82487146e 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_object.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_object.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_
#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_
+#include <set>
+
#include "core/fxcrt/include/fx_string.h"
#include "core/fxcrt/include/fx_system.h"
@@ -39,7 +41,11 @@ class CPDF_Object {
uint32_t GetObjNum() const { return m_ObjNum; }
uint32_t GetGenNum() const { return m_GenNum; }
- virtual CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const = 0;
+ // Create a deep copy of the object.
+ virtual CPDF_Object* Clone() const = 0;
+ // Create a deep copy of the object except any reference object be
+ // copied to the object it points to directly.
+ virtual CPDF_Object* CloneDirectObject() const;
virtual CPDF_Object* GetDirect() const;
void Release();
@@ -82,11 +88,27 @@ class CPDF_Object {
friend class CPDF_Document;
friend class CPDF_IndirectObjectHolder;
friend class CPDF_Parser;
+ friend class CPDF_Array;
Lei Zhang 2016/08/19 16:21:09 put friends in alphabetical order
Wei Li 2016/08/19 18:14:57 Done.
+ friend class CPDF_Dictionary;
+ friend class CPDF_Reference;
+ friend class CPDF_Stream;
CPDF_Object() : m_ObjNum(0), m_GenNum(0) {}
virtual ~CPDF_Object();
void Destroy() { delete this; }
+ CPDF_Object* CloneObjectNonCyclic(bool bDirect) const;
+
+ // Create a deep copy of the object with the option to either
+ // copy a reference object or directly copy the object it refers to
+ // when |bDirect| is true.
+ // Also check cyclic reference against |pVisited|, no copy if it is found.
+ // Complex objects should implement their own CloneNonCyclic()
+ // function to properly check for possible loop.
+ virtual CPDF_Object* CloneNonCyclic(
+ bool bDirect,
+ std::set<const CPDF_Object*>* pVisited) const;
+
uint32_t m_ObjNum;
uint32_t m_GenNum;

Powered by Google App Engine
This is Rietveld 408576698