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 "parser_int.h" | 7 #include "parser_int.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 dwRet = SetEncryptHandler(); | 240 dwRet = SetEncryptHandler(); |
241 if (dwRet != PDFPARSE_ERROR_SUCCESS) | 241 if (dwRet != PDFPARSE_ERROR_SUCCESS) |
242 return dwRet; | 242 return dwRet; |
243 | 243 |
244 m_pDocument->LoadDoc(); | 244 m_pDocument->LoadDoc(); |
245 if (!m_pDocument->GetRoot()) | 245 if (!m_pDocument->GetRoot()) |
246 return PDFPARSE_ERROR_FORMAT; | 246 return PDFPARSE_ERROR_FORMAT; |
247 } | 247 } |
248 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 248 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
249 sizeof(FX_FILESIZE), CompareFileSize); | 249 sizeof(FX_FILESIZE), CompareFileSize); |
250 FX_DWORD RootObjNum = GetRootObjNum(); | 250 if (GetRootObjNum() == 0) { |
251 if (RootObjNum == 0) { | |
252 ReleaseEncryptHandler(); | 251 ReleaseEncryptHandler(); |
253 RebuildCrossRef(); | 252 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
254 RootObjNum = GetRootObjNum(); | |
255 if (RootObjNum == 0) | |
256 return PDFPARSE_ERROR_FORMAT; | 253 return PDFPARSE_ERROR_FORMAT; |
257 | 254 |
258 dwRet = SetEncryptHandler(); | 255 dwRet = SetEncryptHandler(); |
259 if (dwRet != PDFPARSE_ERROR_SUCCESS) | 256 if (dwRet != PDFPARSE_ERROR_SUCCESS) |
260 return dwRet; | 257 return dwRet; |
261 } | 258 } |
262 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { | 259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { |
263 CPDF_Reference* pMetadata = | 260 CPDF_Reference* pMetadata = |
264 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); | 261 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); |
265 if (pMetadata) | 262 if (pMetadata) |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 last_trailer = m_Syntax.m_FileLen; | 965 last_trailer = m_Syntax.m_FileLen; |
969 } | 966 } |
970 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; | 967 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; |
971 void* pResult = | 968 void* pResult = |
972 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 969 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
973 sizeof(FX_FILESIZE), CompareFileSize); | 970 sizeof(FX_FILESIZE), CompareFileSize); |
974 if (pResult == NULL) { | 971 if (pResult == NULL) { |
975 m_SortedOffset.Add(offset); | 972 m_SortedOffset.Add(offset); |
976 } | 973 } |
977 FX_Free(buffer); | 974 FX_Free(buffer); |
978 return TRUE; | 975 return m_pTrailer && m_CrossRef.GetSize() > 0; |
979 } | 976 } |
980 | 977 |
981 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, | 978 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, |
982 FX_FILESIZE& prev, | 979 FX_FILESIZE& prev, |
983 FX_BOOL bMainXRef) { | 980 FX_BOOL bMainXRef) { |
984 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr); | 981 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr); |
985 if (!pObject) | 982 if (!pObject) |
986 return FALSE; | 983 return FALSE; |
987 | 984 |
988 if (m_pDocument) { | 985 if (m_pDocument) { |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1598 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
1602 return dwRet; | 1599 return dwRet; |
1603 } | 1600 } |
1604 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); | 1601 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); |
1605 if (m_pDocument->GetRoot() == NULL) { | 1602 if (m_pDocument->GetRoot() == NULL) { |
1606 return PDFPARSE_ERROR_FORMAT; | 1603 return PDFPARSE_ERROR_FORMAT; |
1607 } | 1604 } |
1608 } | 1605 } |
1609 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1606 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
1610 sizeof(FX_FILESIZE), CompareFileSize); | 1607 sizeof(FX_FILESIZE), CompareFileSize); |
1611 FX_DWORD RootObjNum = GetRootObjNum(); | 1608 if (GetRootObjNum() == 0) { |
1612 if (RootObjNum == 0) { | |
1613 ReleaseEncryptHandler(); | 1609 ReleaseEncryptHandler(); |
1614 RebuildCrossRef(); | 1610 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
1615 RootObjNum = GetRootObjNum(); | |
1616 if (RootObjNum == 0) { | |
1617 return PDFPARSE_ERROR_FORMAT; | 1611 return PDFPARSE_ERROR_FORMAT; |
1618 } | 1612 |
1619 dwRet = SetEncryptHandler(); | 1613 dwRet = SetEncryptHandler(); |
1620 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1614 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
1621 return dwRet; | 1615 return dwRet; |
1622 } | 1616 } |
1623 } | 1617 } |
1624 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { | 1618 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { |
1625 if (CPDF_Reference* pMetadata = ToReference( | 1619 if (CPDF_Reference* pMetadata = ToReference( |
1626 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")))) | 1620 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")))) |
1627 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); | 1621 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
1628 } | 1622 } |
(...skipping 3318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4947 if (!m_pLinearizedDict) | 4941 if (!m_pLinearizedDict) |
4948 return -1; | 4942 return -1; |
4949 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); | 4943 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); |
4950 if (!pRange) | 4944 if (!pRange) |
4951 return -1; | 4945 return -1; |
4952 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4946 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4953 if (!pStreamLen) | 4947 if (!pStreamLen) |
4954 return -1; | 4948 return -1; |
4955 return pStreamLen->GetInteger(); | 4949 return pStreamLen->GetInteger(); |
4956 } | 4950 } |
OLD | NEW |