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 19 matching lines...) Expand all Loading... |
30 const int32_t kMaxXRefSize = 1048576; | 30 const int32_t kMaxXRefSize = 1048576; |
31 | 31 |
32 uint32_t GetVarInt(const uint8_t* p, int32_t n) { | 32 uint32_t GetVarInt(const uint8_t* p, int32_t n) { |
33 uint32_t result = 0; | 33 uint32_t result = 0; |
34 for (int32_t i = 0; i < n; ++i) | 34 for (int32_t i = 0; i < n; ++i) |
35 result = result * 256 + p[i]; | 35 result = result * 256 + p[i]; |
36 return result; | 36 return result; |
37 } | 37 } |
38 | 38 |
39 int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) { | 39 int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) { |
40 return pObjStream->GetDict()->GetIntegerBy("N"); | 40 return pObjStream->GetDict()->GetIntegerFor("N"); |
41 } | 41 } |
42 | 42 |
43 int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) { | 43 int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) { |
44 return pObjStream->GetDict()->GetIntegerBy("First"); | 44 return pObjStream->GetDict()->GetIntegerFor("First"); |
45 } | 45 } |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 CPDF_Parser::CPDF_Parser() | 49 CPDF_Parser::CPDF_Parser() |
50 : m_pDocument(nullptr), | 50 : m_pDocument(nullptr), |
51 m_bHasParsed(false), | 51 m_bHasParsed(false), |
52 m_bOwnFileRead(true), | 52 m_bOwnFileRead(true), |
53 m_FileVersion(0), | 53 m_FileVersion(0), |
54 m_pTrailer(nullptr), | 54 m_pTrailer(nullptr), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 ReleaseEncryptHandler(); | 224 ReleaseEncryptHandler(); |
225 if (!RebuildCrossRef() || GetRootObjNum() == 0) | 225 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
226 return FORMAT_ERROR; | 226 return FORMAT_ERROR; |
227 | 227 |
228 eRet = SetEncryptHandler(); | 228 eRet = SetEncryptHandler(); |
229 if (eRet != SUCCESS) | 229 if (eRet != SUCCESS) |
230 return eRet; | 230 return eRet; |
231 } | 231 } |
232 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { | 232 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { |
233 CPDF_Reference* pMetadata = | 233 CPDF_Reference* pMetadata = |
234 ToReference(m_pDocument->GetRoot()->GetObjectBy("Metadata")); | 234 ToReference(m_pDocument->GetRoot()->GetObjectFor("Metadata")); |
235 if (pMetadata) | 235 if (pMetadata) |
236 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); | 236 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); |
237 } | 237 } |
238 return SUCCESS; | 238 return SUCCESS; |
239 } | 239 } |
240 CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { | 240 CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { |
241 ReleaseEncryptHandler(); | 241 ReleaseEncryptHandler(); |
242 SetEncryptDictionary(nullptr); | 242 SetEncryptDictionary(nullptr); |
243 | 243 |
244 if (!m_pTrailer) | 244 if (!m_pTrailer) |
245 return FORMAT_ERROR; | 245 return FORMAT_ERROR; |
246 | 246 |
247 CPDF_Object* pEncryptObj = m_pTrailer->GetObjectBy("Encrypt"); | 247 CPDF_Object* pEncryptObj = m_pTrailer->GetObjectFor("Encrypt"); |
248 if (pEncryptObj) { | 248 if (pEncryptObj) { |
249 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { | 249 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
250 SetEncryptDictionary(pEncryptDict); | 250 SetEncryptDictionary(pEncryptDict); |
251 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { | 251 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
252 pEncryptObj = m_pDocument->GetOrParseIndirectObject(pRef->GetRefObjNum()); | 252 pEncryptObj = m_pDocument->GetOrParseIndirectObject(pRef->GetRefObjNum()); |
253 if (pEncryptObj) | 253 if (pEncryptObj) |
254 SetEncryptDictionary(pEncryptObj->GetDict()); | 254 SetEncryptDictionary(pEncryptObj->GetDict()); |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 if (m_pEncryptDict) { | 258 if (m_pEncryptDict) { |
259 CFX_ByteString filter = m_pEncryptDict->GetStringBy("Filter"); | 259 CFX_ByteString filter = m_pEncryptDict->GetStringFor("Filter"); |
260 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; | 260 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; |
261 Error err = HANDLER_ERROR; | 261 Error err = HANDLER_ERROR; |
262 if (filter == "Standard") { | 262 if (filter == "Standard") { |
263 pSecurityHandler.reset(new CPDF_SecurityHandler); | 263 pSecurityHandler.reset(new CPDF_SecurityHandler); |
264 err = PASSWORD_ERROR; | 264 err = PASSWORD_ERROR; |
265 } | 265 } |
266 if (!pSecurityHandler) | 266 if (!pSecurityHandler) |
267 return HANDLER_ERROR; | 267 return HANDLER_ERROR; |
268 | 268 |
269 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) | 269 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 360 |
361 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 361 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
362 LoadTrailerV4()); | 362 LoadTrailerV4()); |
363 if (!pDict) | 363 if (!pDict) |
364 return FALSE; | 364 return FALSE; |
365 | 365 |
366 xrefpos = GetDirectInteger(pDict.get(), "Prev"); | 366 xrefpos = GetDirectInteger(pDict.get(), "Prev"); |
367 | 367 |
368 // SLOW ... | 368 // SLOW ... |
369 XRefStreamList.insert(XRefStreamList.begin(), | 369 XRefStreamList.insert(XRefStreamList.begin(), |
370 pDict->GetIntegerBy("XRefStm")); | 370 pDict->GetIntegerFor("XRefStm")); |
371 m_Trailers.Add(pDict.release()); | 371 m_Trailers.Add(pDict.release()); |
372 } | 372 } |
373 | 373 |
374 for (size_t i = 0; i < CrossRefList.size(); ++i) { | 374 for (size_t i = 0; i < CrossRefList.size(); ++i) { |
375 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) | 375 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) |
376 return FALSE; | 376 return FALSE; |
377 if (i == 0 && !VerifyCrossRefV4()) | 377 if (i == 0 && !VerifyCrossRefV4()) |
378 return FALSE; | 378 return FALSE; |
379 } | 379 } |
380 return TRUE; | 380 return TRUE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 415 |
416 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 416 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
417 LoadTrailerV4()); | 417 LoadTrailerV4()); |
418 if (!pDict) | 418 if (!pDict) |
419 return FALSE; | 419 return FALSE; |
420 | 420 |
421 xrefpos = GetDirectInteger(pDict.get(), "Prev"); | 421 xrefpos = GetDirectInteger(pDict.get(), "Prev"); |
422 | 422 |
423 // SLOW ... | 423 // SLOW ... |
424 XRefStreamList.insert(XRefStreamList.begin(), | 424 XRefStreamList.insert(XRefStreamList.begin(), |
425 pDict->GetIntegerBy("XRefStm")); | 425 pDict->GetIntegerFor("XRefStm")); |
426 m_Trailers.Add(pDict.release()); | 426 m_Trailers.Add(pDict.release()); |
427 } | 427 } |
428 | 428 |
429 for (size_t i = 1; i < CrossRefList.size(); ++i) { | 429 for (size_t i = 1; i < CrossRefList.size(); ++i) { |
430 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) | 430 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) |
431 return FALSE; | 431 return FALSE; |
432 } | 432 } |
433 return TRUE; | 433 return TRUE; |
434 } | 434 } |
435 | 435 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { | 744 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { |
745 FX_FILESIZE obj_pos = start_pos - m_pSyntax->m_HeaderOffset; | 745 FX_FILESIZE obj_pos = start_pos - m_pSyntax->m_HeaderOffset; |
746 m_SortedOffset.insert(obj_pos); | 746 m_SortedOffset.insert(obj_pos); |
747 last_obj = start_pos; | 747 last_obj = start_pos; |
748 FX_FILESIZE obj_end = 0; | 748 FX_FILESIZE obj_end = 0; |
749 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( | 749 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( |
750 m_pDocument, obj_pos, objnum, &obj_end); | 750 m_pDocument, obj_pos, objnum, &obj_end); |
751 if (CPDF_Stream* pStream = ToStream(pObject)) { | 751 if (CPDF_Stream* pStream = ToStream(pObject)) { |
752 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 752 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
753 if ((pDict->KeyExist("Type")) && | 753 if ((pDict->KeyExist("Type")) && |
754 (pDict->GetStringBy("Type") == "XRef" && | 754 (pDict->GetStringFor("Type") == "XRef" && |
755 pDict->KeyExist("Size"))) { | 755 pDict->KeyExist("Size"))) { |
756 CPDF_Object* pRoot = pDict->GetObjectBy("Root"); | 756 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); |
757 if (pRoot && pRoot->GetDict() && | 757 if (pRoot && pRoot->GetDict() && |
758 pRoot->GetDict()->GetObjectBy("Pages")) { | 758 pRoot->GetDict()->GetObjectFor("Pages")) { |
759 if (m_pTrailer) | 759 if (m_pTrailer) |
760 m_pTrailer->Release(); | 760 m_pTrailer->Release(); |
761 m_pTrailer = ToDictionary(pDict->Clone()); | 761 m_pTrailer = ToDictionary(pDict->Clone()); |
762 } | 762 } |
763 } | 763 } |
764 } | 764 } |
765 } | 765 } |
766 | 766 |
767 FX_FILESIZE offset = 0; | 767 FX_FILESIZE offset = 0; |
768 m_pSyntax->RestorePos(obj_pos); | 768 m_pSyntax->RestorePos(obj_pos); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 812 |
813 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); | 813 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); |
814 if (pObj) { | 814 if (pObj) { |
815 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 815 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
816 pObj->Release(); | 816 pObj->Release(); |
817 } else { | 817 } else { |
818 CPDF_Stream* pStream = pObj->AsStream(); | 818 CPDF_Stream* pStream = pObj->AsStream(); |
819 if (CPDF_Dictionary* pTrailer = | 819 if (CPDF_Dictionary* pTrailer = |
820 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 820 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
821 if (m_pTrailer) { | 821 if (m_pTrailer) { |
822 CPDF_Object* pRoot = pTrailer->GetObjectBy("Root"); | 822 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); |
823 CPDF_Reference* pRef = ToReference(pRoot); | 823 CPDF_Reference* pRef = ToReference(pRoot); |
824 if (!pRoot || | 824 if (!pRoot || |
825 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 825 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
826 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 826 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
827 auto it = pTrailer->begin(); | 827 auto it = pTrailer->begin(); |
828 while (it != pTrailer->end()) { | 828 while (it != pTrailer->end()) { |
829 const CFX_ByteString& key = it->first; | 829 const CFX_ByteString& key = it->first; |
830 CPDF_Object* pElement = it->second; | 830 CPDF_Object* pElement = it->second; |
831 ++it; | 831 ++it; |
832 uint32_t dwObjNum = | 832 uint32_t dwObjNum = |
833 pElement ? pElement->GetObjNum() : 0; | 833 pElement ? pElement->GetObjNum() : 0; |
834 if (dwObjNum) { | 834 if (dwObjNum) { |
835 m_pTrailer->SetAtReference(key, m_pDocument, | 835 m_pTrailer->SetReferenceFor(key, m_pDocument, |
836 dwObjNum); | 836 dwObjNum); |
837 } else { | 837 } else { |
838 m_pTrailer->SetAt(key, pElement->Clone()); | 838 m_pTrailer->SetFor(key, pElement->Clone()); |
839 } | 839 } |
840 } | 840 } |
841 } | 841 } |
842 pObj->Release(); | 842 pObj->Release(); |
843 } else { | 843 } else { |
844 if (pObj->IsStream()) { | 844 if (pObj->IsStream()) { |
845 m_pTrailer = ToDictionary(pTrailer->Clone()); | 845 m_pTrailer = ToDictionary(pTrailer->Clone()); |
846 pObj->Release(); | 846 pObj->Release(); |
847 } else { | 847 } else { |
848 m_pTrailer = pTrailer; | 848 m_pTrailer = pTrailer; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 pObject)) { | 973 pObject)) { |
974 return FALSE; | 974 return FALSE; |
975 } | 975 } |
976 } | 976 } |
977 | 977 |
978 CPDF_Stream* pStream = pObject->AsStream(); | 978 CPDF_Stream* pStream = pObject->AsStream(); |
979 if (!pStream) | 979 if (!pStream) |
980 return FALSE; | 980 return FALSE; |
981 | 981 |
982 CPDF_Dictionary* pDict = pStream->GetDict(); | 982 CPDF_Dictionary* pDict = pStream->GetDict(); |
983 *pos = pDict->GetIntegerBy("Prev"); | 983 *pos = pDict->GetIntegerFor("Prev"); |
984 int32_t size = pDict->GetIntegerBy("Size"); | 984 int32_t size = pDict->GetIntegerFor("Size"); |
985 if (size < 0) { | 985 if (size < 0) { |
986 pStream->Release(); | 986 pStream->Release(); |
987 return FALSE; | 987 return FALSE; |
988 } | 988 } |
989 | 989 |
990 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone()); | 990 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone()); |
991 if (bMainXRef) { | 991 if (bMainXRef) { |
992 m_pTrailer = pNewTrailer; | 992 m_pTrailer = pNewTrailer; |
993 ShrinkObjectMap(size); | 993 ShrinkObjectMap(size); |
994 for (auto& it : m_ObjectInfo) | 994 for (auto& it : m_ObjectInfo) |
995 it.second.type = 0; | 995 it.second.type = 0; |
996 } else { | 996 } else { |
997 m_Trailers.Add(pNewTrailer); | 997 m_Trailers.Add(pNewTrailer); |
998 } | 998 } |
999 | 999 |
1000 std::vector<std::pair<int32_t, int32_t>> arrIndex; | 1000 std::vector<std::pair<int32_t, int32_t>> arrIndex; |
1001 CPDF_Array* pArray = pDict->GetArrayBy("Index"); | 1001 CPDF_Array* pArray = pDict->GetArrayFor("Index"); |
1002 if (pArray) { | 1002 if (pArray) { |
1003 for (size_t i = 0; i < pArray->GetCount() / 2; i++) { | 1003 for (size_t i = 0; i < pArray->GetCount() / 2; i++) { |
1004 CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2); | 1004 CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2); |
1005 CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1); | 1005 CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1); |
1006 | 1006 |
1007 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { | 1007 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { |
1008 int nStartNum = pStartNumObj->GetInteger(); | 1008 int nStartNum = pStartNumObj->GetInteger(); |
1009 int nCount = pCountObj->GetInteger(); | 1009 int nCount = pCountObj->GetInteger(); |
1010 if (nStartNum >= 0 && nCount > 0) | 1010 if (nStartNum >= 0 && nCount > 0) |
1011 arrIndex.push_back(std::make_pair(nStartNum, nCount)); | 1011 arrIndex.push_back(std::make_pair(nStartNum, nCount)); |
1012 } | 1012 } |
1013 } | 1013 } |
1014 } | 1014 } |
1015 | 1015 |
1016 if (arrIndex.size() == 0) | 1016 if (arrIndex.size() == 0) |
1017 arrIndex.push_back(std::make_pair(0, size)); | 1017 arrIndex.push_back(std::make_pair(0, size)); |
1018 | 1018 |
1019 pArray = pDict->GetArrayBy("W"); | 1019 pArray = pDict->GetArrayFor("W"); |
1020 if (!pArray) { | 1020 if (!pArray) { |
1021 pStream->Release(); | 1021 pStream->Release(); |
1022 return FALSE; | 1022 return FALSE; |
1023 } | 1023 } |
1024 | 1024 |
1025 CFX_ArrayTemplate<uint32_t> WidthArray; | 1025 CFX_ArrayTemplate<uint32_t> WidthArray; |
1026 FX_SAFE_UINT32 dwAccWidth = 0; | 1026 FX_SAFE_UINT32 dwAccWidth = 0; |
1027 for (size_t i = 0; i < pArray->GetCount(); ++i) { | 1027 for (size_t i = 0; i < pArray->GetCount(); ++i) { |
1028 WidthArray.Add(pArray->GetIntegerAt(i)); | 1028 WidthArray.Add(pArray->GetIntegerAt(i)); |
1029 dwAccWidth += WidthArray[i]; | 1029 dwAccWidth += WidthArray[i]; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 } | 1100 } |
1101 } | 1101 } |
1102 } | 1102 } |
1103 segindex += count; | 1103 segindex += count; |
1104 } | 1104 } |
1105 pStream->Release(); | 1105 pStream->Release(); |
1106 return TRUE; | 1106 return TRUE; |
1107 } | 1107 } |
1108 | 1108 |
1109 CPDF_Array* CPDF_Parser::GetIDArray() { | 1109 CPDF_Array* CPDF_Parser::GetIDArray() { |
1110 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectBy("ID") : nullptr; | 1110 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; |
1111 if (!pID) | 1111 if (!pID) |
1112 return nullptr; | 1112 return nullptr; |
1113 | 1113 |
1114 if (CPDF_Reference* pRef = pID->AsReference()) { | 1114 if (CPDF_Reference* pRef = pID->AsReference()) { |
1115 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); | 1115 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); |
1116 m_pTrailer->SetAt("ID", pID); | 1116 m_pTrailer->SetFor("ID", pID); |
1117 } | 1117 } |
1118 return ToArray(pID); | 1118 return ToArray(pID); |
1119 } | 1119 } |
1120 | 1120 |
1121 uint32_t CPDF_Parser::GetRootObjNum() { | 1121 uint32_t CPDF_Parser::GetRootObjNum() { |
1122 CPDF_Reference* pRef = | 1122 CPDF_Reference* pRef = |
1123 ToReference(m_pTrailer ? m_pTrailer->GetObjectBy("Root") : nullptr); | 1123 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); |
1124 return pRef ? pRef->GetRefObjNum() : 0; | 1124 return pRef ? pRef->GetRefObjNum() : 0; |
1125 } | 1125 } |
1126 | 1126 |
1127 uint32_t CPDF_Parser::GetInfoObjNum() { | 1127 uint32_t CPDF_Parser::GetInfoObjNum() { |
1128 CPDF_Reference* pRef = | 1128 CPDF_Reference* pRef = |
1129 ToReference(m_pTrailer ? m_pTrailer->GetObjectBy("Info") : nullptr); | 1129 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Info") : nullptr); |
1130 return pRef ? pRef->GetRefObjNum() : 0; | 1130 return pRef ? pRef->GetRefObjNum() : 0; |
1131 } | 1131 } |
1132 | 1132 |
1133 FX_BOOL CPDF_Parser::IsFormStream(uint32_t objnum, FX_BOOL& bForm) { | 1133 FX_BOOL CPDF_Parser::IsFormStream(uint32_t objnum, FX_BOOL& bForm) { |
1134 bForm = FALSE; | 1134 bForm = FALSE; |
1135 if (!IsValidObjectNumber(objnum)) | 1135 if (!IsValidObjectNumber(objnum)) |
1136 return TRUE; | 1136 return TRUE; |
1137 | 1137 |
1138 if (GetObjectType(objnum) == 0) | 1138 if (GetObjectType(objnum) == 0) |
1139 return TRUE; | 1139 return TRUE; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 m_pSyntax->RestorePos(SavedPos); | 1439 m_pSyntax->RestorePos(SavedPos); |
1440 return nullptr; | 1440 return nullptr; |
1441 } | 1441 } |
1442 | 1442 |
1443 uint32_t gennum = FXSYS_atoui(word.c_str()); | 1443 uint32_t gennum = FXSYS_atoui(word.c_str()); |
1444 if (m_pSyntax->GetKeyword() != "obj") { | 1444 if (m_pSyntax->GetKeyword() != "obj") { |
1445 m_pSyntax->RestorePos(SavedPos); | 1445 m_pSyntax->RestorePos(SavedPos); |
1446 return nullptr; | 1446 return nullptr; |
1447 } | 1447 } |
1448 | 1448 |
1449 CPDF_Object* pObj = m_pSyntax->GetObjectByStrict(pObjList, objnum, gennum); | 1449 CPDF_Object* pObj = m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum); |
1450 if (pResultPos) | 1450 if (pResultPos) |
1451 *pResultPos = m_pSyntax->m_Pos; | 1451 *pResultPos = m_pSyntax->m_Pos; |
1452 | 1452 |
1453 m_pSyntax->RestorePos(SavedPos); | 1453 m_pSyntax->RestorePos(SavedPos); |
1454 return pObj; | 1454 return pObj; |
1455 } | 1455 } |
1456 | 1456 |
1457 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { | 1457 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { |
1458 if (m_pSyntax->GetKeyword() != "trailer") | 1458 if (m_pSyntax->GetKeyword() != "trailer") |
1459 return nullptr; | 1459 return nullptr; |
1460 | 1460 |
1461 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 1461 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
1462 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); | 1462 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); |
1463 if (!ToDictionary(pObj.get())) | 1463 if (!ToDictionary(pObj.get())) |
1464 return nullptr; | 1464 return nullptr; |
1465 return pObj.release()->AsDictionary(); | 1465 return pObj.release()->AsDictionary(); |
1466 } | 1466 } |
1467 | 1467 |
1468 uint32_t CPDF_Parser::GetPermissions() const { | 1468 uint32_t CPDF_Parser::GetPermissions() const { |
1469 if (!m_pSecurityHandler) | 1469 if (!m_pSecurityHandler) |
1470 return 0xFFFFFFFF; | 1470 return 0xFFFFFFFF; |
1471 | 1471 |
1472 uint32_t dwPermission = m_pSecurityHandler->GetPermissions(); | 1472 uint32_t dwPermission = m_pSecurityHandler->GetPermissions(); |
1473 if (m_pEncryptDict && m_pEncryptDict->GetStringBy("Filter") == "Standard") { | 1473 if (m_pEncryptDict && m_pEncryptDict->GetStringFor("Filter") == "Standard") { |
1474 // See PDF Reference 1.7, page 123, table 3.20. | 1474 // See PDF Reference 1.7, page 123, table 3.20. |
1475 dwPermission &= 0xFFFFFFFC; | 1475 dwPermission &= 0xFFFFFFFC; |
1476 dwPermission |= 0xFFFFF0C0; | 1476 dwPermission |= 0xFFFFF0C0; |
1477 } | 1477 } |
1478 return dwPermission; | 1478 return dwPermission; |
1479 } | 1479 } |
1480 | 1480 |
1481 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, | 1481 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, |
1482 uint32_t offset) { | 1482 uint32_t offset) { |
1483 m_pSyntax->InitParser(pFileAccess, offset); | 1483 m_pSyntax->InitParser(pFileAccess, offset); |
(...skipping 14 matching lines...) Expand all Loading... |
1498 if (m_pSyntax->GetKeyword() != "obj") { | 1498 if (m_pSyntax->GetKeyword() != "obj") { |
1499 m_pSyntax->RestorePos(SavedPos); | 1499 m_pSyntax->RestorePos(SavedPos); |
1500 return FALSE; | 1500 return FALSE; |
1501 } | 1501 } |
1502 | 1502 |
1503 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); | 1503 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); |
1504 if (!m_pLinearized) | 1504 if (!m_pLinearized) |
1505 return FALSE; | 1505 return FALSE; |
1506 | 1506 |
1507 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1507 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
1508 if (pDict && pDict->GetObjectBy("Linearized")) { | 1508 if (pDict && pDict->GetObjectFor("Linearized")) { |
1509 m_pSyntax->GetNextWord(nullptr); | 1509 m_pSyntax->GetNextWord(nullptr); |
1510 | 1510 |
1511 CPDF_Object* pLen = pDict->GetObjectBy("L"); | 1511 CPDF_Object* pLen = pDict->GetObjectFor("L"); |
1512 if (!pLen) { | 1512 if (!pLen) { |
1513 m_pLinearized->Release(); | 1513 m_pLinearized->Release(); |
1514 m_pLinearized = nullptr; | 1514 m_pLinearized = nullptr; |
1515 return FALSE; | 1515 return FALSE; |
1516 } | 1516 } |
1517 | 1517 |
1518 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) | 1518 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) |
1519 return FALSE; | 1519 return FALSE; |
1520 | 1520 |
1521 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectBy("P"))) | 1521 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) |
1522 m_dwFirstPageNo = pNo->GetInteger(); | 1522 m_dwFirstPageNo = pNo->GetInteger(); |
1523 | 1523 |
1524 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectBy("T"))) | 1524 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) |
1525 m_LastXRefOffset = pTable->GetInteger(); | 1525 m_LastXRefOffset = pTable->GetInteger(); |
1526 | 1526 |
1527 return TRUE; | 1527 return TRUE; |
1528 } | 1528 } |
1529 m_pLinearized->Release(); | 1529 m_pLinearized->Release(); |
1530 m_pLinearized = nullptr; | 1530 m_pLinearized = nullptr; |
1531 return FALSE; | 1531 return FALSE; |
1532 } | 1532 } |
1533 | 1533 |
1534 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(IFX_FileRead* pFileAccess, | 1534 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(IFX_FileRead* pFileAccess, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 if (!RebuildCrossRef() || GetRootObjNum() == 0) | 1599 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
1600 return FORMAT_ERROR; | 1600 return FORMAT_ERROR; |
1601 | 1601 |
1602 eRet = SetEncryptHandler(); | 1602 eRet = SetEncryptHandler(); |
1603 if (eRet != SUCCESS) | 1603 if (eRet != SUCCESS) |
1604 return eRet; | 1604 return eRet; |
1605 } | 1605 } |
1606 | 1606 |
1607 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { | 1607 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { |
1608 if (CPDF_Reference* pMetadata = | 1608 if (CPDF_Reference* pMetadata = |
1609 ToReference(m_pDocument->GetRoot()->GetObjectBy("Metadata"))) | 1609 ToReference(m_pDocument->GetRoot()->GetObjectFor("Metadata"))) |
1610 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); | 1610 m_pSyntax->m_MetadataObjnum = pMetadata->GetRefObjNum(); |
1611 } | 1611 } |
1612 return SUCCESS; | 1612 return SUCCESS; |
1613 } | 1613 } |
1614 | 1614 |
1615 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { | 1615 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { |
1616 if (!LoadCrossRefV5(&xrefpos, FALSE)) | 1616 if (!LoadCrossRefV5(&xrefpos, FALSE)) |
1617 return FALSE; | 1617 return FALSE; |
1618 | 1618 |
1619 std::set<FX_FILESIZE> seen_xrefpos; | 1619 std::set<FX_FILESIZE> seen_xrefpos; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1658 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1659 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1659 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1660 m_LastXRefOffset = 0; | 1660 m_LastXRefOffset = 0; |
1661 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1661 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1662 return FORMAT_ERROR; | 1662 return FORMAT_ERROR; |
1663 } | 1663 } |
1664 | 1664 |
1665 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1665 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1666 return SUCCESS; | 1666 return SUCCESS; |
1667 } | 1667 } |
OLD | NEW |