OLD | NEW |
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 #include "core/include/fpdfapi/fpdf_parser.h" | 7 #include "core/include/fpdfapi/fpdf_parser.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 18 matching lines...) Expand all Loading... |
29 // A limit on the maximum object number in the xref table. Theoretical limits | 29 // A limit on the maximum object number in the xref table. Theoretical limits |
30 // are higher, but this may be large enough in practice. | 30 // are higher, but this may be large enough in practice. |
31 const FX_DWORD kMaxObjectNumber = 1048576; | 31 const FX_DWORD kMaxObjectNumber = 1048576; |
32 | 32 |
33 struct SearchTagRecord { | 33 struct SearchTagRecord { |
34 const char* m_pTag; | 34 const char* m_pTag; |
35 FX_DWORD m_Len; | 35 FX_DWORD m_Len; |
36 FX_DWORD m_Offset; | 36 FX_DWORD m_Offset; |
37 }; | 37 }; |
38 | 38 |
| 39 template <typename T> |
| 40 class ScopedSetInsertion { |
| 41 public: |
| 42 ScopedSetInsertion(std::set<T>* org_set, T elem) |
| 43 : m_Set(org_set), m_Entry(elem) { |
| 44 m_Set->insert(m_Entry); |
| 45 } |
| 46 ~ScopedSetInsertion() { m_Set->erase(m_Entry); } |
| 47 |
| 48 private: |
| 49 std::set<T>* const m_Set; |
| 50 const T m_Entry; |
| 51 }; |
| 52 |
39 int CompareFileSize(const void* p1, const void* p2) { | 53 int CompareFileSize(const void* p1, const void* p2) { |
40 return *(FX_FILESIZE*)p1 - *(FX_FILESIZE*)p2; | 54 return *(FX_FILESIZE*)p1 - *(FX_FILESIZE*)p2; |
41 } | 55 } |
42 | 56 |
43 int32_t GetHeaderOffset(IFX_FileRead* pFile) { | 57 int32_t GetHeaderOffset(IFX_FileRead* pFile) { |
44 const FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025); | 58 const FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025); |
45 const size_t kBufSize = 4; | 59 const size_t kBufSize = 4; |
46 uint8_t buf[kBufSize]; | 60 uint8_t buf[kBufSize]; |
47 int32_t offset = 0; | 61 int32_t offset = 0; |
48 while (offset <= 1024) { | 62 while (offset <= 1024) { |
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 m_Syntax.RestorePos(SavedPos); | 1200 m_Syntax.RestorePos(SavedPos); |
1187 return TRUE; | 1201 return TRUE; |
1188 } | 1202 } |
1189 | 1203 |
1190 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, | 1204 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, |
1191 FX_DWORD objnum, | 1205 FX_DWORD objnum, |
1192 PARSE_CONTEXT* pContext) { | 1206 PARSE_CONTEXT* pContext) { |
1193 if (!IsValidObjectNumber(objnum)) | 1207 if (!IsValidObjectNumber(objnum)) |
1194 return nullptr; | 1208 return nullptr; |
1195 | 1209 |
| 1210 // Prevent circular parsing the same object. |
| 1211 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) |
| 1212 return nullptr; |
| 1213 ScopedSetInsertion<FX_DWORD> local_insert(&m_ParsingObjNums, objnum); |
| 1214 |
1196 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1215 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
1197 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1216 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
1198 if (pos <= 0) | 1217 if (pos <= 0) |
1199 return nullptr; | 1218 return nullptr; |
1200 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); | 1219 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); |
1201 } | 1220 } |
1202 if (m_V5Type[objnum] != 2) | 1221 if (m_V5Type[objnum] != 2) |
1203 return nullptr; | 1222 return nullptr; |
1204 | 1223 |
1205 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); | 1224 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
(...skipping 3766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4972 if (!m_pLinearizedDict) | 4991 if (!m_pLinearizedDict) |
4973 return -1; | 4992 return -1; |
4974 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4993 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4975 if (!pRange) | 4994 if (!pRange) |
4976 return -1; | 4995 return -1; |
4977 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4996 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4978 if (!pStreamLen) | 4997 if (!pStreamLen) |
4979 return -1; | 4998 return -1; |
4980 return pStreamLen->GetInteger(); | 4999 return pStreamLen->GetInteger(); |
4981 } | 5000 } |
OLD | NEW |