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

Side by Side Diff: core/include/fpdfapi/fpdf_objects.h

Issue 1585533002: Fix infinite loops caused by calling circular indirect objects (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ 7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_
8 #define CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ 8 #define CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_
9 9
10 #include <map> 10 #include <map>
(...skipping 27 matching lines...) Expand all
38 #define PDFOBJ_NAME 4 38 #define PDFOBJ_NAME 4
39 #define PDFOBJ_ARRAY 5 39 #define PDFOBJ_ARRAY 5
40 #define PDFOBJ_DICTIONARY 6 40 #define PDFOBJ_DICTIONARY 6
41 #define PDFOBJ_STREAM 7 41 #define PDFOBJ_STREAM 7
42 #define PDFOBJ_NULL 8 42 #define PDFOBJ_NULL 8
43 #define PDFOBJ_REFERENCE 9 43 #define PDFOBJ_REFERENCE 9
44 44
45 class CPDF_Object { 45 class CPDF_Object {
46 public: 46 public:
47 int GetType() const { return m_Type; } 47 int GetType() const { return m_Type; }
48
49 FX_DWORD GetObjNum() const { return m_ObjNum; } 48 FX_DWORD GetObjNum() const { return m_ObjNum; }
50
51 FX_DWORD GetGenNum() const { return m_GenNum; } 49 FX_DWORD GetGenNum() const { return m_GenNum; }
52 50
53 FX_BOOL IsIdentical(CPDF_Object* pObj) const; 51 FX_BOOL IsIdentical(CPDF_Object* pObj) const;
54
55 CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const; 52 CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const;
56
57 CPDF_Object* CloneRef(CPDF_IndirectObjectHolder* pObjs) const; 53 CPDF_Object* CloneRef(CPDF_IndirectObjectHolder* pObjs) const;
58 54
59 CPDF_Object* GetDirect() const; 55 CPDF_Object* GetDirect() const;
56 int GetDirectType() const;
57 FX_BOOL IsModified() const { return FALSE; }
60 58
61 void Release(); 59 void Release();
62 60
63 CFX_ByteString GetString() const; 61 CFX_ByteString GetString() const;
64
65 CFX_ByteStringC GetConstString() const; 62 CFX_ByteStringC GetConstString() const;
66
67 CFX_WideString GetUnicodeText(CFX_CharMap* pCharMap = NULL) const; 63 CFX_WideString GetUnicodeText(CFX_CharMap* pCharMap = NULL) const;
68 FX_FLOAT GetNumber() const; 64 FX_FLOAT GetNumber() const;
69
70 FX_FLOAT GetNumber16() const; 65 FX_FLOAT GetNumber16() const;
71
72 int GetInteger() const; 66 int GetInteger() const;
73
74 CPDF_Dictionary* GetDict() const; 67 CPDF_Dictionary* GetDict() const;
75
76 CPDF_Array* GetArray() const; 68 CPDF_Array* GetArray() const;
77 69
78 void SetString(const CFX_ByteString& str); 70 void SetString(const CFX_ByteString& str);
79
80 void SetUnicodeText(const FX_WCHAR* pUnicodes, int len = -1); 71 void SetUnicodeText(const FX_WCHAR* pUnicodes, int len = -1);
81 72
82 int GetDirectType() const;
83
84 FX_BOOL IsModified() const { return FALSE; }
85
86 bool IsArray() const { return m_Type == PDFOBJ_ARRAY; } 73 bool IsArray() const { return m_Type == PDFOBJ_ARRAY; }
87 bool IsBoolean() const { return m_Type == PDFOBJ_BOOLEAN; } 74 bool IsBoolean() const { return m_Type == PDFOBJ_BOOLEAN; }
88 bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; } 75 bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; }
89 bool IsName() const { return m_Type == PDFOBJ_NAME; } 76 bool IsName() const { return m_Type == PDFOBJ_NAME; }
90 bool IsNumber() const { return m_Type == PDFOBJ_NUMBER; } 77 bool IsNumber() const { return m_Type == PDFOBJ_NUMBER; }
91 bool IsReference() const { return m_Type == PDFOBJ_REFERENCE; } 78 bool IsReference() const { return m_Type == PDFOBJ_REFERENCE; }
92 bool IsStream() const { return m_Type == PDFOBJ_STREAM; } 79 bool IsStream() const { return m_Type == PDFOBJ_STREAM; }
93 bool IsString() const { return m_Type == PDFOBJ_STRING; } 80 bool IsString() const { return m_Type == PDFOBJ_STRING; }
94 81
95 CPDF_Array* AsArray(); 82 CPDF_Array* AsArray();
96 const CPDF_Array* AsArray() const; 83 const CPDF_Array* AsArray() const;
97
98 CPDF_Boolean* AsBoolean(); 84 CPDF_Boolean* AsBoolean();
99 const CPDF_Boolean* AsBoolean() const; 85 const CPDF_Boolean* AsBoolean() const;
100
101 CPDF_Dictionary* AsDictionary(); 86 CPDF_Dictionary* AsDictionary();
102 const CPDF_Dictionary* AsDictionary() const; 87 const CPDF_Dictionary* AsDictionary() const;
103
104 CPDF_Name* AsName(); 88 CPDF_Name* AsName();
105 const CPDF_Name* AsName() const; 89 const CPDF_Name* AsName() const;
106
107 CPDF_Number* AsNumber(); 90 CPDF_Number* AsNumber();
108 const CPDF_Number* AsNumber() const; 91 const CPDF_Number* AsNumber() const;
109
110 CPDF_Reference* AsReference(); 92 CPDF_Reference* AsReference();
111 const CPDF_Reference* AsReference() const; 93 const CPDF_Reference* AsReference() const;
112
113 CPDF_Stream* AsStream(); 94 CPDF_Stream* AsStream();
114 const CPDF_Stream* AsStream() const; 95 const CPDF_Stream* AsStream() const;
115
116 CPDF_String* AsString(); 96 CPDF_String* AsString();
117 const CPDF_String* AsString() const; 97 const CPDF_String* AsString() const;
118 98
119 protected: 99 protected:
120 explicit CPDF_Object(FX_DWORD type) 100 explicit CPDF_Object(FX_DWORD type)
121 : m_Type(type), m_ObjNum(0), m_GenNum(0) {} 101 : m_Type(type), m_ObjNum(0), m_GenNum(0) {}
122 ~CPDF_Object() {} 102 ~CPDF_Object() {}
123 void Destroy(); 103 void Destroy();
124 104
125 static const int kObjectRefMaxDepth = 128; 105 const CPDF_Object* const GetBasicObject() const;
126 static int s_nCurRefDepth; 106
127 FX_DWORD m_Type; 107 FX_DWORD m_Type;
128 FX_DWORD m_ObjNum; 108 FX_DWORD m_ObjNum;
129 FX_DWORD m_GenNum; 109 FX_DWORD m_GenNum;
130 110
131 friend class CPDF_IndirectObjectHolder; 111 friend class CPDF_IndirectObjectHolder;
132 friend class CPDF_Parser; 112 friend class CPDF_Parser;
133 friend class CPDF_SyntaxParser; 113 friend class CPDF_SyntaxParser;
134 114
135 private: 115 private:
136 CPDF_Object(const CPDF_Object& src) {} 116 CPDF_Object(const CPDF_Object& src) {}
137 CPDF_Object* CloneInternal(FX_BOOL bDirect, 117 CPDF_Object* CloneInternal(FX_BOOL bDirect,
138 std::set<FX_DWORD>* visited) const; 118 std::set<FX_DWORD>* visited) const;
139 }; 119 };
140 class CPDF_Boolean : public CPDF_Object { 120 class CPDF_Boolean : public CPDF_Object {
141 public: 121 public:
142 CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) {} 122 CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) {}
143 explicit CPDF_Boolean(FX_BOOL value) 123 explicit CPDF_Boolean(FX_BOOL value)
144 : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) {} 124 : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) {}
145 125
146 FX_BOOL Identical(CPDF_Boolean* pOther) const { 126 FX_BOOL Identical(CPDF_Boolean* pOther) const {
147 return m_bValue == pOther->m_bValue; 127 return m_bValue == pOther->m_bValue;
148 } 128 }
149 129
130 CFX_ByteString GetString() const { return m_bValue ? "true" : "false"; }
131 FX_BOOL GetValue() const { return m_bValue; }
132
150 protected: 133 protected:
151 FX_BOOL m_bValue; 134 FX_BOOL m_bValue;
152 friend class CPDF_Object; 135 friend class CPDF_Object;
153 }; 136 };
154 inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) { 137 inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) {
155 return obj ? obj->AsBoolean() : nullptr; 138 return obj ? obj->AsBoolean() : nullptr;
156 } 139 }
157 inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { 140 inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) {
158 return obj ? obj->AsBoolean() : nullptr; 141 return obj ? obj->AsBoolean() : nullptr;
159 } 142 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 192
210 class CPDF_String : public CPDF_Object { 193 class CPDF_String : public CPDF_Object {
211 public: 194 public:
212 CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) {} 195 CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) {}
213 196
214 CPDF_String(const CFX_ByteString& str, FX_BOOL bHex) 197 CPDF_String(const CFX_ByteString& str, FX_BOOL bHex)
215 : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) {} 198 : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) {}
216 199
217 explicit CPDF_String(const CFX_WideString& str); 200 explicit CPDF_String(const CFX_WideString& str);
218 201
219 CFX_ByteString& GetString() { return m_String; } 202 CFX_ByteString GetString() const { return m_String; }
220 203
221 FX_BOOL Identical(CPDF_String* pOther) const { 204 FX_BOOL Identical(CPDF_String* pOther) const {
222 return m_String == pOther->m_String; 205 return m_String == pOther->m_String;
223 } 206 }
224 207
225 FX_BOOL IsHex() const { return m_bHex; } 208 FX_BOOL IsHex() const { return m_bHex; }
226 209
227 protected: 210 protected:
228 CFX_ByteString m_String; 211 CFX_ByteString m_String;
229 212
230 FX_BOOL m_bHex; 213 FX_BOOL m_bHex;
231 friend class CPDF_Object; 214 friend class CPDF_Object;
232 }; 215 };
233 inline CPDF_String* ToString(CPDF_Object* obj) { 216 inline CPDF_String* ToString(CPDF_Object* obj) {
234 return obj ? obj->AsString() : nullptr; 217 return obj ? obj->AsString() : nullptr;
235 } 218 }
236 inline const CPDF_String* ToString(const CPDF_Object* obj) { 219 inline const CPDF_String* ToString(const CPDF_Object* obj) {
237 return obj ? obj->AsString() : nullptr; 220 return obj ? obj->AsString() : nullptr;
238 } 221 }
239 222
240 class CPDF_Name : public CPDF_Object { 223 class CPDF_Name : public CPDF_Object {
241 public: 224 public:
242 explicit CPDF_Name(const CFX_ByteString& str) 225 explicit CPDF_Name(const CFX_ByteString& str)
243 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} 226 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {}
244 explicit CPDF_Name(const CFX_ByteStringC& str) 227 explicit CPDF_Name(const CFX_ByteStringC& str)
245 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} 228 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {}
246 explicit CPDF_Name(const FX_CHAR* str) 229 explicit CPDF_Name(const FX_CHAR* str)
247 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} 230 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {}
248 231
249 CFX_ByteString& GetString() { return m_Name; } 232 CFX_ByteString GetString() const { return m_Name; }
250 233
251 FX_BOOL Identical(CPDF_Name* pOther) const { 234 FX_BOOL Identical(CPDF_Name* pOther) const {
252 return m_Name == pOther->m_Name; 235 return m_Name == pOther->m_Name;
253 } 236 }
254 237
255 protected: 238 protected:
256 CFX_ByteString m_Name; 239 CFX_ByteString m_Name;
257 friend class CPDF_Object; 240 friend class CPDF_Object;
258 }; 241 };
259 inline CPDF_Name* ToName(CPDF_Object* obj) { 242 inline CPDF_Name* ToName(CPDF_Object* obj) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 iterator end() { return m_IndirectObjs.end(); } 579 iterator end() { return m_IndirectObjs.end(); }
597 const_iterator end() const { return m_IndirectObjs.end(); } 580 const_iterator end() const { return m_IndirectObjs.end(); }
598 581
599 protected: 582 protected:
600 CPDF_Parser* m_pParser; 583 CPDF_Parser* m_pParser;
601 FX_DWORD m_LastObjNum; 584 FX_DWORD m_LastObjNum;
602 std::map<FX_DWORD, CPDF_Object*> m_IndirectObjs; 585 std::map<FX_DWORD, CPDF_Object*> m_IndirectObjs;
603 }; 586 };
604 587
605 #endif // CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ 588 #endif // CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698