| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "../../../include/fpdfapi/fpdf_module.h" | 10 #include "../../../include/fpdfapi/fpdf_module.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 return err; | 274 return err; |
| 275 } | 275 } |
| 276 CPDF_CryptoHandler* pCryptoHandler = m_pSecurityHandler->CreateCryptoHan
dler(); | 276 CPDF_CryptoHandler* pCryptoHandler = m_pSecurityHandler->CreateCryptoHan
dler(); |
| 277 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler)) { | 277 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler)) { |
| 278 delete pCryptoHandler; | 278 delete pCryptoHandler; |
| 279 pCryptoHandler = NULL; | 279 pCryptoHandler = NULL; |
| 280 return PDFPARSE_ERROR_HANDLER; | 280 return PDFPARSE_ERROR_HANDLER; |
| 281 } | 281 } |
| 282 m_Syntax.SetEncrypt(pCryptoHandler); | 282 m_Syntax.SetEncrypt(pCryptoHandler); |
| 283 } else if (m_pEncryptDict) { | 283 } else if (m_pEncryptDict) { |
| 284 CFX_ByteString filter = m_pEncryptDict->GetString(FX_BSTRC("Filter")); | 284 CFX_ByteString filter = m_pEncryptDict->GetStringAt("Filter"); |
| 285 CPDF_SecurityHandler* pSecurityHandler = NULL; | 285 CPDF_SecurityHandler* pSecurityHandler = NULL; |
| 286 FX_DWORD err = PDFPARSE_ERROR_HANDLER; | 286 FX_DWORD err = PDFPARSE_ERROR_HANDLER; |
| 287 if (filter == FX_BSTRC("Standard")) { | 287 if (filter == FX_BSTRC("Standard")) { |
| 288 pSecurityHandler = FPDF_CreateStandardSecurityHandler(); | 288 pSecurityHandler = FPDF_CreateStandardSecurityHandler(); |
| 289 err = PDFPARSE_ERROR_PASSWORD; | 289 err = PDFPARSE_ERROR_PASSWORD; |
| 290 } | 290 } |
| 291 if (pSecurityHandler == NULL) { | 291 if (pSecurityHandler == NULL) { |
| 292 return PDFPARSE_ERROR_HANDLER; | 292 return PDFPARSE_ERROR_HANDLER; |
| 293 } | 293 } |
| 294 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { | 294 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 } | 780 } |
| 781 FX_FILESIZE obj_end = 0; | 781 FX_FILESIZE obj_end = 0; |
| 782 CPDF_Object *pObject = ParseIndirectObjectAtBySt
rict(m_pDocument, obj_pos, objnum, NULL, &obj_end); | 782 CPDF_Object *pObject = ParseIndirectObjectAtBySt
rict(m_pDocument, obj_pos, objnum, NULL, &obj_end); |
| 783 if (pObject) { | 783 if (pObject) { |
| 784 int iType = pObject->GetType(); | 784 int iType = pObject->GetType(); |
| 785 if (iType == PDFOBJ_STREAM) { | 785 if (iType == PDFOBJ_STREAM) { |
| 786 CPDF_Stream* pStream = (CPDF_Stream*)pOb
ject; | 786 CPDF_Stream* pStream = (CPDF_Stream*)pOb
ject; |
| 787 CPDF_Dictionary* pDict = pStream->GetDic
t(); | 787 CPDF_Dictionary* pDict = pStream->GetDic
t(); |
| 788 if (pDict) { | 788 if (pDict) { |
| 789 if (pDict->KeyExist(FX_BSTRC("Type")
)) { | 789 if (pDict->KeyExist(FX_BSTRC("Type")
)) { |
| 790 CFX_ByteString bsValue = pDict->
GetString(FX_BSTRC("Type")); | 790 CFX_ByteString bsValue = pDict->
GetStringAt("Type"); |
| 791 if (bsValue == FX_BSTRC("XRef")
&& pDict->KeyExist(FX_BSTRC("Size"))) { | 791 if (bsValue == FX_BSTRC("XRef")
&& pDict->KeyExist(FX_BSTRC("Size"))) { |
| 792 CPDF_Object* pRoot = pDict->
GetElement(FX_BSTRC("Root")); | 792 CPDF_Object* pRoot = pDict->
GetElement(FX_BSTRC("Root")); |
| 793 if (pRoot && pRoot->GetDict(
) && pRoot->GetDict()->GetElement(FX_BSTRC("Pages"))) { | 793 if (pRoot && pRoot->GetDict(
) && pRoot->GetDict()->GetElement(FX_BSTRC("Pages"))) { |
| 794 if (m_pTrailer) { | 794 if (m_pTrailer) { |
| 795 m_pTrailer->Release(
); | 795 m_pTrailer->Release(
); |
| 796 } | 796 } |
| 797 m_pTrailer = (CPDF_Dicti
onary*)pDict->Clone(); | 797 m_pTrailer = (CPDF_Dicti
onary*)pDict->Clone(); |
| 798 } | 798 } |
| 799 } | 799 } |
| 800 } | 800 } |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 return NULL; | 1457 return NULL; |
| 1458 } | 1458 } |
| 1459 return (CPDF_Dictionary*)pObj; | 1459 return (CPDF_Dictionary*)pObj; |
| 1460 } | 1460 } |
| 1461 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) | 1461 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) |
| 1462 { | 1462 { |
| 1463 if (m_pSecurityHandler == NULL) { | 1463 if (m_pSecurityHandler == NULL) { |
| 1464 return (FX_DWORD) - 1; | 1464 return (FX_DWORD) - 1; |
| 1465 } | 1465 } |
| 1466 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); | 1466 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); |
| 1467 if (m_pEncryptDict && m_pEncryptDict->GetString(FX_BSTRC("Filter")) == FX_BS
TRC("Standard")) { | 1467 if (m_pEncryptDict && m_pEncryptDict->GetStringAt("Filter") == "Standard") { |
| 1468 dwPermission &= 0xFFFFFFFC; | 1468 dwPermission &= 0xFFFFFFFC; |
| 1469 dwPermission |= 0xFFFFF0C0; | 1469 dwPermission |= 0xFFFFF0C0; |
| 1470 if(bCheckRevision && m_pEncryptDict->GetInteger(FX_BSTRC("R")) == 2) { | 1470 if(bCheckRevision && m_pEncryptDict->GetInteger(FX_BSTRC("R")) == 2) { |
| 1471 dwPermission &= 0xFFFFF0FF; | 1471 dwPermission &= 0xFFFFF0FF; |
| 1472 } | 1472 } |
| 1473 } | 1473 } |
| 1474 return dwPermission; | 1474 return dwPermission; |
| 1475 } | 1475 } |
| 1476 FX_BOOL CPDF_Parser::IsOwner() | 1476 FX_BOOL CPDF_Parser::IsOwner() |
| 1477 { | 1477 { |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3041 CPDF_Array *pArray = pObj->GetArray(); | 3041 CPDF_Array *pArray = pObj->GetArray(); |
| 3042 for (FX_DWORD k = 0; k < pArray->GetCount(); k++) { | 3042 for (FX_DWORD k = 0; k < pArray->GetCount(); k++) { |
| 3043 new_obj_array.Add(pArray->GetElement(k)); | 3043 new_obj_array.Add(pArray->GetElement(k)); |
| 3044 } | 3044 } |
| 3045 } | 3045 } |
| 3046 break; | 3046 break; |
| 3047 case PDFOBJ_STREAM: | 3047 case PDFOBJ_STREAM: |
| 3048 pObj = pObj->GetDict(); | 3048 pObj = pObj->GetDict(); |
| 3049 case PDFOBJ_DICTIONARY: { | 3049 case PDFOBJ_DICTIONARY: { |
| 3050 CPDF_Dictionary *pDict = pObj->GetDict(); | 3050 CPDF_Dictionary *pDict = pObj->GetDict(); |
| 3051 if (pDict && pDict->GetString("Type") == "Page" && !bParsePa
ge) { | 3051 if (!bParsePage && |
| 3052 pDict && |
| 3053 pDict->GetStringAt("Type") == "Page") { |
| 3052 continue; | 3054 continue; |
| 3053 } | 3055 } |
| 3054 FX_POSITION pos = pDict->GetStartPos(); | 3056 FX_POSITION pos = pDict->GetStartPos(); |
| 3055 while (pos) { | 3057 while (pos) { |
| 3056 CPDF_Object *value; | 3058 CPDF_Object *value; |
| 3057 CFX_ByteString key; | 3059 CFX_ByteString key; |
| 3058 value = pDict->GetNextElement(pos, key); | 3060 value = pDict->GetNextElement(pos, key); |
| 3059 if (key != "Parent") { | 3061 if (key != "Parent") { |
| 3060 new_obj_array.Add(value); | 3062 new_obj_array.Add(value); |
| 3061 } | 3063 } |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3472 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { | 3474 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { |
| 3473 UnavailObjList.Add(((CPDF_Reference *)pItem)->GetRefObjN
um()); | 3475 UnavailObjList.Add(((CPDF_Reference *)pItem)->GetRefObjN
um()); |
| 3474 } | 3476 } |
| 3475 } | 3477 } |
| 3476 } | 3478 } |
| 3477 } | 3479 } |
| 3478 if (pObj->GetType() != PDFOBJ_DICTIONARY) { | 3480 if (pObj->GetType() != PDFOBJ_DICTIONARY) { |
| 3479 pObj->Release(); | 3481 pObj->Release(); |
| 3480 continue; | 3482 continue; |
| 3481 } | 3483 } |
| 3482 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); | 3484 CFX_ByteString type = pObj->GetDict()->GetStringAt("Type"); |
| 3483 if (type == FX_BSTRC("Pages")) { | 3485 if (type == FX_BSTRC("Pages")) { |
| 3484 m_PagesArray.Add(pObj); | 3486 m_PagesArray.Add(pObj); |
| 3485 continue; | 3487 continue; |
| 3486 } | 3488 } |
| 3487 pObj->Release(); | 3489 pObj->Release(); |
| 3488 } | 3490 } |
| 3489 m_PageObjList.RemoveAll(); | 3491 m_PageObjList.RemoveAll(); |
| 3490 if (UnavailObjList.GetSize()) { | 3492 if (UnavailObjList.GetSize()) { |
| 3491 m_PageObjList.Append(UnavailObjList); | 3493 m_PageObjList.Append(UnavailObjList); |
| 3492 return FALSE; | 3494 return FALSE; |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4156 pPage->Release(); | 4158 pPage->Release(); |
| 4157 return TRUE; | 4159 return TRUE; |
| 4158 } | 4160 } |
| 4159 if (pPage->GetType() != PDFOBJ_DICTIONARY) { | 4161 if (pPage->GetType() != PDFOBJ_DICTIONARY) { |
| 4160 pPage->Release(); | 4162 pPage->Release(); |
| 4161 m_docStatus = PDF_DATAAVAIL_ERROR; | 4163 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 4162 return FALSE; | 4164 return FALSE; |
| 4163 } | 4165 } |
| 4164 pPageNode->m_dwPageNo = dwPageNo; | 4166 pPageNode->m_dwPageNo = dwPageNo; |
| 4165 CPDF_Dictionary* pDict = pPage->GetDict(); | 4167 CPDF_Dictionary* pDict = pPage->GetDict(); |
| 4166 CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteS
tring(); | 4168 CFX_ByteString type = pDict ? pDict->GetStringAt("Type") : CFX_ByteString(); |
| 4167 if (type == FX_BSTRC("Pages")) { | 4169 if (type == FX_BSTRC("Pages")) { |
| 4168 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4170 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 4169 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); | 4171 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); |
| 4170 if (!pKids) { | 4172 if (!pKids) { |
| 4171 m_docStatus = PDF_DATAAVAIL_PAGE; | 4173 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 4172 return TRUE; | 4174 return TRUE; |
| 4173 } | 4175 } |
| 4174 switch (pKids->GetType()) { | 4176 switch (pKids->GetType()) { |
| 4175 case PDFOBJ_REFERENCE: { | 4177 case PDFOBJ_REFERENCE: { |
| 4176 CPDF_Reference *pKid = (CPDF_Reference *)pKids; | 4178 CPDF_Reference *pKid = (CPDF_Reference *)pKids; |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4632 } | 4634 } |
| 4633 CPDF_PageNode::~CPDF_PageNode() | 4635 CPDF_PageNode::~CPDF_PageNode() |
| 4634 { | 4636 { |
| 4635 int32_t iSize = m_childNode.GetSize(); | 4637 int32_t iSize = m_childNode.GetSize(); |
| 4636 for (int32_t i = 0; i < iSize; ++i) { | 4638 for (int32_t i = 0; i < iSize; ++i) { |
| 4637 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4639 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
| 4638 delete pNode; | 4640 delete pNode; |
| 4639 } | 4641 } |
| 4640 m_childNode.RemoveAll(); | 4642 m_childNode.RemoveAll(); |
| 4641 } | 4643 } |
| OLD | NEW |