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_data_avail.h" | 7 #include "core/fpdfapi/parser/cpdf_data_avail.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
14 #include "core/fpdfapi/parser/cpdf_array.h" | 14 #include "core/fpdfapi/parser/cpdf_array.h" |
15 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 15 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
16 #include "core/fpdfapi/parser/cpdf_document.h" | 16 #include "core/fpdfapi/parser/cpdf_document.h" |
17 #include "core/fpdfapi/parser/cpdf_hint_tables.h" | 17 #include "core/fpdfapi/parser/cpdf_hint_tables.h" |
| 18 #include "core/fpdfapi/parser/cpdf_linearized.h" |
18 #include "core/fpdfapi/parser/cpdf_name.h" | 19 #include "core/fpdfapi/parser/cpdf_name.h" |
19 #include "core/fpdfapi/parser/cpdf_number.h" | 20 #include "core/fpdfapi/parser/cpdf_number.h" |
20 #include "core/fpdfapi/parser/cpdf_reference.h" | 21 #include "core/fpdfapi/parser/cpdf_reference.h" |
21 #include "core/fpdfapi/parser/cpdf_stream.h" | 22 #include "core/fpdfapi/parser/cpdf_stream.h" |
22 #include "core/fpdfapi/parser/fpdf_parser_utility.h" | 23 #include "core/fpdfapi/parser/fpdf_parser_utility.h" |
23 #include "core/fxcrt/fx_ext.h" | 24 #include "core/fxcrt/fx_ext.h" |
24 #include "core/fxcrt/fx_safe_types.h" | 25 #include "core/fxcrt/fx_safe_types.h" |
25 #include "third_party/base/stl_util.h" | 26 #include "third_party/base/stl_util.h" |
26 | 27 |
27 CPDF_DataAvail::FileAvail::~FileAvail() {} | 28 CPDF_DataAvail::FileAvail::~FileAvail() {} |
28 | 29 |
29 CPDF_DataAvail::DownloadHints::~DownloadHints() {} | 30 CPDF_DataAvail::DownloadHints::~DownloadHints() {} |
30 | 31 |
31 // static | 32 // static |
32 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; | 33 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; |
33 | 34 |
34 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, | 35 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, |
35 IFX_SeekableReadStream* pFileRead, | 36 IFX_SeekableReadStream* pFileRead, |
36 bool bSupportHintTable) | 37 bool bSupportHintTable) |
37 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { | 38 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { |
38 m_Pos = 0; | 39 m_Pos = 0; |
39 m_dwFileLen = 0; | 40 m_dwFileLen = 0; |
40 if (m_pFileRead) { | 41 if (m_pFileRead) { |
41 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); | 42 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
42 } | 43 } |
43 m_dwCurrentOffset = 0; | 44 m_dwCurrentOffset = 0; |
44 m_dwXRefOffset = 0; | 45 m_dwXRefOffset = 0; |
45 m_bufferOffset = 0; | 46 m_bufferOffset = 0; |
46 m_dwFirstPageNo = 0; | |
47 m_bufferSize = 0; | 47 m_bufferSize = 0; |
48 m_PagesObjNum = 0; | 48 m_PagesObjNum = 0; |
49 m_dwCurrentXRefSteam = 0; | 49 m_dwCurrentXRefSteam = 0; |
50 m_dwAcroFormObjNum = 0; | 50 m_dwAcroFormObjNum = 0; |
51 m_dwInfoObjNum = 0; | 51 m_dwInfoObjNum = 0; |
52 m_pDocument = 0; | 52 m_pDocument = 0; |
53 m_dwEncryptObjNum = 0; | 53 m_dwEncryptObjNum = 0; |
54 m_dwPrevXRefOffset = 0; | 54 m_dwPrevXRefOffset = 0; |
55 m_dwLastXRefOffset = 0; | 55 m_dwLastXRefOffset = 0; |
56 m_bDocAvail = false; | 56 m_bDocAvail = false; |
57 m_bMainXRefLoadTried = false; | 57 m_bMainXRefLoadTried = false; |
58 m_bDocAvail = false; | 58 m_bDocAvail = false; |
59 m_bLinearized = false; | |
60 m_bPagesLoad = false; | 59 m_bPagesLoad = false; |
61 m_bPagesTreeLoad = false; | 60 m_bPagesTreeLoad = false; |
62 m_bMainXRefLoadedOK = false; | 61 m_bMainXRefLoadedOK = false; |
63 m_bAnnotsLoad = false; | 62 m_bAnnotsLoad = false; |
64 m_bHaveAcroForm = false; | 63 m_bHaveAcroForm = false; |
65 m_bAcroFormLoad = false; | 64 m_bAcroFormLoad = false; |
66 m_bPageLoadedOK = false; | 65 m_bPageLoadedOK = false; |
67 m_bNeedDownLoadResource = false; | 66 m_bNeedDownLoadResource = false; |
68 m_bLinearizedFormParamLoad = false; | 67 m_bLinearizedFormParamLoad = false; |
69 m_pLinearized = nullptr; | |
70 m_pRoot = nullptr; | 68 m_pRoot = nullptr; |
71 m_pTrailer = nullptr; | 69 m_pTrailer = nullptr; |
72 m_pCurrentParser = nullptr; | 70 m_pCurrentParser = nullptr; |
73 m_pAcroForm = nullptr; | 71 m_pAcroForm = nullptr; |
74 m_pPageDict = nullptr; | 72 m_pPageDict = nullptr; |
75 m_pPageResource = nullptr; | 73 m_pPageResource = nullptr; |
76 m_docStatus = PDF_DATAAVAIL_HEADER; | 74 m_docStatus = PDF_DATAAVAIL_HEADER; |
77 m_parser.m_bOwnFileRead = false; | 75 m_parser.m_bOwnFileRead = false; |
78 m_bTotalLoadPageTree = false; | 76 m_bTotalLoadPageTree = false; |
79 m_bCurPageDictLoadOK = false; | 77 m_bCurPageDictLoadOK = false; |
80 m_bLinearedDataOK = false; | 78 m_bLinearedDataOK = false; |
81 m_bSupportHintTable = bSupportHintTable; | 79 m_bSupportHintTable = bSupportHintTable; |
82 } | 80 } |
83 | 81 |
84 CPDF_DataAvail::~CPDF_DataAvail() { | 82 CPDF_DataAvail::~CPDF_DataAvail() { |
85 m_pHintTables.reset(); | 83 m_pHintTables.reset(); |
86 if (m_pLinearized) | |
87 m_pLinearized->Release(); | |
88 | 84 |
89 if (m_pRoot) | 85 if (m_pRoot) |
90 m_pRoot->Release(); | 86 m_pRoot->Release(); |
91 | 87 |
92 if (m_pTrailer) | 88 if (m_pTrailer) |
93 m_pTrailer->Release(); | 89 m_pTrailer->Release(); |
94 | 90 |
95 for (CPDF_Object* pObject : m_arrayAcroforms) | 91 for (CPDF_Object* pObject : m_arrayAcroforms) |
96 pObject->Release(); | 92 pObject->Release(); |
97 } | 93 } |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 m_docStatus = PDF_DATAAVAIL_END; | 609 m_docStatus = PDF_DATAAVAIL_END; |
614 } | 610 } |
615 return true; | 611 return true; |
616 } | 612 } |
617 | 613 |
618 pHints->AddSegment(0, kReqSize); | 614 pHints->AddSegment(0, kReqSize); |
619 return false; | 615 return false; |
620 } | 616 } |
621 | 617 |
622 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { | 618 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { |
623 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 619 if (!m_pLinearized->GetFirstPageEndOffset() || |
624 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr; | 620 !m_pLinearized->GetFileSize() || !m_pLinearized->GetLastXRefOffset()) { |
625 if (!pEndOffSet) { | |
626 m_docStatus = PDF_DATAAVAIL_ERROR; | |
627 return false; | |
628 } | |
629 | |
630 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr; | |
631 if (!pXRefOffset) { | |
632 m_docStatus = PDF_DATAAVAIL_ERROR; | |
633 return false; | |
634 } | |
635 | |
636 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr; | |
637 if (!pFileLen) { | |
638 m_docStatus = PDF_DATAAVAIL_ERROR; | 621 m_docStatus = PDF_DATAAVAIL_ERROR; |
639 return false; | 622 return false; |
640 } | 623 } |
641 | 624 |
642 bool bNeedDownLoad = false; | 625 bool bNeedDownLoad = false; |
643 if (pEndOffSet->IsNumber()) { | 626 uint32_t dwEnd = m_pLinearized->GetFirstPageEndOffset(); |
644 uint32_t dwEnd = pEndOffSet->GetInteger(); | 627 dwEnd += 512; |
645 dwEnd += 512; | 628 if ((FX_FILESIZE)dwEnd > m_dwFileLen) |
646 if ((FX_FILESIZE)dwEnd > m_dwFileLen) | 629 dwEnd = (uint32_t)m_dwFileLen; |
647 dwEnd = (uint32_t)m_dwFileLen; | |
648 | 630 |
649 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 631 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
650 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 632 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
651 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 633 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
652 pHints->AddSegment(iStartPos, iSize); | 634 pHints->AddSegment(iStartPos, iSize); |
653 bNeedDownLoad = true; | 635 bNeedDownLoad = true; |
654 } | |
655 } | 636 } |
656 | 637 |
657 m_dwLastXRefOffset = 0; | 638 m_dwLastXRefOffset = m_pLinearized->GetLastXRefOffset(); |
658 FX_FILESIZE dwFileLen = 0; | 639 FX_FILESIZE dwFileLen = m_pLinearized->GetFileSize(); |
659 if (pXRefOffset->IsNumber()) | |
660 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | |
661 | |
662 if (pFileLen->IsNumber()) | |
663 dwFileLen = pFileLen->GetInteger(); | |
664 | |
665 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 640 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
666 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { | 641 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { |
667 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 642 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
668 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); | 643 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); |
669 FX_FILESIZE offset = m_dwLastXRefOffset; | 644 FX_FILESIZE offset = m_dwLastXRefOffset; |
670 if (dwSize < 512 && dwFileLen > 512) { | 645 if (dwSize < 512 && dwFileLen > 512) { |
671 dwSize = 512; | 646 dwSize = 512; |
672 offset = dwFileLen - 512; | 647 offset = dwFileLen - 512; |
673 } | 648 } |
674 pHints->AddSegment(offset, dwSize); | 649 pHints->AddSegment(offset, dwSize); |
(...skipping 27 matching lines...) Expand all Loading... |
702 size += 512; | 677 size += 512; |
703 | 678 |
704 if (!m_pFileAvail->IsDataAvail(offset, size)) { | 679 if (!m_pFileAvail->IsDataAvail(offset, size)) { |
705 pHints->AddSegment(offset, size); | 680 pHints->AddSegment(offset, size); |
706 return false; | 681 return false; |
707 } | 682 } |
708 return true; | 683 return true; |
709 } | 684 } |
710 | 685 |
711 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { | 686 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { |
712 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 687 if (m_pLinearized->GetPageCount() <= 1) { |
713 if (!pDict) { | 688 m_docStatus = PDF_DATAAVAIL_DONE; |
| 689 return true; |
| 690 } |
| 691 if (!m_pLinearized->HasHintTable()) { |
714 m_docStatus = PDF_DATAAVAIL_ERROR; | 692 m_docStatus = PDF_DATAAVAIL_ERROR; |
715 return false; | 693 return false; |
716 } | 694 } |
717 | 695 |
718 // The actual value is not required here, but validate its existence and type. | 696 FX_FILESIZE szHintStart = m_pLinearized->GetHintStart(); |
719 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O")); | 697 FX_FILESIZE szHintLength = m_pLinearized->GetHintLength(); |
720 if (!pFirstPage || !pFirstPage->IsInteger()) { | |
721 m_docStatus = PDF_DATAAVAIL_ERROR; | |
722 return false; | |
723 } | |
724 | |
725 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N")); | |
726 if (!pPageCount || !pPageCount->IsInteger()) { | |
727 m_docStatus = PDF_DATAAVAIL_ERROR; | |
728 return false; | |
729 } | |
730 | |
731 int nPageCount = pPageCount->GetInteger(); | |
732 if (nPageCount <= 1) { | |
733 m_docStatus = PDF_DATAAVAIL_DONE; | |
734 return true; | |
735 } | |
736 | |
737 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); | |
738 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0; | |
739 if (nHintStreamSize != 2 && nHintStreamSize != 4) { | |
740 m_docStatus = PDF_DATAAVAIL_ERROR; | |
741 return false; | |
742 } | |
743 | |
744 for (const CPDF_Object* pArrayObject : *pHintStreamRange) { | |
745 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect()); | |
746 if (!pNumber || !pNumber->IsInteger()) { | |
747 m_docStatus = PDF_DATAAVAIL_ERROR; | |
748 return false; | |
749 } | |
750 } | |
751 | |
752 FX_FILESIZE szHintStart = pHintStreamRange->GetIntegerAt(0); | |
753 FX_FILESIZE szHintLength = pHintStreamRange->GetIntegerAt(1); | |
754 if (szHintStart < 0 || szHintLength <= 0) { | |
755 m_docStatus = PDF_DATAAVAIL_ERROR; | |
756 return false; | |
757 } | |
758 | 698 |
759 if (!IsDataAvail(szHintStart, szHintLength, pHints)) | 699 if (!IsDataAvail(szHintStart, szHintLength, pHints)) |
760 return false; | 700 return false; |
761 | 701 |
762 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); | 702 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); |
763 | 703 |
764 std::unique_ptr<CPDF_HintTables> pHintTables( | 704 std::unique_ptr<CPDF_HintTables> pHintTables( |
765 new CPDF_HintTables(this, pDict)); | 705 new CPDF_HintTables(this, m_pLinearized.get())); |
766 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( | 706 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( |
767 ParseIndirectObjectAt(szHintStart, 0)); | 707 ParseIndirectObjectAt(szHintStart, 0)); |
768 CPDF_Stream* pStream = ToStream(pHintStream.get()); | 708 CPDF_Stream* pStream = ToStream(pHintStream.get()); |
769 if (pStream && pHintTables->LoadHintStream(pStream)) | 709 if (pStream && pHintTables->LoadHintStream(pStream)) |
770 m_pHintTables = std::move(pHintTables); | 710 m_pHintTables = std::move(pHintTables); |
771 | 711 |
772 m_docStatus = PDF_DATAAVAIL_DONE; | 712 m_docStatus = PDF_DATAAVAIL_DONE; |
773 return true; | 713 return true; |
774 } | 714 } |
775 | 715 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 | 759 |
820 uint8_t buffer[1024]; | 760 uint8_t buffer[1024]; |
821 m_pFileRead->ReadBlock(buffer, 0, kReqSize); | 761 m_pFileRead->ReadBlock(buffer, 0, kReqSize); |
822 if (IsLinearizedFile(buffer, kReqSize)) | 762 if (IsLinearizedFile(buffer, kReqSize)) |
823 return Linearized; | 763 return Linearized; |
824 | 764 |
825 return NotLinearized; | 765 return NotLinearized; |
826 } | 766 } |
827 | 767 |
828 bool CPDF_DataAvail::IsLinearized() { | 768 bool CPDF_DataAvail::IsLinearized() { |
829 return m_bLinearized; | 769 return !!m_pLinearized; |
830 } | 770 } |
831 | 771 |
832 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { | 772 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { |
833 if (m_pLinearized) | 773 if (m_pLinearized) |
834 return m_bLinearized; | 774 return true; |
835 | 775 |
836 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false)); | 776 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false)); |
837 | 777 |
838 int32_t offset = GetHeaderOffset(file.get()); | 778 int32_t offset = GetHeaderOffset(file.get()); |
839 if (offset == -1) { | 779 if (offset == -1) { |
840 m_docStatus = PDF_DATAAVAIL_ERROR; | 780 m_docStatus = PDF_DATAAVAIL_ERROR; |
841 return false; | 781 return false; |
842 } | 782 } |
843 | 783 |
844 m_dwHeaderOffset = offset; | 784 m_dwHeaderOffset = offset; |
845 m_syntaxParser.InitParser(file.get(), offset); | 785 m_syntaxParser.InitParser(file.get(), offset); |
846 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 786 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
847 | 787 |
848 bool bNumber; | 788 bool bNumber; |
849 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); | 789 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); |
850 if (!bNumber) | 790 if (!bNumber) |
851 return false; | 791 return false; |
852 | 792 |
853 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); | 793 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); |
854 m_pLinearized = | 794 m_pLinearized = CPDF_Linearized::CreateForObject(UniqueObject( |
855 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 795 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum))); |
856 if (!m_pLinearized) | 796 if (!m_pLinearized || |
| 797 m_pLinearized->GetFileSize() != m_pFileRead->GetSize()) { |
| 798 m_pLinearized.reset(); |
857 return false; | 799 return false; |
858 | 800 } |
859 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | |
860 if (!pDict || !pDict->GetObjectFor("Linearized")) | |
861 return false; | |
862 | |
863 CPDF_Object* pLen = pDict->GetObjectFor("L"); | |
864 if (!pLen) | |
865 return false; | |
866 | |
867 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) | |
868 return false; | |
869 | |
870 m_bLinearized = true; | |
871 | |
872 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) | |
873 m_dwFirstPageNo = pNo->GetInteger(); | |
874 | |
875 return true; | 801 return true; |
876 } | 802 } |
877 | 803 |
878 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { | 804 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { |
879 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 805 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
880 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); | 806 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); |
881 | 807 |
882 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 808 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
883 uint8_t buffer[1024]; | 809 uint8_t buffer[1024]; |
884 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 810 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 m_bPageLoadedOK = false; | 1526 m_bPageLoadedOK = false; |
1601 m_bAnnotsLoad = false; | 1527 m_bAnnotsLoad = false; |
1602 m_bNeedDownLoadResource = false; | 1528 m_bNeedDownLoadResource = false; |
1603 m_objs_array.clear(); | 1529 m_objs_array.clear(); |
1604 m_ObjectSet.clear(); | 1530 m_ObjectSet.clear(); |
1605 } | 1531 } |
1606 | 1532 |
1607 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) | 1533 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) |
1608 return DataAvailable; | 1534 return DataAvailable; |
1609 | 1535 |
1610 if (m_bLinearized) { | 1536 if (m_pLinearized) { |
1611 if (dwPage == m_dwFirstPageNo) { | 1537 if (dwPage == m_pLinearized->GetFirstPageNo()) { |
1612 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); | 1538 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); |
1613 if (nRet == DataAvailable) | 1539 if (nRet == DataAvailable) |
1614 m_pagesLoadState.insert(dwPage); | 1540 m_pagesLoadState.insert(dwPage); |
1615 return nRet; | 1541 return nRet; |
1616 } | 1542 } |
1617 | 1543 |
1618 DocAvailStatus nResult = CheckLinearizedData(pHints); | 1544 DocAvailStatus nResult = CheckLinearizedData(pHints); |
1619 if (nResult != DataAvailable) | 1545 if (nResult != DataAvailable) |
1620 return nResult; | 1546 return nResult; |
1621 | 1547 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 | 1657 |
1732 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, | 1658 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, |
1733 uint32_t* pSize) { | 1659 uint32_t* pSize) { |
1734 if (pPos) | 1660 if (pPos) |
1735 *pPos = m_dwLastXRefOffset; | 1661 *pPos = m_dwLastXRefOffset; |
1736 if (pSize) | 1662 if (pSize) |
1737 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); | 1663 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); |
1738 } | 1664 } |
1739 | 1665 |
1740 int CPDF_DataAvail::GetPageCount() const { | 1666 int CPDF_DataAvail::GetPageCount() const { |
1741 if (m_pLinearized) { | 1667 if (m_pLinearized) |
1742 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1668 return m_pLinearized->GetPageCount(); |
1743 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("N") : nullptr; | |
1744 return pObj ? pObj->GetInteger() : 0; | |
1745 } | |
1746 return m_pDocument ? m_pDocument->GetPageCount() : 0; | 1669 return m_pDocument ? m_pDocument->GetPageCount() : 0; |
1747 } | 1670 } |
1748 | 1671 |
1749 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { | 1672 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { |
1750 if (!m_pDocument || index < 0 || index >= GetPageCount()) | 1673 if (!m_pDocument || index < 0 || index >= GetPageCount()) |
1751 return nullptr; | 1674 return nullptr; |
1752 CPDF_Dictionary* page = m_pDocument->GetPage(index); | 1675 CPDF_Dictionary* page = m_pDocument->GetPage(index); |
1753 if (page) | 1676 if (page) |
1754 return page; | 1677 return page; |
1755 if (!m_pLinearized || !m_pHintTables) | 1678 if (!m_pLinearized || !m_pHintTables) |
1756 return nullptr; | 1679 return nullptr; |
1757 | 1680 |
1758 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1681 if (index == static_cast<int>(m_pLinearized->GetFirstPageNo())) |
1759 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr; | |
1760 int firstPageNum = pObj ? pObj->GetInteger() : 0; | |
1761 if (index == firstPageNum) | |
1762 return nullptr; | 1682 return nullptr; |
1763 FX_FILESIZE szPageStartPos = 0; | 1683 FX_FILESIZE szPageStartPos = 0; |
1764 FX_FILESIZE szPageLength = 0; | 1684 FX_FILESIZE szPageLength = 0; |
1765 uint32_t dwObjNum = 0; | 1685 uint32_t dwObjNum = 0; |
1766 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, | 1686 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, |
1767 &szPageLength, &dwObjNum); | 1687 &szPageLength, &dwObjNum); |
1768 if (!bPagePosGot || !dwObjNum) | 1688 if (!bPagePosGot || !dwObjNum) |
1769 return nullptr; | 1689 return nullptr; |
1770 // We should say to the document, which object is the page. | 1690 // We should say to the document, which object is the page. |
1771 m_pDocument->SetPageObjNum(index, dwObjNum); | 1691 m_pDocument->SetPageObjNum(index, dwObjNum); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 return FormAvailable; | 1736 return FormAvailable; |
1817 } | 1737 } |
1818 | 1738 |
1819 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1739 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
1820 | 1740 |
1821 CPDF_DataAvail::PageNode::~PageNode() { | 1741 CPDF_DataAvail::PageNode::~PageNode() { |
1822 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1742 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
1823 delete m_childNode[i]; | 1743 delete m_childNode[i]; |
1824 m_childNode.RemoveAll(); | 1744 m_childNode.RemoveAll(); |
1825 } | 1745 } |
OLD | NEW |