| 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 <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if (RootObjNum == 0) { | 251 if (RootObjNum == 0) { |
| 252 return PDFPARSE_ERROR_FORMAT; | 252 return PDFPARSE_ERROR_FORMAT; |
| 253 } | 253 } |
| 254 dwRet = SetEncryptHandler(); | 254 dwRet = SetEncryptHandler(); |
| 255 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 255 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
| 256 return dwRet; | 256 return dwRet; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { | 259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { |
| 260 CPDF_Reference* pMetadata = | 260 CPDF_Reference* pMetadata = |
| 261 (CPDF_Reference*)m_pDocument->GetRoot()->GetElement( | 261 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); |
| 262 FX_BSTRC("Metadata")); | 262 if (pMetadata) |
| 263 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { | |
| 264 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); | 263 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| 265 } | |
| 266 } | 264 } |
| 267 return PDFPARSE_ERROR_SUCCESS; | 265 return PDFPARSE_ERROR_SUCCESS; |
| 268 } | 266 } |
| 269 FX_DWORD CPDF_Parser::SetEncryptHandler() { | 267 FX_DWORD CPDF_Parser::SetEncryptHandler() { |
| 270 ReleaseEncryptHandler(); | 268 ReleaseEncryptHandler(); |
| 271 SetEncryptDictionary(NULL); | 269 SetEncryptDictionary(NULL); |
| 272 if (m_pTrailer == NULL) { | 270 if (m_pTrailer == NULL) { |
| 273 return PDFPARSE_ERROR_FORMAT; | 271 return PDFPARSE_ERROR_FORMAT; |
| 274 } | 272 } |
| 275 CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt")); | 273 CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt")); |
| 276 if (pEncryptObj) { | 274 if (pEncryptObj) { |
| 277 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { | 275 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
| 278 SetEncryptDictionary(pEncryptDict); | 276 SetEncryptDictionary(pEncryptDict); |
| 279 } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) { | 277 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
| 280 pEncryptObj = m_pDocument->GetIndirectObject( | 278 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
| 281 ((CPDF_Reference*)pEncryptObj)->GetRefObjNum()); | 279 if (pEncryptObj) |
| 282 if (pEncryptObj) { | |
| 283 SetEncryptDictionary(pEncryptObj->GetDict()); | 280 SetEncryptDictionary(pEncryptObj->GetDict()); |
| 284 } | |
| 285 } | 281 } |
| 286 } | 282 } |
| 287 if (m_bForceUseSecurityHandler) { | 283 if (m_bForceUseSecurityHandler) { |
| 288 FX_DWORD err = PDFPARSE_ERROR_HANDLER; | 284 FX_DWORD err = PDFPARSE_ERROR_HANDLER; |
| 289 if (!m_pSecurityHandler) { | 285 if (!m_pSecurityHandler) { |
| 290 return PDFPARSE_ERROR_HANDLER; | 286 return PDFPARSE_ERROR_HANDLER; |
| 291 } | 287 } |
| 292 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { | 288 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { |
| 293 return err; | 289 return err; |
| 294 } | 290 } |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 if (pObj) { | 829 if (pObj) { |
| 834 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 830 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
| 835 pObj->Release(); | 831 pObj->Release(); |
| 836 } else { | 832 } else { |
| 837 CPDF_Stream* pStream = pObj->AsStream(); | 833 CPDF_Stream* pStream = pObj->AsStream(); |
| 838 if (CPDF_Dictionary* pTrailer = | 834 if (CPDF_Dictionary* pTrailer = |
| 839 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 835 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
| 840 if (m_pTrailer) { | 836 if (m_pTrailer) { |
| 841 CPDF_Object* pRoot = | 837 CPDF_Object* pRoot = |
| 842 pTrailer->GetElement(FX_BSTRC("Root")); | 838 pTrailer->GetElement(FX_BSTRC("Root")); |
| 843 if (pRoot == NULL || | 839 CPDF_Reference* pRef = ToReference(pRoot); |
| 844 (pRoot->GetType() == PDFOBJ_REFERENCE && | 840 if (!pRoot || |
| 841 (pRef && |
| 845 (FX_DWORD)m_CrossRef.GetSize() > | 842 (FX_DWORD)m_CrossRef.GetSize() > |
| 846 ((CPDF_Reference*)pRoot)->GetRefObjNum() && | 843 pRef->GetRefObjNum() && |
| 847 m_CrossRef.GetAt(((CPDF_Reference*)pRoot) | 844 m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) { |
| 848 ->GetRefObjNum()) != 0)) { | |
| 849 FX_POSITION pos = pTrailer->GetStartPos(); | 845 FX_POSITION pos = pTrailer->GetStartPos(); |
| 850 while (pos) { | 846 while (pos) { |
| 851 CFX_ByteString key; | 847 CFX_ByteString key; |
| 852 CPDF_Object* pObj = | 848 CPDF_Object* pObj = |
| 853 pTrailer->GetNextElement(pos, key); | 849 pTrailer->GetNextElement(pos, key); |
| 854 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); | 850 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); |
| 855 } | 851 } |
| 856 pObj->Release(); | 852 pObj->Release(); |
| 857 } else { | 853 } else { |
| 858 pObj->Release(); | 854 pObj->Release(); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 segindex += count; | 1118 segindex += count; |
| 1123 } | 1119 } |
| 1124 pStream->Release(); | 1120 pStream->Release(); |
| 1125 return TRUE; | 1121 return TRUE; |
| 1126 } | 1122 } |
| 1127 CPDF_Array* CPDF_Parser::GetIDArray() { | 1123 CPDF_Array* CPDF_Parser::GetIDArray() { |
| 1128 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL; | 1124 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL; |
| 1129 if (!pID) | 1125 if (!pID) |
| 1130 return nullptr; | 1126 return nullptr; |
| 1131 | 1127 |
| 1132 if (pID->GetType() == PDFOBJ_REFERENCE) { | 1128 if (CPDF_Reference* pRef = pID->AsReference()) { |
| 1133 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); | 1129 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); |
| 1134 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); | 1130 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); |
| 1135 } | 1131 } |
| 1136 return ToArray(pID); | 1132 return ToArray(pID); |
| 1137 } | 1133 } |
| 1138 FX_DWORD CPDF_Parser::GetRootObjNum() { | 1134 FX_DWORD CPDF_Parser::GetRootObjNum() { |
| 1139 CPDF_Object* pRef = | 1135 CPDF_Reference* pRef = ToReference( |
| 1140 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL; | 1136 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : nullptr); |
| 1141 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 1137 return pRef ? pRef->GetRefObjNum() : 0; |
| 1142 return 0; | |
| 1143 } | |
| 1144 return ((CPDF_Reference*)pRef)->GetRefObjNum(); | |
| 1145 } | 1138 } |
| 1146 FX_DWORD CPDF_Parser::GetInfoObjNum() { | 1139 FX_DWORD CPDF_Parser::GetInfoObjNum() { |
| 1147 CPDF_Object* pRef = | 1140 CPDF_Reference* pRef = ToReference( |
| 1148 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL; | 1141 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : nullptr); |
| 1149 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 1142 return pRef ? pRef->GetRefObjNum() : 0; |
| 1150 return 0; | |
| 1151 } | |
| 1152 return ((CPDF_Reference*)pRef)->GetRefObjNum(); | |
| 1153 } | 1143 } |
| 1154 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { | 1144 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { |
| 1155 bForm = FALSE; | 1145 bForm = FALSE; |
| 1156 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1146 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { |
| 1157 return TRUE; | 1147 return TRUE; |
| 1158 } | 1148 } |
| 1159 if (m_V5Type[objnum] == 0) { | 1149 if (m_V5Type[objnum] == 0) { |
| 1160 return TRUE; | 1150 return TRUE; |
| 1161 } | 1151 } |
| 1162 if (m_V5Type[objnum] == 2) { | 1152 if (m_V5Type[objnum] == 2) { |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 RootObjNum = GetRootObjNum(); | 1600 RootObjNum = GetRootObjNum(); |
| 1611 if (RootObjNum == 0) { | 1601 if (RootObjNum == 0) { |
| 1612 return PDFPARSE_ERROR_FORMAT; | 1602 return PDFPARSE_ERROR_FORMAT; |
| 1613 } | 1603 } |
| 1614 dwRet = SetEncryptHandler(); | 1604 dwRet = SetEncryptHandler(); |
| 1615 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1605 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
| 1616 return dwRet; | 1606 return dwRet; |
| 1617 } | 1607 } |
| 1618 } | 1608 } |
| 1619 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { | 1609 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { |
| 1620 CPDF_Object* pMetadata = | 1610 if (CPDF_Reference* pMetadata = ToReference( |
| 1621 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")); | 1611 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")))) |
| 1622 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { | 1612 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| 1623 m_Syntax.m_MetadataObjnum = ((CPDF_Reference*)pMetadata)->GetRefObjNum(); | |
| 1624 } | |
| 1625 } | 1613 } |
| 1626 return PDFPARSE_ERROR_SUCCESS; | 1614 return PDFPARSE_ERROR_SUCCESS; |
| 1627 } | 1615 } |
| 1628 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { | 1616 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { |
| 1629 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { | 1617 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { |
| 1630 return FALSE; | 1618 return FALSE; |
| 1631 } | 1619 } |
| 1632 while (xrefpos) | 1620 while (xrefpos) |
| 1633 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { | 1621 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { |
| 1634 return FALSE; | 1622 return FALSE; |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2367 markers = 1; | 2355 markers = 1; |
| 2368 } | 2356 } |
| 2369 return markers; | 2357 return markers; |
| 2370 } | 2358 } |
| 2371 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, | 2359 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, |
| 2372 PARSE_CONTEXT* pContext, | 2360 PARSE_CONTEXT* pContext, |
| 2373 FX_DWORD objnum, | 2361 FX_DWORD objnum, |
| 2374 FX_DWORD gennum) { | 2362 FX_DWORD gennum) { |
| 2375 CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length")); | 2363 CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length")); |
| 2376 FX_FILESIZE len = -1; | 2364 FX_FILESIZE len = -1; |
| 2377 if (pLenObj && ((pLenObj->GetType() != PDFOBJ_REFERENCE) || | 2365 CPDF_Reference* pLenObjRef = ToReference(pLenObj); |
| 2378 ((((CPDF_Reference*)pLenObj)->GetObjList()) && | 2366 |
| 2379 ((CPDF_Reference*)pLenObj)->GetRefObjNum() != objnum))) { | 2367 bool differingObjNum = !pLenObjRef || (pLenObjRef->GetObjList() && |
| 2368 pLenObjRef->GetRefObjNum() != objnum); |
| 2369 if (pLenObj && differingObjNum) |
| 2380 len = pLenObj->GetInteger(); | 2370 len = pLenObj->GetInteger(); |
| 2381 } | 2371 |
| 2382 // Locate the start of stream. | 2372 // Locate the start of stream. |
| 2383 ToNextLine(); | 2373 ToNextLine(); |
| 2384 FX_FILESIZE streamStartPos = m_Pos; | 2374 FX_FILESIZE streamStartPos = m_Pos; |
| 2385 if (pContext) { | 2375 if (pContext) { |
| 2386 pContext->m_DataStart = streamStartPos; | 2376 pContext->m_DataStart = streamStartPos; |
| 2387 } | 2377 } |
| 2388 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1; | 2378 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1; |
| 2389 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1; | 2379 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1; |
| 2390 CPDF_CryptoHandler* pCryptoHandler = | 2380 CPDF_CryptoHandler* pCryptoHandler = |
| 2391 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get(); | 2381 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get(); |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3057 while (pos) { | 3047 while (pos) { |
| 3058 CPDF_Object* value; | 3048 CPDF_Object* value; |
| 3059 CFX_ByteString key; | 3049 CFX_ByteString key; |
| 3060 value = pDict->GetNextElement(pos, key); | 3050 value = pDict->GetNextElement(pos, key); |
| 3061 if (key != "Parent") { | 3051 if (key != "Parent") { |
| 3062 new_obj_array.Add(value); | 3052 new_obj_array.Add(value); |
| 3063 } | 3053 } |
| 3064 } | 3054 } |
| 3065 } break; | 3055 } break; |
| 3066 case PDFOBJ_REFERENCE: { | 3056 case PDFOBJ_REFERENCE: { |
| 3067 CPDF_Reference* pRef = (CPDF_Reference*)pObj; | 3057 CPDF_Reference* pRef = pObj->AsReference(); |
| 3068 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3058 FX_DWORD dwNum = pRef->GetRefObjNum(); |
| 3069 FX_FILESIZE offset; | 3059 FX_FILESIZE offset; |
| 3070 FX_DWORD original_size = GetObjectSize(dwNum, offset); | 3060 FX_DWORD original_size = GetObjectSize(dwNum, offset); |
| 3071 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; | 3061 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; |
| 3072 if (size.ValueOrDefault(0) == 0 || offset < 0 || | 3062 if (size.ValueOrDefault(0) == 0 || offset < 0 || |
| 3073 offset >= m_dwFileLen) { | 3063 offset >= m_dwFileLen) { |
| 3074 break; | 3064 break; |
| 3075 } | 3065 } |
| 3076 | 3066 |
| 3077 size += offset; | 3067 size += offset; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3099 new_obj_array.Add(pReferred); | 3089 new_obj_array.Add(pReferred); |
| 3100 } | 3090 } |
| 3101 } | 3091 } |
| 3102 } break; | 3092 } break; |
| 3103 } | 3093 } |
| 3104 } | 3094 } |
| 3105 if (count > 0) { | 3095 if (count > 0) { |
| 3106 int32_t iSize = new_obj_array.GetSize(); | 3096 int32_t iSize = new_obj_array.GetSize(); |
| 3107 for (i = 0; i < iSize; ++i) { | 3097 for (i = 0; i < iSize; ++i) { |
| 3108 CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i]; | 3098 CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i]; |
| 3109 int32_t type = pObj->GetType(); | 3099 if (CPDF_Reference* pRef = pObj->AsReference()) { |
| 3110 if (type == PDFOBJ_REFERENCE) { | |
| 3111 CPDF_Reference* pRef = (CPDF_Reference*)pObj; | |
| 3112 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3100 FX_DWORD dwNum = pRef->GetRefObjNum(); |
| 3113 if (!m_objnum_array.Find(dwNum)) { | 3101 if (!m_objnum_array.Find(dwNum)) |
| 3114 ret_array.Add(pObj); | 3102 ret_array.Add(pObj); |
| 3115 } | |
| 3116 } else { | 3103 } else { |
| 3117 ret_array.Add(pObj); | 3104 ret_array.Add(pObj); |
| 3118 } | 3105 } |
| 3119 } | 3106 } |
| 3120 return FALSE; | 3107 return FALSE; |
| 3121 } | 3108 } |
| 3122 obj_array.RemoveAll(); | 3109 obj_array.RemoveAll(); |
| 3123 obj_array.Append(new_obj_array); | 3110 obj_array.Append(new_obj_array); |
| 3124 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 3111 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); |
| 3125 } | 3112 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3373 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3360 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 3374 return TRUE; | 3361 return TRUE; |
| 3375 } | 3362 } |
| 3376 return FALSE; | 3363 return FALSE; |
| 3377 } | 3364 } |
| 3378 CPDF_Dictionary* pDict = m_pRoot->GetDict(); | 3365 CPDF_Dictionary* pDict = m_pRoot->GetDict(); |
| 3379 if (!pDict) { | 3366 if (!pDict) { |
| 3380 m_docStatus = PDF_DATAAVAIL_ERROR; | 3367 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3381 return FALSE; | 3368 return FALSE; |
| 3382 } | 3369 } |
| 3383 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages")); | 3370 CPDF_Reference* pRef = ToReference(pDict->GetElement(FX_BSTRC("Pages"))); |
| 3384 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3371 if (!pRef) { |
| 3385 m_docStatus = PDF_DATAAVAIL_ERROR; | 3372 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3386 return FALSE; | 3373 return FALSE; |
| 3387 } | 3374 } |
| 3375 |
| 3388 m_PagesObjNum = pRef->GetRefObjNum(); | 3376 m_PagesObjNum = pRef->GetRefObjNum(); |
| 3389 CPDF_Reference* pAcroFormRef = | 3377 CPDF_Reference* pAcroFormRef = |
| 3390 (CPDF_Reference*)m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm")); | 3378 ToReference(m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm"))); |
| 3391 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { | 3379 if (pAcroFormRef) { |
| 3392 m_bHaveAcroForm = TRUE; | 3380 m_bHaveAcroForm = TRUE; |
| 3393 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); | 3381 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); |
| 3394 } | 3382 } |
| 3383 |
| 3395 if (m_dwInfoObjNum) { | 3384 if (m_dwInfoObjNum) { |
| 3396 m_docStatus = PDF_DATAAVAIL_INFO; | 3385 m_docStatus = PDF_DATAAVAIL_INFO; |
| 3397 } else { | 3386 } else { |
| 3398 if (m_bHaveAcroForm) { | 3387 m_docStatus = |
| 3399 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3388 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; |
| 3400 } else { | |
| 3401 m_docStatus = PDF_DATAAVAIL_PAGETREE; | |
| 3402 } | |
| 3403 } | 3389 } |
| 3404 return TRUE; | 3390 return TRUE; |
| 3405 } | 3391 } |
| 3406 FX_BOOL CPDF_DataAvail::PreparePageItem() { | 3392 FX_BOOL CPDF_DataAvail::PreparePageItem() { |
| 3407 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 3393 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 3408 CPDF_Reference* pRef = | 3394 CPDF_Reference* pRef = |
| 3409 pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL; | 3395 ToReference(pRoot ? pRoot->GetElement(FX_BSTRC("Pages")) : nullptr); |
| 3410 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3396 if (!pRef) { |
| 3411 m_docStatus = PDF_DATAAVAIL_ERROR; | 3397 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3412 return FALSE; | 3398 return FALSE; |
| 3413 } | 3399 } |
| 3400 |
| 3414 m_PagesObjNum = pRef->GetRefObjNum(); | 3401 m_PagesObjNum = pRef->GetRefObjNum(); |
| 3415 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); | 3402 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); |
| 3416 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3403 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
| 3417 return TRUE; | 3404 return TRUE; |
| 3418 } | 3405 } |
| 3419 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { | 3406 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { |
| 3420 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) | 3407 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) |
| 3421 return FALSE; | 3408 return FALSE; |
| 3422 | 3409 |
| 3423 m_pageMapCheckState.insert(iPage); | 3410 m_pageMapCheckState.insert(iPage); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3436 if (!pObj) { | 3423 if (!pObj) { |
| 3437 if (bExist) { | 3424 if (bExist) { |
| 3438 UnavailObjList.Add(dwPageObjNum); | 3425 UnavailObjList.Add(dwPageObjNum); |
| 3439 } | 3426 } |
| 3440 continue; | 3427 continue; |
| 3441 } | 3428 } |
| 3442 if (pObj->IsArray()) { | 3429 if (pObj->IsArray()) { |
| 3443 CPDF_Array* pArray = pObj->GetArray(); | 3430 CPDF_Array* pArray = pObj->GetArray(); |
| 3444 if (pArray) { | 3431 if (pArray) { |
| 3445 int32_t iSize = pArray->GetCount(); | 3432 int32_t iSize = pArray->GetCount(); |
| 3446 CPDF_Object* pItem = NULL; | |
| 3447 for (int32_t j = 0; j < iSize; ++j) { | 3433 for (int32_t j = 0; j < iSize; ++j) { |
| 3448 pItem = pArray->GetElement(j); | 3434 if (CPDF_Reference* pRef = ToReference(pArray->GetElement(j))) |
| 3449 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { | 3435 UnavailObjList.Add(pRef->GetRefObjNum()); |
| 3450 UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum()); | |
| 3451 } | |
| 3452 } | 3436 } |
| 3453 } | 3437 } |
| 3454 } | 3438 } |
| 3455 if (!pObj->IsDictionary()) { | 3439 if (!pObj->IsDictionary()) { |
| 3456 pObj->Release(); | 3440 pObj->Release(); |
| 3457 continue; | 3441 continue; |
| 3458 } | 3442 } |
| 3459 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); | 3443 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); |
| 3460 if (type == FX_BSTRC("Pages")) { | 3444 if (type == FX_BSTRC("Pages")) { |
| 3461 m_PagesArray.Add(pObj); | 3445 m_PagesArray.Add(pObj); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3496 if (!pParser) { | 3480 if (!pParser) { |
| 3497 m_docStatus = PDF_DATAAVAIL_ERROR; | 3481 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3498 return FALSE; | 3482 return FALSE; |
| 3499 } | 3483 } |
| 3500 CPDF_Dictionary* pDict = pPages->GetDict(); | 3484 CPDF_Dictionary* pDict = pPages->GetDict(); |
| 3501 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; | 3485 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; |
| 3502 if (!pKids) { | 3486 if (!pKids) { |
| 3503 return TRUE; | 3487 return TRUE; |
| 3504 } | 3488 } |
| 3505 switch (pKids->GetType()) { | 3489 switch (pKids->GetType()) { |
| 3506 case PDFOBJ_REFERENCE: { | 3490 case PDFOBJ_REFERENCE: |
| 3507 CPDF_Reference* pKid = (CPDF_Reference*)pKids; | 3491 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); |
| 3508 m_PageObjList.Add(pKid->GetRefObjNum()); | 3492 break; |
| 3509 } break; | |
| 3510 case PDFOBJ_ARRAY: { | 3493 case PDFOBJ_ARRAY: { |
| 3511 CPDF_Array* pKidsArray = pKids->AsArray(); | 3494 CPDF_Array* pKidsArray = pKids->AsArray(); |
| 3512 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 3495 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
| 3513 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); | 3496 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i))) |
| 3514 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { | 3497 m_PageObjList.Add(pRef->GetRefObjNum()); |
| 3515 m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum()); | |
| 3516 } | |
| 3517 } | 3498 } |
| 3518 } break; | 3499 } break; |
| 3519 default: | 3500 default: |
| 3520 m_docStatus = PDF_DATAAVAIL_ERROR; | 3501 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3521 return FALSE; | 3502 return FALSE; |
| 3522 } | 3503 } |
| 3523 return TRUE; | 3504 return TRUE; |
| 3524 } | 3505 } |
| 3525 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) { | 3506 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) { |
| 3526 FX_BOOL bExist = FALSE; | 3507 FX_BOOL bExist = FALSE; |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4005 if (!pTrailer) { | 3986 if (!pTrailer) { |
| 4006 m_Pos += m_syntaxParser.SavePos(); | 3987 m_Pos += m_syntaxParser.SavePos(); |
| 4007 pHints->AddSegment(m_Pos, iTrailerSize); | 3988 pHints->AddSegment(m_Pos, iTrailerSize); |
| 4008 return FALSE; | 3989 return FALSE; |
| 4009 } | 3990 } |
| 4010 if (!pTrailer->IsDictionary()) | 3991 if (!pTrailer->IsDictionary()) |
| 4011 return FALSE; | 3992 return FALSE; |
| 4012 | 3993 |
| 4013 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); | 3994 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); |
| 4014 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); | 3995 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); |
| 4015 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { | 3996 if (ToReference(pEncrypt)) { |
| 4016 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3997 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 4017 return TRUE; | 3998 return TRUE; |
| 4018 } | 3999 } |
| 4019 | 4000 |
| 4020 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, FX_BSTRC("Prev")); | 4001 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, FX_BSTRC("Prev")); |
| 4021 if (xrefpos) { | 4002 if (xrefpos) { |
| 4022 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, FX_BSTRC("XRefStm")); | 4003 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, FX_BSTRC("XRefStm")); |
| 4023 if (m_dwPrevXRefOffset) { | 4004 if (m_dwPrevXRefOffset) { |
| 4024 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4005 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 4025 } else { | 4006 } else { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4084 | 4065 |
| 4085 CPDF_Array* pArray = pPages->AsArray(); | 4066 CPDF_Array* pArray = pPages->AsArray(); |
| 4086 if (!pArray) { | 4067 if (!pArray) { |
| 4087 pPages->Release(); | 4068 pPages->Release(); |
| 4088 m_docStatus = PDF_DATAAVAIL_ERROR; | 4069 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 4089 return FALSE; | 4070 return FALSE; |
| 4090 } | 4071 } |
| 4091 | 4072 |
| 4092 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4073 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 4093 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { | 4074 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { |
| 4094 CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i); | 4075 CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); |
| 4095 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { | 4076 if (!pKid) |
| 4096 continue; | 4077 continue; |
| 4097 } | 4078 |
| 4098 CPDF_PageNode* pNode = new CPDF_PageNode(); | 4079 CPDF_PageNode* pNode = new CPDF_PageNode(); |
| 4099 pPageNode->m_childNode.Add(pNode); | 4080 pPageNode->m_childNode.Add(pNode); |
| 4100 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); | 4081 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 4101 } | 4082 } |
| 4102 pPages->Release(); | 4083 pPages->Release(); |
| 4103 return TRUE; | 4084 return TRUE; |
| 4104 } | 4085 } |
| 4105 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, | 4086 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, |
| 4106 CPDF_PageNode* pPageNode, | 4087 CPDF_PageNode* pPageNode, |
| 4107 IFX_DownloadHints* pHints) { | 4088 IFX_DownloadHints* pHints) { |
| 4108 FX_BOOL bExist = FALSE; | 4089 FX_BOOL bExist = FALSE; |
| 4109 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); | 4090 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); |
| 4110 if (!bExist) { | 4091 if (!bExist) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4134 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type")); | 4115 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type")); |
| 4135 if (type == FX_BSTRC("Pages")) { | 4116 if (type == FX_BSTRC("Pages")) { |
| 4136 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4117 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 4137 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids")); | 4118 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids")); |
| 4138 if (!pKids) { | 4119 if (!pKids) { |
| 4139 m_docStatus = PDF_DATAAVAIL_PAGE; | 4120 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 4140 return TRUE; | 4121 return TRUE; |
| 4141 } | 4122 } |
| 4142 switch (pKids->GetType()) { | 4123 switch (pKids->GetType()) { |
| 4143 case PDFOBJ_REFERENCE: { | 4124 case PDFOBJ_REFERENCE: { |
| 4144 CPDF_Reference* pKid = (CPDF_Reference*)pKids; | 4125 CPDF_Reference* pKid = pKids->AsReference(); |
| 4145 CPDF_PageNode* pNode = new CPDF_PageNode(); | 4126 CPDF_PageNode* pNode = new CPDF_PageNode(); |
| 4146 pPageNode->m_childNode.Add(pNode); | 4127 pPageNode->m_childNode.Add(pNode); |
| 4147 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 4128 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 4148 } break; | 4129 } break; |
| 4149 case PDFOBJ_ARRAY: { | 4130 case PDFOBJ_ARRAY: { |
| 4150 CPDF_Array* pKidsArray = pKids->AsArray(); | 4131 CPDF_Array* pKidsArray = pKids->AsArray(); |
| 4151 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 4132 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
| 4152 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); | 4133 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); |
| 4153 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { | 4134 if (!pKid) |
| 4154 continue; | 4135 continue; |
| 4155 } | 4136 |
| 4156 CPDF_PageNode* pNode = new CPDF_PageNode(); | 4137 CPDF_PageNode* pNode = new CPDF_PageNode(); |
| 4157 pPageNode->m_childNode.Add(pNode); | 4138 pPageNode->m_childNode.Add(pNode); |
| 4158 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); | 4139 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 4159 } | 4140 } |
| 4160 } break; | 4141 } break; |
| 4161 default: | 4142 default: |
| 4162 break; | 4143 break; |
| 4163 } | 4144 } |
| 4164 } else if (type == FX_BSTRC("Page")) { | 4145 } else if (type == FX_BSTRC("Page")) { |
| 4165 pPageNode->m_type = PDF_PAGENODE_PAGE; | 4146 pPageNode->m_type = PDF_PAGENODE_PAGE; |
| 4166 } else { | 4147 } else { |
| 4167 pPage->Release(); | 4148 pPage->Release(); |
| 4168 m_docStatus = PDF_DATAAVAIL_ERROR; | 4149 m_docStatus = PDF_DATAAVAIL_ERROR; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4587 return FALSE; | 4568 return FALSE; |
| 4588 } | 4569 } |
| 4589 CPDF_PageNode::~CPDF_PageNode() { | 4570 CPDF_PageNode::~CPDF_PageNode() { |
| 4590 int32_t iSize = m_childNode.GetSize(); | 4571 int32_t iSize = m_childNode.GetSize(); |
| 4591 for (int32_t i = 0; i < iSize; ++i) { | 4572 for (int32_t i = 0; i < iSize; ++i) { |
| 4592 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4573 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
| 4593 delete pNode; | 4574 delete pNode; |
| 4594 } | 4575 } |
| 4595 m_childNode.RemoveAll(); | 4576 m_childNode.RemoveAll(); |
| 4596 } | 4577 } |
| OLD | NEW |