| 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/cpdf_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_parser.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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), | 57 m_pLinearized(nullptr), |
| 58 m_dwFirstPageNo(0), | 58 m_dwFirstPageNo(0), |
| 59 m_dwXrefStartObjNum(0) { | 59 m_dwXrefStartObjNum(0) { |
| 60 m_pSyntax.reset(new CPDF_SyntaxParser); | 60 m_pSyntax.reset(new CPDF_SyntaxParser); |
| 61 } | 61 } |
| 62 | 62 |
| 63 CPDF_Parser::~CPDF_Parser() { | 63 CPDF_Parser::~CPDF_Parser() { |
| 64 if (m_pTrailer) | 64 delete m_pTrailer; |
| 65 m_pTrailer->Release(); | |
| 66 | |
| 67 ReleaseEncryptHandler(); | 65 ReleaseEncryptHandler(); |
| 68 SetEncryptDictionary(nullptr); | 66 SetEncryptDictionary(nullptr); |
| 69 | 67 |
| 70 if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) { | 68 if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) { |
| 71 m_pSyntax->m_pFileAccess->Release(); | 69 m_pSyntax->m_pFileAccess->Release(); |
| 72 m_pSyntax->m_pFileAccess = nullptr; | 70 m_pSyntax->m_pFileAccess = nullptr; |
| 73 } | 71 } |
| 74 | 72 |
| 75 int32_t iLen = m_Trailers.GetSize(); | 73 int32_t iLen = m_Trailers.GetSize(); |
| 76 for (int32_t i = 0; i < iLen; ++i) { | 74 for (int32_t i = 0; i < iLen; ++i) |
| 77 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) | 75 delete m_Trailers.GetAt(i); |
| 78 trailer->Release(); | |
| 79 } | |
| 80 | 76 |
| 81 if (m_pLinearized) | 77 delete m_pLinearized; |
| 82 m_pLinearized->Release(); | |
| 83 } | 78 } |
| 84 | 79 |
| 85 uint32_t CPDF_Parser::GetLastObjNum() const { | 80 uint32_t CPDF_Parser::GetLastObjNum() const { |
| 86 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; | 81 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; |
| 87 } | 82 } |
| 88 | 83 |
| 89 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const { | 84 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const { |
| 90 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; | 85 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; |
| 91 } | 86 } |
| 92 | 87 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // Check for circular references. | 346 // Check for circular references. |
| 352 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) | 347 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) |
| 353 return FALSE; | 348 return FALSE; |
| 354 | 349 |
| 355 seen_xrefpos.insert(xrefpos); | 350 seen_xrefpos.insert(xrefpos); |
| 356 | 351 |
| 357 // SLOW ... | 352 // SLOW ... |
| 358 CrossRefList.insert(CrossRefList.begin(), xrefpos); | 353 CrossRefList.insert(CrossRefList.begin(), xrefpos); |
| 359 LoadCrossRefV4(xrefpos, 0, TRUE); | 354 LoadCrossRefV4(xrefpos, 0, TRUE); |
| 360 | 355 |
| 361 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 356 std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); |
| 362 LoadTrailerV4()); | |
| 363 if (!pDict) | 357 if (!pDict) |
| 364 return FALSE; | 358 return FALSE; |
| 365 | 359 |
| 366 xrefpos = GetDirectInteger(pDict.get(), "Prev"); | 360 xrefpos = GetDirectInteger(pDict.get(), "Prev"); |
| 367 | 361 |
| 368 // SLOW ... | 362 // SLOW ... |
| 369 XRefStreamList.insert(XRefStreamList.begin(), | 363 XRefStreamList.insert(XRefStreamList.begin(), |
| 370 pDict->GetIntegerFor("XRefStm")); | 364 pDict->GetIntegerFor("XRefStm")); |
| 371 m_Trailers.Add(pDict.release()); | 365 m_Trailers.Add(pDict.release()); |
| 372 } | 366 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // Check for circular references. | 400 // Check for circular references. |
| 407 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) | 401 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) |
| 408 return FALSE; | 402 return FALSE; |
| 409 | 403 |
| 410 seen_xrefpos.insert(xrefpos); | 404 seen_xrefpos.insert(xrefpos); |
| 411 | 405 |
| 412 // SLOW ... | 406 // SLOW ... |
| 413 CrossRefList.insert(CrossRefList.begin(), xrefpos); | 407 CrossRefList.insert(CrossRefList.begin(), xrefpos); |
| 414 LoadCrossRefV4(xrefpos, 0, TRUE); | 408 LoadCrossRefV4(xrefpos, 0, TRUE); |
| 415 | 409 |
| 416 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 410 std::unique_ptr<CPDF_Dictionary> pDict(LoadTrailerV4()); |
| 417 LoadTrailerV4()); | |
| 418 if (!pDict) | 411 if (!pDict) |
| 419 return FALSE; | 412 return FALSE; |
| 420 | 413 |
| 421 xrefpos = GetDirectInteger(pDict.get(), "Prev"); | 414 xrefpos = GetDirectInteger(pDict.get(), "Prev"); |
| 422 | 415 |
| 423 // SLOW ... | 416 // SLOW ... |
| 424 XRefStreamList.insert(XRefStreamList.begin(), | 417 XRefStreamList.insert(XRefStreamList.begin(), |
| 425 pDict->GetIntegerFor("XRefStm")); | 418 pDict->GetIntegerFor("XRefStm")); |
| 426 m_Trailers.Add(pDict.release()); | 419 m_Trailers.Add(pDict.release()); |
| 427 } | 420 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 return FALSE; | 577 return FALSE; |
| 585 } | 578 } |
| 586 m_ObjectStreamMap.clear(); | 579 m_ObjectStreamMap.clear(); |
| 587 m_bXRefStream = TRUE; | 580 m_bXRefStream = TRUE; |
| 588 return TRUE; | 581 return TRUE; |
| 589 } | 582 } |
| 590 | 583 |
| 591 FX_BOOL CPDF_Parser::RebuildCrossRef() { | 584 FX_BOOL CPDF_Parser::RebuildCrossRef() { |
| 592 m_ObjectInfo.clear(); | 585 m_ObjectInfo.clear(); |
| 593 m_SortedOffset.clear(); | 586 m_SortedOffset.clear(); |
| 594 if (m_pTrailer) { | 587 delete m_pTrailer; |
| 595 m_pTrailer->Release(); | 588 m_pTrailer = nullptr; |
| 596 m_pTrailer = nullptr; | |
| 597 } | |
| 598 | 589 |
| 599 ParserState state = ParserState::kDefault; | 590 ParserState state = ParserState::kDefault; |
| 600 | |
| 601 int32_t inside_index = 0; | 591 int32_t inside_index = 0; |
| 602 uint32_t objnum = 0; | 592 uint32_t objnum = 0; |
| 603 uint32_t gennum = 0; | 593 uint32_t gennum = 0; |
| 604 int32_t depth = 0; | 594 int32_t depth = 0; |
| 605 | |
| 606 const uint32_t kBufferSize = 4096; | 595 const uint32_t kBufferSize = 4096; |
| 607 std::vector<uint8_t> buffer(kBufferSize); | 596 std::vector<uint8_t> buffer(kBufferSize); |
| 608 | 597 |
| 609 FX_FILESIZE pos = m_pSyntax->m_HeaderOffset; | 598 FX_FILESIZE pos = m_pSyntax->m_HeaderOffset; |
| 610 FX_FILESIZE start_pos = 0; | 599 FX_FILESIZE start_pos = 0; |
| 611 FX_FILESIZE start_pos1 = 0; | 600 FX_FILESIZE start_pos1 = 0; |
| 612 FX_FILESIZE last_obj = -1; | 601 FX_FILESIZE last_obj = -1; |
| 613 FX_FILESIZE last_xref = -1; | 602 FX_FILESIZE last_xref = -1; |
| 614 FX_FILESIZE last_trailer = -1; | 603 FX_FILESIZE last_trailer = -1; |
| 615 | 604 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 m_pDocument, obj_pos, objnum, &obj_end); | 739 m_pDocument, obj_pos, objnum, &obj_end); |
| 751 if (CPDF_Stream* pStream = ToStream(pObject)) { | 740 if (CPDF_Stream* pStream = ToStream(pObject)) { |
| 752 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 741 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
| 753 if ((pDict->KeyExist("Type")) && | 742 if ((pDict->KeyExist("Type")) && |
| 754 (pDict->GetStringFor("Type") == "XRef" && | 743 (pDict->GetStringFor("Type") == "XRef" && |
| 755 pDict->KeyExist("Size"))) { | 744 pDict->KeyExist("Size"))) { |
| 756 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); | 745 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); |
| 757 if (pRoot && pRoot->GetDict() && | 746 if (pRoot && pRoot->GetDict() && |
| 758 pRoot->GetDict()->GetObjectFor("Pages")) { | 747 pRoot->GetDict()->GetObjectFor("Pages")) { |
| 759 if (m_pTrailer) | 748 if (m_pTrailer) |
| 760 m_pTrailer->Release(); | 749 delete m_pTrailer; |
| 761 m_pTrailer = ToDictionary(pDict->Clone()); | 750 m_pTrailer = ToDictionary(pDict->Clone()); |
| 762 } | 751 } |
| 763 } | 752 } |
| 764 } | 753 } |
| 765 } | 754 } |
| 766 | 755 |
| 767 FX_FILESIZE offset = 0; | 756 FX_FILESIZE offset = 0; |
| 768 m_pSyntax->RestorePos(obj_pos); | 757 m_pSyntax->RestorePos(obj_pos); |
| 769 offset = m_pSyntax->FindTag("obj", 0); | 758 offset = m_pSyntax->FindTag("obj", 0); |
| 770 if (offset == -1) | 759 if (offset == -1) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 788 m_ObjectInfo[objnum].gennum = gennum; | 777 m_ObjectInfo[objnum].gennum = gennum; |
| 789 if (oldgen != gennum) | 778 if (oldgen != gennum) |
| 790 m_bVersionUpdated = true; | 779 m_bVersionUpdated = true; |
| 791 } | 780 } |
| 792 } else { | 781 } else { |
| 793 m_ObjectInfo[objnum].pos = obj_pos; | 782 m_ObjectInfo[objnum].pos = obj_pos; |
| 794 m_ObjectInfo[objnum].type = 1; | 783 m_ObjectInfo[objnum].type = 1; |
| 795 m_ObjectInfo[objnum].gennum = gennum; | 784 m_ObjectInfo[objnum].gennum = gennum; |
| 796 } | 785 } |
| 797 | 786 |
| 798 if (pObject) | 787 delete pObject; |
| 799 pObject->Release(); | |
| 800 } | 788 } |
| 801 --i; | 789 --i; |
| 802 state = ParserState::kDefault; | 790 state = ParserState::kDefault; |
| 803 break; | 791 break; |
| 804 } | 792 } |
| 805 break; | 793 break; |
| 806 | 794 |
| 807 case ParserState::kTrailer: | 795 case ParserState::kTrailer: |
| 808 if (inside_index == 7) { | 796 if (inside_index == 7) { |
| 809 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { | 797 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { |
| 810 last_trailer = pos + i - 7; | 798 last_trailer = pos + i - 7; |
| 811 m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset); | 799 m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset); |
| 812 | 800 |
| 813 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); | 801 CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); |
| 814 if (pObj) { | 802 if (pObj) { |
| 815 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 803 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
| 816 pObj->Release(); | 804 delete pObj; |
| 817 } else { | 805 } else { |
| 818 CPDF_Stream* pStream = pObj->AsStream(); | 806 CPDF_Stream* pStream = pObj->AsStream(); |
| 819 if (CPDF_Dictionary* pTrailer = | 807 if (CPDF_Dictionary* pTrailer = |
| 820 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 808 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
| 821 if (m_pTrailer) { | 809 if (m_pTrailer) { |
| 822 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); | 810 CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); |
| 823 CPDF_Reference* pRef = ToReference(pRoot); | 811 CPDF_Reference* pRef = ToReference(pRoot); |
| 824 if (!pRoot || | 812 if (!pRoot || |
| 825 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 813 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
| 826 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 814 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
| 827 auto it = pTrailer->begin(); | 815 auto it = pTrailer->begin(); |
| 828 while (it != pTrailer->end()) { | 816 while (it != pTrailer->end()) { |
| 829 const CFX_ByteString& key = it->first; | 817 const CFX_ByteString& key = it->first; |
| 830 CPDF_Object* pElement = it->second; | 818 CPDF_Object* pElement = it->second; |
| 831 ++it; | 819 ++it; |
| 832 uint32_t dwObjNum = | 820 uint32_t dwObjNum = |
| 833 pElement ? pElement->GetObjNum() : 0; | 821 pElement ? pElement->GetObjNum() : 0; |
| 834 if (dwObjNum) { | 822 if (dwObjNum) { |
| 835 m_pTrailer->SetReferenceFor(key, m_pDocument, | 823 m_pTrailer->SetReferenceFor(key, m_pDocument, |
| 836 dwObjNum); | 824 dwObjNum); |
| 837 } else { | 825 } else { |
| 838 m_pTrailer->SetFor(key, pElement->Clone()); | 826 m_pTrailer->SetFor(key, pElement->Clone()); |
| 839 } | 827 } |
| 840 } | 828 } |
| 841 } | 829 } |
| 842 pObj->Release(); | 830 delete pObj; |
| 843 } else { | 831 } else { |
| 844 if (pObj->IsStream()) { | 832 if (pObj->IsStream()) { |
| 845 m_pTrailer = ToDictionary(pTrailer->Clone()); | 833 m_pTrailer = ToDictionary(pTrailer->Clone()); |
| 846 pObj->Release(); | 834 delete pObj; |
| 847 } else { | 835 } else { |
| 848 m_pTrailer = pTrailer; | 836 m_pTrailer = pTrailer; |
| 849 } | 837 } |
| 850 | 838 |
| 851 FX_FILESIZE dwSavePos = m_pSyntax->SavePos(); | 839 FX_FILESIZE dwSavePos = m_pSyntax->SavePos(); |
| 852 CFX_ByteString strWord = m_pSyntax->GetKeyword(); | 840 CFX_ByteString strWord = m_pSyntax->GetKeyword(); |
| 853 if (!strWord.Compare("startxref")) { | 841 if (!strWord.Compare("startxref")) { |
| 854 bool bNumber; | 842 bool bNumber; |
| 855 CFX_ByteString bsOffset = | 843 CFX_ByteString bsOffset = |
| 856 m_pSyntax->GetNextWord(&bNumber); | 844 m_pSyntax->GetNextWord(&bNumber); |
| 857 if (bNumber) | 845 if (bNumber) |
| 858 m_LastXRefOffset = FXSYS_atoi(bsOffset.c_str()); | 846 m_LastXRefOffset = FXSYS_atoi(bsOffset.c_str()); |
| 859 } | 847 } |
| 860 m_pSyntax->RestorePos(dwSavePos); | 848 m_pSyntax->RestorePos(dwSavePos); |
| 861 } | 849 } |
| 862 } else { | 850 } else { |
| 863 pObj->Release(); | 851 delete pObj; |
| 864 } | 852 } |
| 865 } | 853 } |
| 866 } | 854 } |
| 867 } | 855 } |
| 868 --i; | 856 --i; |
| 869 state = ParserState::kDefault; | 857 state = ParserState::kDefault; |
| 870 } else if (byte == "trailer"[inside_index]) { | 858 } else if (byte == "trailer"[inside_index]) { |
| 871 inside_index++; | 859 inside_index++; |
| 872 } else { | 860 } else { |
| 873 --i; | 861 --i; |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 *pResultPos = m_pSyntax->m_Pos; | 1398 *pResultPos = m_pSyntax->m_Pos; |
| 1411 | 1399 |
| 1412 m_pSyntax->RestorePos(SavedPos); | 1400 m_pSyntax->RestorePos(SavedPos); |
| 1413 return pObj; | 1401 return pObj; |
| 1414 } | 1402 } |
| 1415 | 1403 |
| 1416 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { | 1404 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { |
| 1417 if (m_pSyntax->GetKeyword() != "trailer") | 1405 if (m_pSyntax->GetKeyword() != "trailer") |
| 1418 return nullptr; | 1406 return nullptr; |
| 1419 | 1407 |
| 1420 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 1408 std::unique_ptr<CPDF_Object> pObj( |
| 1421 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); | 1409 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); |
| 1422 if (!ToDictionary(pObj.get())) | 1410 if (!ToDictionary(pObj.get())) |
| 1423 return nullptr; | 1411 return nullptr; |
| 1424 return pObj.release()->AsDictionary(); | 1412 return pObj.release()->AsDictionary(); |
| 1425 } | 1413 } |
| 1426 | 1414 |
| 1427 uint32_t CPDF_Parser::GetPermissions() const { | 1415 uint32_t CPDF_Parser::GetPermissions() const { |
| 1428 if (!m_pSecurityHandler) | 1416 if (!m_pSecurityHandler) |
| 1429 return 0xFFFFFFFF; | 1417 return 0xFFFFFFFF; |
| 1430 | 1418 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); | 1450 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); |
| 1463 if (!m_pLinearized) | 1451 if (!m_pLinearized) |
| 1464 return FALSE; | 1452 return FALSE; |
| 1465 | 1453 |
| 1466 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1454 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1467 if (pDict && pDict->GetObjectFor("Linearized")) { | 1455 if (pDict && pDict->GetObjectFor("Linearized")) { |
| 1468 m_pSyntax->GetNextWord(nullptr); | 1456 m_pSyntax->GetNextWord(nullptr); |
| 1469 | 1457 |
| 1470 CPDF_Object* pLen = pDict->GetObjectFor("L"); | 1458 CPDF_Object* pLen = pDict->GetObjectFor("L"); |
| 1471 if (!pLen) { | 1459 if (!pLen) { |
| 1472 m_pLinearized->Release(); | 1460 delete m_pLinearized; |
| 1473 m_pLinearized = nullptr; | 1461 m_pLinearized = nullptr; |
| 1474 return FALSE; | 1462 return FALSE; |
| 1475 } | 1463 } |
| 1476 | 1464 |
| 1477 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) | 1465 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) |
| 1478 return FALSE; | 1466 return FALSE; |
| 1479 | 1467 |
| 1480 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) | 1468 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) |
| 1481 m_dwFirstPageNo = pNo->GetInteger(); | 1469 m_dwFirstPageNo = pNo->GetInteger(); |
| 1482 | 1470 |
| 1483 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) | 1471 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) |
| 1484 m_LastXRefOffset = pTable->GetInteger(); | 1472 m_LastXRefOffset = pTable->GetInteger(); |
| 1485 | 1473 |
| 1486 return TRUE; | 1474 return TRUE; |
| 1487 } | 1475 } |
| 1488 m_pLinearized->Release(); | 1476 delete m_pLinearized; |
| 1489 m_pLinearized = nullptr; | 1477 m_pLinearized = nullptr; |
| 1490 return FALSE; | 1478 return FALSE; |
| 1491 } | 1479 } |
| 1492 | 1480 |
| 1493 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(IFX_FileRead* pFileAccess, | 1481 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(IFX_FileRead* pFileAccess, |
| 1494 CPDF_Document* pDocument) { | 1482 CPDF_Document* pDocument) { |
| 1495 ASSERT(!m_bHasParsed); | 1483 ASSERT(!m_bHasParsed); |
| 1496 | 1484 |
| 1497 m_bXRefStream = FALSE; | 1485 m_bXRefStream = FALSE; |
| 1498 m_LastXRefOffset = 0; | 1486 m_LastXRefOffset = 0; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 return FALSE; | 1574 return FALSE; |
| 1587 } | 1575 } |
| 1588 m_ObjectStreamMap.clear(); | 1576 m_ObjectStreamMap.clear(); |
| 1589 m_bXRefStream = TRUE; | 1577 m_bXRefStream = TRUE; |
| 1590 return TRUE; | 1578 return TRUE; |
| 1591 } | 1579 } |
| 1592 | 1580 |
| 1593 CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { | 1581 CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { |
| 1594 uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; | 1582 uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; |
| 1595 m_pSyntax->m_MetadataObjnum = 0; | 1583 m_pSyntax->m_MetadataObjnum = 0; |
| 1596 if (m_pTrailer) { | |
| 1597 m_pTrailer->Release(); | |
| 1598 m_pTrailer = nullptr; | |
| 1599 } | |
| 1600 | 1584 |
| 1585 delete m_pTrailer; |
| 1586 m_pTrailer = nullptr; |
| 1601 m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); | 1587 m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); |
| 1588 |
| 1602 uint8_t ch = 0; | 1589 uint8_t ch = 0; |
| 1603 uint32_t dwCount = 0; | 1590 uint32_t dwCount = 0; |
| 1604 m_pSyntax->GetNextChar(ch); | 1591 m_pSyntax->GetNextChar(ch); |
| 1605 while (PDFCharIsWhitespace(ch)) { | 1592 while (PDFCharIsWhitespace(ch)) { |
| 1606 ++dwCount; | 1593 ++dwCount; |
| 1607 if (m_pSyntax->m_FileLen >= | 1594 if (m_pSyntax->m_FileLen >= |
| 1608 (FX_FILESIZE)(m_pSyntax->SavePos() + m_pSyntax->m_HeaderOffset)) { | 1595 (FX_FILESIZE)(m_pSyntax->SavePos() + m_pSyntax->m_HeaderOffset)) { |
| 1609 break; | 1596 break; |
| 1610 } | 1597 } |
| 1611 m_pSyntax->GetNextChar(ch); | 1598 m_pSyntax->GetNextChar(ch); |
| 1612 } | 1599 } |
| 1613 m_LastXRefOffset += dwCount; | 1600 m_LastXRefOffset += dwCount; |
| 1614 m_ObjectStreamMap.clear(); | 1601 m_ObjectStreamMap.clear(); |
| 1615 m_ObjCache.clear(); | 1602 m_ObjCache.clear(); |
| 1616 | 1603 |
| 1617 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1604 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
| 1618 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1605 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
| 1619 m_LastXRefOffset = 0; | 1606 m_LastXRefOffset = 0; |
| 1620 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1607 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1621 return FORMAT_ERROR; | 1608 return FORMAT_ERROR; |
| 1622 } | 1609 } |
| 1623 | 1610 |
| 1624 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1611 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1625 return SUCCESS; | 1612 return SUCCESS; |
| 1626 } | 1613 } |
| OLD | NEW |