| 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/parser/cpdf_parser.h" | 7 #include "core/fpdfapi/parser/cpdf_parser.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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), |
| 55 m_pEncryptDict(nullptr), | 55 m_pEncryptDict(nullptr), |
| 56 m_bVersionUpdated(false), | 56 m_bVersionUpdated(false), |
| 57 m_pLinearized(nullptr), | |
| 58 m_dwFirstPageNo(0), | 57 m_dwFirstPageNo(0), |
| 59 m_dwXrefStartObjNum(0) { | 58 m_dwXrefStartObjNum(0) { |
| 60 m_pSyntax.reset(new CPDF_SyntaxParser); | 59 m_pSyntax.reset(new CPDF_SyntaxParser); |
| 61 } | 60 } |
| 62 | 61 |
| 63 CPDF_Parser::~CPDF_Parser() { | 62 CPDF_Parser::~CPDF_Parser() { |
| 64 delete m_pTrailer; | 63 delete m_pTrailer; |
| 65 ReleaseEncryptHandler(); | 64 ReleaseEncryptHandler(); |
| 66 SetEncryptDictionary(nullptr); | 65 SetEncryptDictionary(nullptr); |
| 67 | 66 |
| 68 if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) { | 67 if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) { |
| 69 m_pSyntax->m_pFileAccess->Release(); | 68 m_pSyntax->m_pFileAccess->Release(); |
| 70 m_pSyntax->m_pFileAccess = nullptr; | 69 m_pSyntax->m_pFileAccess = nullptr; |
| 71 } | 70 } |
| 72 | 71 |
| 73 for (CPDF_Dictionary* trailer : m_Trailers) | 72 for (CPDF_Dictionary* trailer : m_Trailers) |
| 74 delete trailer; | 73 delete trailer; |
| 75 | |
| 76 delete m_pLinearized; | |
| 77 } | 74 } |
| 78 | 75 |
| 79 uint32_t CPDF_Parser::GetLastObjNum() const { | 76 uint32_t CPDF_Parser::GetLastObjNum() const { |
| 80 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; | 77 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; |
| 81 } | 78 } |
| 82 | 79 |
| 83 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const { | 80 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const { |
| 84 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; | 81 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; |
| 85 } | 82 } |
| 86 | 83 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 } else { | 724 } else { |
| 728 inside_index++; | 725 inside_index++; |
| 729 } | 726 } |
| 730 break; | 727 break; |
| 731 case 3: | 728 case 3: |
| 732 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { | 729 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { |
| 733 FX_FILESIZE obj_pos = start_pos - m_pSyntax->m_HeaderOffset; | 730 FX_FILESIZE obj_pos = start_pos - m_pSyntax->m_HeaderOffset; |
| 734 m_SortedOffset.insert(obj_pos); | 731 m_SortedOffset.insert(obj_pos); |
| 735 last_obj = start_pos; | 732 last_obj = start_pos; |
| 736 FX_FILESIZE obj_end = 0; | 733 FX_FILESIZE obj_end = 0; |
| 737 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( | 734 std::unique_ptr<CPDF_Object> pObject = |
| 738 m_pDocument, obj_pos, objnum, &obj_end); | 735 ParseIndirectObjectAtByStrict(m_pDocument, obj_pos, objnum, |
| 739 if (CPDF_Stream* pStream = ToStream(pObject)) { | 736 &obj_end); |
| 737 if (CPDF_Stream* pStream = ToStream(pObject.get())) { |
| 740 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 738 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
| 741 if ((pDict->KeyExist("Type")) && | 739 if ((pDict->KeyExist("Type")) && |
| 742 (pDict->GetStringFor("Type") == "XRef" && | 740 (pDict->GetStringFor("Type") == "XRef" && |
| 743 pDict->KeyExist("Size"))) { | 741 pDict->KeyExist("Size"))) { |
| 744 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); | 742 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); |
| 745 if (pRoot && pRoot->GetDict() && | 743 if (pRoot && pRoot->GetDict() && |
| 746 pRoot->GetDict()->GetObjectFor("Pages")) { | 744 pRoot->GetDict()->GetObjectFor("Pages")) { |
| 747 delete m_pTrailer; | 745 delete m_pTrailer; |
| 748 m_pTrailer = ToDictionary(pDict->Clone()); | 746 m_pTrailer = ToDictionary(pDict->Clone()); |
| 749 } | 747 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 774 m_ObjectInfo[objnum].pos = obj_pos; | 772 m_ObjectInfo[objnum].pos = obj_pos; |
| 775 m_ObjectInfo[objnum].gennum = gennum; | 773 m_ObjectInfo[objnum].gennum = gennum; |
| 776 if (oldgen != gennum) | 774 if (oldgen != gennum) |
| 777 m_bVersionUpdated = true; | 775 m_bVersionUpdated = true; |
| 778 } | 776 } |
| 779 } else { | 777 } else { |
| 780 m_ObjectInfo[objnum].pos = obj_pos; | 778 m_ObjectInfo[objnum].pos = obj_pos; |
| 781 m_ObjectInfo[objnum].type = 1; | 779 m_ObjectInfo[objnum].type = 1; |
| 782 m_ObjectInfo[objnum].gennum = gennum; | 780 m_ObjectInfo[objnum].gennum = gennum; |
| 783 } | 781 } |
| 784 | |
| 785 delete pObject; | |
| 786 } | 782 } |
| 787 --i; | 783 --i; |
| 788 state = ParserState::kDefault; | 784 state = ParserState::kDefault; |
| 789 break; | 785 break; |
| 790 } | 786 } |
| 791 break; | 787 break; |
| 792 | 788 |
| 793 case ParserState::kTrailer: | 789 case ParserState::kTrailer: |
| 794 if (inside_index == 7) { | 790 if (inside_index == 7) { |
| 795 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { | 791 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { |
| 796 last_trailer = pos + i - 7; | 792 last_trailer = pos + i - 7; |
| 797 m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset); | 793 m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset); |
| 798 | 794 |
| 799 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); | 795 std::unique_ptr<CPDF_Object> pObj = |
| 796 m_pSyntax->GetObject(m_pDocument, 0, 0, true); |
| 800 if (pObj) { | 797 if (pObj) { |
| 801 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 798 if (pObj->IsDictionary() || pObj->AsStream()) { |
| 802 delete pObj; | |
| 803 } else { | |
| 804 CPDF_Stream* pStream = pObj->AsStream(); | 799 CPDF_Stream* pStream = pObj->AsStream(); |
| 805 if (CPDF_Dictionary* pTrailer = | 800 if (CPDF_Dictionary* pTrailer = |
| 806 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 801 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
| 807 if (m_pTrailer) { | 802 if (m_pTrailer) { |
| 808 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); | 803 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); |
| 809 CPDF_Reference* pRef = ToReference(pRoot); | 804 CPDF_Reference* pRef = ToReference(pRoot); |
| 810 if (!pRoot || | 805 if (!pRoot || |
| 811 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 806 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
| 812 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 807 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
| 813 auto it = pTrailer->begin(); | 808 auto it = pTrailer->begin(); |
| 814 while (it != pTrailer->end()) { | 809 while (it != pTrailer->end()) { |
| 815 const CFX_ByteString& key = it->first; | 810 const CFX_ByteString& key = it->first; |
| 816 CPDF_Object* pElement = it->second; | 811 CPDF_Object* pElement = it->second; |
| 817 ++it; | 812 ++it; |
| 818 uint32_t dwObjNum = | 813 uint32_t dwObjNum = |
| 819 pElement ? pElement->GetObjNum() : 0; | 814 pElement ? pElement->GetObjNum() : 0; |
| 820 if (dwObjNum) { | 815 if (dwObjNum) { |
| 821 m_pTrailer->SetReferenceFor(key, m_pDocument, | 816 m_pTrailer->SetReferenceFor(key, m_pDocument, |
| 822 dwObjNum); | 817 dwObjNum); |
| 823 } else { | 818 } else { |
| 824 m_pTrailer->SetFor(key, pElement->Clone()); | 819 m_pTrailer->SetFor(key, pElement->Clone()); |
| 825 } | 820 } |
| 826 } | 821 } |
| 827 } | 822 } |
| 828 delete pObj; | |
| 829 } else { | 823 } else { |
| 830 if (pObj->IsStream()) { | 824 if (pObj->IsStream()) { |
| 831 m_pTrailer = ToDictionary(pTrailer->Clone()); | 825 m_pTrailer = ToDictionary(pTrailer->Clone()); |
| 832 delete pObj; | |
| 833 } else { | 826 } else { |
| 834 m_pTrailer = pTrailer; | 827 m_pTrailer = pTrailer; |
| 835 } | 828 } |
| 836 | 829 |
| 837 FX_FILESIZE dwSavePos = m_pSyntax->SavePos(); | 830 FX_FILESIZE dwSavePos = m_pSyntax->SavePos(); |
| 838 CFX_ByteString strWord = m_pSyntax->GetKeyword(); | 831 CFX_ByteString strWord = m_pSyntax->GetKeyword(); |
| 839 if (!strWord.Compare("startxref")) { | 832 if (!strWord.Compare("startxref")) { |
| 840 bool bNumber; | 833 bool bNumber; |
| 841 CFX_ByteString bsOffset = | 834 CFX_ByteString bsOffset = |
| 842 m_pSyntax->GetNextWord(&bNumber); | 835 m_pSyntax->GetNextWord(&bNumber); |
| 843 if (bNumber) | 836 if (bNumber) |
| 844 m_LastXRefOffset = FXSYS_atoi(bsOffset.c_str()); | 837 m_LastXRefOffset = FXSYS_atoi(bsOffset.c_str()); |
| 845 } | 838 } |
| 846 m_pSyntax->RestorePos(dwSavePos); | 839 m_pSyntax->RestorePos(dwSavePos); |
| 847 } | 840 } |
| 848 } else { | |
| 849 delete pObj; | |
| 850 } | 841 } |
| 851 } | 842 } |
| 852 } | 843 } |
| 853 } | 844 } |
| 854 --i; | 845 --i; |
| 855 state = ParserState::kDefault; | 846 state = ParserState::kDefault; |
| 856 } else if (byte == "trailer"[inside_index]) { | 847 } else if (byte == "trailer"[inside_index]) { |
| 857 inside_index++; | 848 inside_index++; |
| 858 } else { | 849 } else { |
| 859 --i; | 850 --i; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 } | 1074 } |
| 1084 return true; | 1075 return true; |
| 1085 } | 1076 } |
| 1086 | 1077 |
| 1087 CPDF_Array* CPDF_Parser::GetIDArray() { | 1078 CPDF_Array* CPDF_Parser::GetIDArray() { |
| 1088 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; | 1079 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; |
| 1089 if (!pID) | 1080 if (!pID) |
| 1090 return nullptr; | 1081 return nullptr; |
| 1091 | 1082 |
| 1092 if (CPDF_Reference* pRef = pID->AsReference()) { | 1083 if (CPDF_Reference* pRef = pID->AsReference()) { |
| 1093 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); | 1084 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release(); |
| 1094 m_pTrailer->SetFor("ID", pID); | 1085 m_pTrailer->SetFor("ID", pID); |
| 1095 } | 1086 } |
| 1096 return ToArray(pID); | 1087 return ToArray(pID); |
| 1097 } | 1088 } |
| 1098 | 1089 |
| 1099 uint32_t CPDF_Parser::GetRootObjNum() { | 1090 uint32_t CPDF_Parser::GetRootObjNum() { |
| 1100 CPDF_Reference* pRef = | 1091 CPDF_Reference* pRef = |
| 1101 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); | 1092 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); |
| 1102 return pRef ? pRef->GetRefObjNum() : 0; | 1093 return pRef ? pRef->GetRefObjNum() : 0; |
| 1103 } | 1094 } |
| 1104 | 1095 |
| 1105 uint32_t CPDF_Parser::GetInfoObjNum() { | 1096 uint32_t CPDF_Parser::GetInfoObjNum() { |
| 1106 CPDF_Reference* pRef = | 1097 CPDF_Reference* pRef = |
| 1107 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Info") : nullptr); | 1098 ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Info") : nullptr); |
| 1108 return pRef ? pRef->GetRefObjNum() : 0; | 1099 return pRef ? pRef->GetRefObjNum() : 0; |
| 1109 } | 1100 } |
| 1110 | 1101 |
| 1111 CPDF_Object* CPDF_Parser::ParseIndirectObject( | 1102 std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject( |
| 1112 CPDF_IndirectObjectHolder* pObjList, | 1103 CPDF_IndirectObjectHolder* pObjList, |
| 1113 uint32_t objnum) { | 1104 uint32_t objnum) { |
| 1114 if (!IsValidObjectNumber(objnum)) | 1105 if (!IsValidObjectNumber(objnum)) |
| 1115 return nullptr; | 1106 return nullptr; |
| 1116 | 1107 |
| 1117 // Prevent circular parsing the same object. | 1108 // Prevent circular parsing the same object. |
| 1118 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) | 1109 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) |
| 1119 return nullptr; | 1110 return nullptr; |
| 1120 | 1111 |
| 1121 pdfium::ScopedSetInsertion<uint32_t> local_insert(&m_ParsingObjNums, objnum); | 1112 pdfium::ScopedSetInsertion<uint32_t> local_insert(&m_ParsingObjNums, objnum); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 nextoff = m_pSyntax->SavePos(); | 1295 nextoff = m_pSyntax->SavePos(); |
| 1305 } | 1296 } |
| 1306 | 1297 |
| 1307 size = (uint32_t)(nextoff - pos); | 1298 size = (uint32_t)(nextoff - pos); |
| 1308 pBuffer = FX_Alloc(uint8_t, size); | 1299 pBuffer = FX_Alloc(uint8_t, size); |
| 1309 m_pSyntax->RestorePos(pos); | 1300 m_pSyntax->RestorePos(pos); |
| 1310 m_pSyntax->ReadBlock(pBuffer, size); | 1301 m_pSyntax->ReadBlock(pBuffer, size); |
| 1311 m_pSyntax->RestorePos(SavedPos); | 1302 m_pSyntax->RestorePos(SavedPos); |
| 1312 } | 1303 } |
| 1313 | 1304 |
| 1314 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt( | 1305 std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObjectAt( |
| 1315 CPDF_IndirectObjectHolder* pObjList, | 1306 CPDF_IndirectObjectHolder* pObjList, |
| 1316 FX_FILESIZE pos, | 1307 FX_FILESIZE pos, |
| 1317 uint32_t objnum) { | 1308 uint32_t objnum) { |
| 1318 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1309 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
| 1319 m_pSyntax->RestorePos(pos); | 1310 m_pSyntax->RestorePos(pos); |
| 1320 bool bIsNumber; | 1311 bool bIsNumber; |
| 1321 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1312 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
| 1322 if (!bIsNumber) { | 1313 if (!bIsNumber) { |
| 1323 m_pSyntax->RestorePos(SavedPos); | 1314 m_pSyntax->RestorePos(SavedPos); |
| 1324 return nullptr; | 1315 return nullptr; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1337 m_pSyntax->RestorePos(SavedPos); | 1328 m_pSyntax->RestorePos(SavedPos); |
| 1338 return nullptr; | 1329 return nullptr; |
| 1339 } | 1330 } |
| 1340 | 1331 |
| 1341 uint32_t parser_gennum = FXSYS_atoui(word.c_str()); | 1332 uint32_t parser_gennum = FXSYS_atoui(word.c_str()); |
| 1342 if (m_pSyntax->GetKeyword() != "obj") { | 1333 if (m_pSyntax->GetKeyword() != "obj") { |
| 1343 m_pSyntax->RestorePos(SavedPos); | 1334 m_pSyntax->RestorePos(SavedPos); |
| 1344 return nullptr; | 1335 return nullptr; |
| 1345 } | 1336 } |
| 1346 | 1337 |
| 1347 CPDF_Object* pObj = | 1338 std::unique_ptr<CPDF_Object> pObj = |
| 1348 m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true); | 1339 m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true); |
| 1349 m_pSyntax->SavePos(); | 1340 m_pSyntax->SavePos(); |
| 1350 | 1341 |
| 1351 CFX_ByteString bsWord = m_pSyntax->GetKeyword(); | 1342 CFX_ByteString bsWord = m_pSyntax->GetKeyword(); |
| 1352 if (bsWord == "endobj") | 1343 if (bsWord == "endobj") |
| 1353 m_pSyntax->SavePos(); | 1344 m_pSyntax->SavePos(); |
| 1354 | 1345 |
| 1355 m_pSyntax->RestorePos(SavedPos); | 1346 m_pSyntax->RestorePos(SavedPos); |
| 1356 if (pObj) { | 1347 if (pObj) { |
| 1357 if (!objnum) | 1348 if (!objnum) |
| 1358 pObj->m_ObjNum = parser_objnum; | 1349 pObj->m_ObjNum = parser_objnum; |
| 1359 pObj->m_GenNum = parser_gennum; | 1350 pObj->m_GenNum = parser_gennum; |
| 1360 } | 1351 } |
| 1361 return pObj; | 1352 return pObj; |
| 1362 } | 1353 } |
| 1363 | 1354 |
| 1364 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 1355 std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObjectAtByStrict( |
| 1365 CPDF_IndirectObjectHolder* pObjList, | 1356 CPDF_IndirectObjectHolder* pObjList, |
| 1366 FX_FILESIZE pos, | 1357 FX_FILESIZE pos, |
| 1367 uint32_t objnum, | 1358 uint32_t objnum, |
| 1368 FX_FILESIZE* pResultPos) { | 1359 FX_FILESIZE* pResultPos) { |
| 1369 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1360 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
| 1370 m_pSyntax->RestorePos(pos); | 1361 m_pSyntax->RestorePos(pos); |
| 1371 | 1362 |
| 1372 bool bIsNumber; | 1363 bool bIsNumber; |
| 1373 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1364 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
| 1374 if (!bIsNumber) { | 1365 if (!bIsNumber) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1387 m_pSyntax->RestorePos(SavedPos); | 1378 m_pSyntax->RestorePos(SavedPos); |
| 1388 return nullptr; | 1379 return nullptr; |
| 1389 } | 1380 } |
| 1390 | 1381 |
| 1391 uint32_t gennum = FXSYS_atoui(word.c_str()); | 1382 uint32_t gennum = FXSYS_atoui(word.c_str()); |
| 1392 if (m_pSyntax->GetKeyword() != "obj") { | 1383 if (m_pSyntax->GetKeyword() != "obj") { |
| 1393 m_pSyntax->RestorePos(SavedPos); | 1384 m_pSyntax->RestorePos(SavedPos); |
| 1394 return nullptr; | 1385 return nullptr; |
| 1395 } | 1386 } |
| 1396 | 1387 |
| 1397 CPDF_Object* pObj = m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum); | 1388 std::unique_ptr<CPDF_Object> pObj = |
| 1389 m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum); |
| 1390 |
| 1398 if (pResultPos) | 1391 if (pResultPos) |
| 1399 *pResultPos = m_pSyntax->m_Pos; | 1392 *pResultPos = m_pSyntax->m_Pos; |
| 1400 | 1393 |
| 1401 m_pSyntax->RestorePos(SavedPos); | 1394 m_pSyntax->RestorePos(SavedPos); |
| 1402 return pObj; | 1395 return pObj; |
| 1403 } | 1396 } |
| 1404 | 1397 |
| 1405 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { | 1398 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { |
| 1406 if (m_pSyntax->GetKeyword() != "trailer") | 1399 if (m_pSyntax->GetKeyword() != "trailer") |
| 1407 return nullptr; | 1400 return nullptr; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 if (m_pSyntax->GetKeyword() != "obj") { | 1439 if (m_pSyntax->GetKeyword() != "obj") { |
| 1447 m_pSyntax->RestorePos(SavedPos); | 1440 m_pSyntax->RestorePos(SavedPos); |
| 1448 return false; | 1441 return false; |
| 1449 } | 1442 } |
| 1450 | 1443 |
| 1451 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); | 1444 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); |
| 1452 if (!m_pLinearized) | 1445 if (!m_pLinearized) |
| 1453 return false; | 1446 return false; |
| 1454 | 1447 |
| 1455 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1448 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1456 if (pDict && pDict->GetObjectFor("Linearized")) { | 1449 if (!pDict || !pDict->GetObjectFor("Linearized")) { |
| 1457 m_pSyntax->GetNextWord(nullptr); | 1450 m_pLinearized.reset(); |
| 1451 return false; |
| 1452 } |
| 1458 | 1453 |
| 1459 CPDF_Object* pLen = pDict->GetObjectFor("L"); | 1454 m_pSyntax->GetNextWord(nullptr); |
| 1460 if (!pLen) { | |
| 1461 delete m_pLinearized; | |
| 1462 m_pLinearized = nullptr; | |
| 1463 return false; | |
| 1464 } | |
| 1465 | 1455 |
| 1466 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) | 1456 CPDF_Object* pLen = pDict->GetObjectFor("L"); |
| 1467 return false; | 1457 if (!pLen) { |
| 1458 m_pLinearized.reset(); |
| 1459 return false; |
| 1460 } |
| 1468 | 1461 |
| 1469 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) | 1462 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) |
| 1470 m_dwFirstPageNo = pNo->GetInteger(); | 1463 return false; |
| 1471 | 1464 |
| 1472 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) | 1465 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) |
| 1473 m_LastXRefOffset = pTable->GetInteger(); | 1466 m_dwFirstPageNo = pNo->GetInteger(); |
| 1474 | 1467 |
| 1475 return true; | 1468 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) |
| 1476 } | 1469 m_LastXRefOffset = pTable->GetInteger(); |
| 1477 delete m_pLinearized; | 1470 |
| 1478 m_pLinearized = nullptr; | 1471 return true; |
| 1479 return false; | |
| 1480 } | 1472 } |
| 1481 | 1473 |
| 1482 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( | 1474 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( |
| 1483 IFX_SeekableReadStream* pFileAccess, | 1475 IFX_SeekableReadStream* pFileAccess, |
| 1484 CPDF_Document* pDocument) { | 1476 CPDF_Document* pDocument) { |
| 1485 ASSERT(!m_bHasParsed); | 1477 ASSERT(!m_bHasParsed); |
| 1486 | 1478 |
| 1487 m_bXRefStream = false; | 1479 m_bXRefStream = false; |
| 1488 m_LastXRefOffset = 0; | 1480 m_LastXRefOffset = 0; |
| 1489 m_bOwnFileRead = true; | 1481 m_bOwnFileRead = true; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1598 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
| 1607 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1599 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
| 1608 m_LastXRefOffset = 0; | 1600 m_LastXRefOffset = 0; |
| 1609 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1601 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1610 return FORMAT_ERROR; | 1602 return FORMAT_ERROR; |
| 1611 } | 1603 } |
| 1612 | 1604 |
| 1613 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1605 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1614 return SUCCESS; | 1606 return SUCCESS; |
| 1615 } | 1607 } |
| OLD | NEW |