| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 ReleaseEncryptHandler(); | 242 ReleaseEncryptHandler(); |
| 243 if (!RebuildCrossRef() || GetRootObjNum() == 0) | 243 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
| 244 return FORMAT_ERROR; | 244 return FORMAT_ERROR; |
| 245 | 245 |
| 246 eRet = SetEncryptHandler(); | 246 eRet = SetEncryptHandler(); |
| 247 if (eRet != SUCCESS) | 247 if (eRet != SUCCESS) |
| 248 return eRet; | 248 return eRet; |
| 249 } | 249 } |
| 250 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { | 250 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { |
| 251 CPDF_Reference* pMetadata = | 251 CPDF_Reference* pMetadata = |
| 252 ToReference(m_pDocument->GetRoot()->GetElement("Metadata")); | 252 ToReference(m_pDocument->GetRoot()->GetObjectBy("Metadata")); |
| 253 if (pMetadata) | 253 if (pMetadata) |
| 254 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); | 254 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| 255 } | 255 } |
| 256 return SUCCESS; | 256 return SUCCESS; |
| 257 } | 257 } |
| 258 CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { | 258 CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { |
| 259 ReleaseEncryptHandler(); | 259 ReleaseEncryptHandler(); |
| 260 SetEncryptDictionary(nullptr); | 260 SetEncryptDictionary(nullptr); |
| 261 | 261 |
| 262 if (!m_pTrailer) | 262 if (!m_pTrailer) |
| 263 return FORMAT_ERROR; | 263 return FORMAT_ERROR; |
| 264 | 264 |
| 265 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); | 265 CPDF_Object* pEncryptObj = m_pTrailer->GetObjectBy("Encrypt"); |
| 266 if (pEncryptObj) { | 266 if (pEncryptObj) { |
| 267 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { | 267 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
| 268 SetEncryptDictionary(pEncryptDict); | 268 SetEncryptDictionary(pEncryptDict); |
| 269 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { | 269 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
| 270 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); | 270 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
| 271 if (pEncryptObj) | 271 if (pEncryptObj) |
| 272 SetEncryptDictionary(pEncryptObj->GetDict()); | 272 SetEncryptDictionary(pEncryptObj->GetDict()); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 m_SortedOffset.insert(obj_pos); | 736 m_SortedOffset.insert(obj_pos); |
| 737 last_obj = start_pos; | 737 last_obj = start_pos; |
| 738 FX_FILESIZE obj_end = 0; | 738 FX_FILESIZE obj_end = 0; |
| 739 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( | 739 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( |
| 740 m_pDocument, obj_pos, objnum, &obj_end); | 740 m_pDocument, obj_pos, objnum, &obj_end); |
| 741 if (CPDF_Stream* pStream = ToStream(pObject)) { | 741 if (CPDF_Stream* pStream = ToStream(pObject)) { |
| 742 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 742 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
| 743 if ((pDict->KeyExist("Type")) && | 743 if ((pDict->KeyExist("Type")) && |
| 744 (pDict->GetStringBy("Type") == "XRef" && | 744 (pDict->GetStringBy("Type") == "XRef" && |
| 745 pDict->KeyExist("Size"))) { | 745 pDict->KeyExist("Size"))) { |
| 746 CPDF_Object* pRoot = pDict->GetElement("Root"); | 746 CPDF_Object* pRoot = pDict->GetObjectBy("Root"); |
| 747 if (pRoot && pRoot->GetDict() && | 747 if (pRoot && pRoot->GetDict() && |
| 748 pRoot->GetDict()->GetElement("Pages")) { | 748 pRoot->GetDict()->GetObjectBy("Pages")) { |
| 749 if (m_pTrailer) | 749 if (m_pTrailer) |
| 750 m_pTrailer->Release(); | 750 m_pTrailer->Release(); |
| 751 m_pTrailer = ToDictionary(pDict->Clone()); | 751 m_pTrailer = ToDictionary(pDict->Clone()); |
| 752 } | 752 } |
| 753 } | 753 } |
| 754 } | 754 } |
| 755 } | 755 } |
| 756 | 756 |
| 757 FX_FILESIZE offset = 0; | 757 FX_FILESIZE offset = 0; |
| 758 m_pSyntax->RestorePos(obj_pos); | 758 m_pSyntax->RestorePos(obj_pos); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 | 802 |
| 803 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); | 803 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); |
| 804 if (pObj) { | 804 if (pObj) { |
| 805 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 805 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
| 806 pObj->Release(); | 806 pObj->Release(); |
| 807 } else { | 807 } else { |
| 808 CPDF_Stream* pStream = pObj->AsStream(); | 808 CPDF_Stream* pStream = pObj->AsStream(); |
| 809 if (CPDF_Dictionary* pTrailer = | 809 if (CPDF_Dictionary* pTrailer = |
| 810 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 810 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
| 811 if (m_pTrailer) { | 811 if (m_pTrailer) { |
| 812 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 812 CPDF_Object* pRoot = pTrailer->GetObjectBy("Root"); |
| 813 CPDF_Reference* pRef = ToReference(pRoot); | 813 CPDF_Reference* pRef = ToReference(pRoot); |
| 814 if (!pRoot || | 814 if (!pRoot || |
| 815 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 815 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
| 816 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 816 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
| 817 auto it = pTrailer->begin(); | 817 auto it = pTrailer->begin(); |
| 818 while (it != pTrailer->end()) { | 818 while (it != pTrailer->end()) { |
| 819 const CFX_ByteString& key = it->first; | 819 const CFX_ByteString& key = it->first; |
| 820 CPDF_Object* pElement = it->second; | 820 CPDF_Object* pElement = it->second; |
| 821 ++it; | 821 ++it; |
| 822 uint32_t dwObjNum = | 822 uint32_t dwObjNum = |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 it.second.type = 0; | 982 it.second.type = 0; |
| 983 } else { | 983 } else { |
| 984 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); | 984 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); |
| 985 } | 985 } |
| 986 | 986 |
| 987 std::vector<std::pair<int32_t, int32_t>> arrIndex; | 987 std::vector<std::pair<int32_t, int32_t>> arrIndex; |
| 988 CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index"); | 988 CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index"); |
| 989 if (pArray) { | 989 if (pArray) { |
| 990 uint32_t nPairSize = pArray->GetCount() / 2; | 990 uint32_t nPairSize = pArray->GetCount() / 2; |
| 991 for (uint32_t i = 0; i < nPairSize; i++) { | 991 for (uint32_t i = 0; i < nPairSize; i++) { |
| 992 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); | 992 CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2); |
| 993 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); | 993 CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1); |
| 994 | 994 |
| 995 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { | 995 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { |
| 996 int nStartNum = pStartNumObj->GetInteger(); | 996 int nStartNum = pStartNumObj->GetInteger(); |
| 997 int nCount = pCountObj->GetInteger(); | 997 int nCount = pCountObj->GetInteger(); |
| 998 if (nStartNum >= 0 && nCount > 0) | 998 if (nStartNum >= 0 && nCount > 0) |
| 999 arrIndex.push_back(std::make_pair(nStartNum, nCount)); | 999 arrIndex.push_back(std::make_pair(nStartNum, nCount)); |
| 1000 } | 1000 } |
| 1001 } | 1001 } |
| 1002 } | 1002 } |
| 1003 | 1003 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 } | 1088 } |
| 1089 } | 1089 } |
| 1090 } | 1090 } |
| 1091 segindex += count; | 1091 segindex += count; |
| 1092 } | 1092 } |
| 1093 pStream->Release(); | 1093 pStream->Release(); |
| 1094 return TRUE; | 1094 return TRUE; |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 CPDF_Array* CPDF_Parser::GetIDArray() { | 1097 CPDF_Array* CPDF_Parser::GetIDArray() { |
| 1098 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement("ID") : nullptr; | 1098 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectBy("ID") : nullptr; |
| 1099 if (!pID) | 1099 if (!pID) |
| 1100 return nullptr; | 1100 return nullptr; |
| 1101 | 1101 |
| 1102 if (CPDF_Reference* pRef = pID->AsReference()) { | 1102 if (CPDF_Reference* pRef = pID->AsReference()) { |
| 1103 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); | 1103 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); |
| 1104 m_pTrailer->SetAt("ID", pID); | 1104 m_pTrailer->SetAt("ID", pID); |
| 1105 } | 1105 } |
| 1106 return ToArray(pID); | 1106 return ToArray(pID); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 uint32_t CPDF_Parser::GetRootObjNum() { | 1109 uint32_t CPDF_Parser::GetRootObjNum() { |
| 1110 CPDF_Reference* pRef = | 1110 CPDF_Reference* pRef = |
| 1111 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); | 1111 ToReference(m_pTrailer ? m_pTrailer->GetObjectBy("Root") : nullptr); |
| 1112 return pRef ? pRef->GetRefObjNum() : 0; | 1112 return pRef ? pRef->GetRefObjNum() : 0; |
| 1113 } | 1113 } |
| 1114 | 1114 |
| 1115 uint32_t CPDF_Parser::GetInfoObjNum() { | 1115 uint32_t CPDF_Parser::GetInfoObjNum() { |
| 1116 CPDF_Reference* pRef = | 1116 CPDF_Reference* pRef = |
| 1117 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); | 1117 ToReference(m_pTrailer ? m_pTrailer->GetObjectBy("Info") : nullptr); |
| 1118 return pRef ? pRef->GetRefObjNum() : 0; | 1118 return pRef ? pRef->GetRefObjNum() : 0; |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 FX_BOOL CPDF_Parser::IsFormStream(uint32_t objnum, FX_BOOL& bForm) { | 1121 FX_BOOL CPDF_Parser::IsFormStream(uint32_t objnum, FX_BOOL& bForm) { |
| 1122 bForm = FALSE; | 1122 bForm = FALSE; |
| 1123 if (!IsValidObjectNumber(objnum)) | 1123 if (!IsValidObjectNumber(objnum)) |
| 1124 return TRUE; | 1124 return TRUE; |
| 1125 | 1125 |
| 1126 if (GetObjectType(objnum) == 0) | 1126 if (GetObjectType(objnum) == 0) |
| 1127 return TRUE; | 1127 return TRUE; |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 if (m_pSyntax->GetKeyword() != "obj") { | 1486 if (m_pSyntax->GetKeyword() != "obj") { |
| 1487 m_pSyntax->RestorePos(SavedPos); | 1487 m_pSyntax->RestorePos(SavedPos); |
| 1488 return FALSE; | 1488 return FALSE; |
| 1489 } | 1489 } |
| 1490 | 1490 |
| 1491 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); | 1491 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); |
| 1492 if (!m_pLinearized) | 1492 if (!m_pLinearized) |
| 1493 return FALSE; | 1493 return FALSE; |
| 1494 | 1494 |
| 1495 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1495 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1496 if (pDict && pDict->GetElement("Linearized")) { | 1496 if (pDict && pDict->GetObjectBy("Linearized")) { |
| 1497 m_pSyntax->GetNextWord(nullptr); | 1497 m_pSyntax->GetNextWord(nullptr); |
| 1498 | 1498 |
| 1499 CPDF_Object* pLen = pDict->GetElement("L"); | 1499 CPDF_Object* pLen = pDict->GetObjectBy("L"); |
| 1500 if (!pLen) { | 1500 if (!pLen) { |
| 1501 m_pLinearized->Release(); | 1501 m_pLinearized->Release(); |
| 1502 m_pLinearized = nullptr; | 1502 m_pLinearized = nullptr; |
| 1503 return FALSE; | 1503 return FALSE; |
| 1504 } | 1504 } |
| 1505 | 1505 |
| 1506 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) | 1506 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) |
| 1507 return FALSE; | 1507 return FALSE; |
| 1508 | 1508 |
| 1509 if (CPDF_Number* pNo = ToNumber(pDict->GetElement("P"))) | 1509 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectBy("P"))) |
| 1510 m_dwFirstPageNo = pNo->GetInteger(); | 1510 m_dwFirstPageNo = pNo->GetInteger(); |
| 1511 | 1511 |
| 1512 if (CPDF_Number* pTable = ToNumber(pDict->GetElement("T"))) | 1512 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectBy("T"))) |
| 1513 m_LastXRefOffset = pTable->GetInteger(); | 1513 m_LastXRefOffset = pTable->GetInteger(); |
| 1514 | 1514 |
| 1515 return TRUE; | 1515 return TRUE; |
| 1516 } | 1516 } |
| 1517 m_pLinearized->Release(); | 1517 m_pLinearized->Release(); |
| 1518 m_pLinearized = nullptr; | 1518 m_pLinearized = nullptr; |
| 1519 return FALSE; | 1519 return FALSE; |
| 1520 } | 1520 } |
| 1521 | 1521 |
| 1522 CPDF_Parser::Error CPDF_Parser::StartAsyncParse(IFX_FileRead* pFileAccess) { | 1522 CPDF_Parser::Error CPDF_Parser::StartAsyncParse(IFX_FileRead* pFileAccess) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 if (!RebuildCrossRef() || GetRootObjNum() == 0) | 1584 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
| 1585 return FORMAT_ERROR; | 1585 return FORMAT_ERROR; |
| 1586 | 1586 |
| 1587 eRet = SetEncryptHandler(); | 1587 eRet = SetEncryptHandler(); |
| 1588 if (eRet != SUCCESS) | 1588 if (eRet != SUCCESS) |
| 1589 return eRet; | 1589 return eRet; |
| 1590 } | 1590 } |
| 1591 | 1591 |
| 1592 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { | 1592 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { |
| 1593 if (CPDF_Reference* pMetadata = | 1593 if (CPDF_Reference* pMetadata = |
| 1594 ToReference(m_pDocument->GetRoot()->GetElement("Metadata"))) | 1594 ToReference(m_pDocument->GetRoot()->GetObjectBy("Metadata"))) |
| 1595 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); | 1595 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| 1596 } | 1596 } |
| 1597 return SUCCESS; | 1597 return SUCCESS; |
| 1598 } | 1598 } |
| 1599 | 1599 |
| 1600 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { | 1600 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { |
| 1601 if (!LoadCrossRefV5(&xrefpos, FALSE)) | 1601 if (!LoadCrossRefV5(&xrefpos, FALSE)) |
| 1602 return FALSE; | 1602 return FALSE; |
| 1603 | 1603 |
| 1604 std::set<FX_FILESIZE> seen_xrefpos; | 1604 std::set<FX_FILESIZE> seen_xrefpos; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1643 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
| 1644 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1644 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
| 1645 m_LastXRefOffset = 0; | 1645 m_LastXRefOffset = 0; |
| 1646 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1646 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1647 return FORMAT_ERROR; | 1647 return FORMAT_ERROR; |
| 1648 } | 1648 } |
| 1649 | 1649 |
| 1650 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1650 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1651 return SUCCESS; | 1651 return SUCCESS; |
| 1652 } | 1652 } |
| OLD | NEW |