Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: core/fpdfapi/parser/cpdf_data_avail.cpp

Issue 2474283005: Revert of Unify some code (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_data_avail.h ('k') | core/fpdfapi/parser/cpdf_document.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
19 #include "core/fpdfapi/parser/cpdf_name.h" 18 #include "core/fpdfapi/parser/cpdf_name.h"
20 #include "core/fpdfapi/parser/cpdf_number.h" 19 #include "core/fpdfapi/parser/cpdf_number.h"
21 #include "core/fpdfapi/parser/cpdf_reference.h" 20 #include "core/fpdfapi/parser/cpdf_reference.h"
22 #include "core/fpdfapi/parser/cpdf_stream.h" 21 #include "core/fpdfapi/parser/cpdf_stream.h"
23 #include "core/fpdfapi/parser/fpdf_parser_utility.h" 22 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
24 #include "core/fxcrt/fx_ext.h" 23 #include "core/fxcrt/fx_ext.h"
25 #include "core/fxcrt/fx_safe_types.h" 24 #include "core/fxcrt/fx_safe_types.h"
26 #include "third_party/base/stl_util.h" 25 #include "third_party/base/stl_util.h"
27 26
28 CPDF_DataAvail::FileAvail::~FileAvail() {} 27 CPDF_DataAvail::FileAvail::~FileAvail() {}
29 28
30 CPDF_DataAvail::DownloadHints::~DownloadHints() {} 29 CPDF_DataAvail::DownloadHints::~DownloadHints() {}
31 30
32 // static 31 // static
33 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; 32 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0;
34 33
35 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, 34 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail,
36 IFX_SeekableReadStream* pFileRead, 35 IFX_SeekableReadStream* pFileRead,
37 bool bSupportHintTable) 36 bool bSupportHintTable)
38 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { 37 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) {
39 m_Pos = 0; 38 m_Pos = 0;
40 m_dwFileLen = 0; 39 m_dwFileLen = 0;
41 if (m_pFileRead) { 40 if (m_pFileRead) {
42 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); 41 m_dwFileLen = (uint32_t)m_pFileRead->GetSize();
43 } 42 }
44 m_dwCurrentOffset = 0; 43 m_dwCurrentOffset = 0;
45 m_dwXRefOffset = 0; 44 m_dwXRefOffset = 0;
46 m_bufferOffset = 0; 45 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;
59 m_bPagesLoad = false; 60 m_bPagesLoad = false;
60 m_bPagesTreeLoad = false; 61 m_bPagesTreeLoad = false;
61 m_bMainXRefLoadedOK = false; 62 m_bMainXRefLoadedOK = false;
62 m_bAnnotsLoad = false; 63 m_bAnnotsLoad = false;
63 m_bHaveAcroForm = false; 64 m_bHaveAcroForm = false;
64 m_bAcroFormLoad = false; 65 m_bAcroFormLoad = false;
65 m_bPageLoadedOK = false; 66 m_bPageLoadedOK = false;
66 m_bNeedDownLoadResource = false; 67 m_bNeedDownLoadResource = false;
67 m_bLinearizedFormParamLoad = false; 68 m_bLinearizedFormParamLoad = false;
69 m_pLinearized = nullptr;
68 m_pRoot = nullptr; 70 m_pRoot = nullptr;
69 m_pTrailer = nullptr; 71 m_pTrailer = nullptr;
70 m_pCurrentParser = nullptr; 72 m_pCurrentParser = nullptr;
71 m_pAcroForm = nullptr; 73 m_pAcroForm = nullptr;
72 m_pPageDict = nullptr; 74 m_pPageDict = nullptr;
73 m_pPageResource = nullptr; 75 m_pPageResource = nullptr;
74 m_docStatus = PDF_DATAAVAIL_HEADER; 76 m_docStatus = PDF_DATAAVAIL_HEADER;
75 m_parser.m_bOwnFileRead = false; 77 m_parser.m_bOwnFileRead = false;
76 m_bTotalLoadPageTree = false; 78 m_bTotalLoadPageTree = false;
77 m_bCurPageDictLoadOK = false; 79 m_bCurPageDictLoadOK = false;
78 m_bLinearedDataOK = false; 80 m_bLinearedDataOK = false;
79 m_bSupportHintTable = bSupportHintTable; 81 m_bSupportHintTable = bSupportHintTable;
80 } 82 }
81 83
82 CPDF_DataAvail::~CPDF_DataAvail() { 84 CPDF_DataAvail::~CPDF_DataAvail() {
83 m_pHintTables.reset(); 85 m_pHintTables.reset();
86 delete m_pLinearized;
87 delete m_pRoot;
88 delete m_pTrailer;
84 89
85 for (CPDF_Object* pObject : m_arrayAcroforms) 90 for (CPDF_Object* pObject : m_arrayAcroforms)
86 delete pObject; 91 delete pObject;
87 } 92 }
88 93
89 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { 94 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) {
90 m_pDocument = pDoc; 95 m_pDocument = pDoc;
91 } 96 }
92 97
93 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { 98 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) {
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 m_docStatus = PDF_DATAAVAIL_END; 606 m_docStatus = PDF_DATAAVAIL_END;
602 } 607 }
603 return true; 608 return true;
604 } 609 }
605 610
606 pHints->AddSegment(0, kReqSize); 611 pHints->AddSegment(0, kReqSize);
607 return false; 612 return false;
608 } 613 }
609 614
610 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { 615 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) {
611 if (!m_pLinearized->GetFirstPageEndOffset() || 616 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
612 !m_pLinearized->GetFileSize() || !m_pLinearized->GetLastXRefOffset()) { 617 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr;
618 if (!pEndOffSet) {
619 m_docStatus = PDF_DATAAVAIL_ERROR;
620 return false;
621 }
622
623 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr;
624 if (!pXRefOffset) {
625 m_docStatus = PDF_DATAAVAIL_ERROR;
626 return false;
627 }
628
629 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr;
630 if (!pFileLen) {
613 m_docStatus = PDF_DATAAVAIL_ERROR; 631 m_docStatus = PDF_DATAAVAIL_ERROR;
614 return false; 632 return false;
615 } 633 }
616 634
617 bool bNeedDownLoad = false; 635 bool bNeedDownLoad = false;
618 uint32_t dwEnd = m_pLinearized->GetFirstPageEndOffset(); 636 if (pEndOffSet->IsNumber()) {
619 dwEnd += 512; 637 uint32_t dwEnd = pEndOffSet->GetInteger();
620 if ((FX_FILESIZE)dwEnd > m_dwFileLen) 638 dwEnd += 512;
621 dwEnd = (uint32_t)m_dwFileLen; 639 if ((FX_FILESIZE)dwEnd > m_dwFileLen)
640 dwEnd = (uint32_t)m_dwFileLen;
622 641
623 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); 642 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen);
624 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; 643 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0;
625 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { 644 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) {
626 pHints->AddSegment(iStartPos, iSize); 645 pHints->AddSegment(iStartPos, iSize);
627 bNeedDownLoad = true; 646 bNeedDownLoad = true;
647 }
628 } 648 }
629 649
630 m_dwLastXRefOffset = m_pLinearized->GetLastXRefOffset(); 650 m_dwLastXRefOffset = 0;
631 FX_FILESIZE dwFileLen = m_pLinearized->GetFileSize(); 651 FX_FILESIZE dwFileLen = 0;
652 if (pXRefOffset->IsNumber())
653 m_dwLastXRefOffset = pXRefOffset->GetInteger();
654
655 if (pFileLen->IsNumber())
656 dwFileLen = pFileLen->GetInteger();
657
632 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, 658 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset,
633 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { 659 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) {
634 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { 660 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) {
635 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); 661 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset);
636 FX_FILESIZE offset = m_dwLastXRefOffset; 662 FX_FILESIZE offset = m_dwLastXRefOffset;
637 if (dwSize < 512 && dwFileLen > 512) { 663 if (dwSize < 512 && dwFileLen > 512) {
638 dwSize = 512; 664 dwSize = 512;
639 offset = dwFileLen - 512; 665 offset = dwFileLen - 512;
640 } 666 }
641 pHints->AddSegment(offset, dwSize); 667 pHints->AddSegment(offset, dwSize);
(...skipping 27 matching lines...) Expand all
669 size += 512; 695 size += 512;
670 696
671 if (!m_pFileAvail->IsDataAvail(offset, size)) { 697 if (!m_pFileAvail->IsDataAvail(offset, size)) {
672 pHints->AddSegment(offset, size); 698 pHints->AddSegment(offset, size);
673 return false; 699 return false;
674 } 700 }
675 return true; 701 return true;
676 } 702 }
677 703
678 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { 704 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) {
679 if (m_pLinearized->GetPageCount() <= 1) { 705 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
680 m_docStatus = PDF_DATAAVAIL_DONE; 706 if (!pDict) {
681 return true;
682 }
683 if (!m_pLinearized->HasHintTable()) {
684 m_docStatus = PDF_DATAAVAIL_ERROR; 707 m_docStatus = PDF_DATAAVAIL_ERROR;
685 return false; 708 return false;
686 } 709 }
687 710
688 FX_FILESIZE szHintStart = m_pLinearized->GetHintStart(); 711 // The actual value is not required here, but validate its existence and type.
689 FX_FILESIZE szHintLength = m_pLinearized->GetHintLength(); 712 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O"));
713 if (!pFirstPage || !pFirstPage->IsInteger()) {
714 m_docStatus = PDF_DATAAVAIL_ERROR;
715 return false;
716 }
717
718 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N"));
719 if (!pPageCount || !pPageCount->IsInteger()) {
720 m_docStatus = PDF_DATAAVAIL_ERROR;
721 return false;
722 }
723
724 int nPageCount = pPageCount->GetInteger();
725 if (nPageCount <= 1) {
726 m_docStatus = PDF_DATAAVAIL_DONE;
727 return true;
728 }
729
730 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H");
731 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0;
732 if (nHintStreamSize != 2 && nHintStreamSize != 4) {
733 m_docStatus = PDF_DATAAVAIL_ERROR;
734 return false;
735 }
736
737 for (const CPDF_Object* pArrayObject : *pHintStreamRange) {
738 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect());
739 if (!pNumber || !pNumber->IsInteger()) {
740 m_docStatus = PDF_DATAAVAIL_ERROR;
741 return false;
742 }
743 }
744
745 FX_FILESIZE szHintStart = pHintStreamRange->GetIntegerAt(0);
746 FX_FILESIZE szHintLength = pHintStreamRange->GetIntegerAt(1);
747 if (szHintStart < 0 || szHintLength <= 0) {
748 m_docStatus = PDF_DATAAVAIL_ERROR;
749 return false;
750 }
690 751
691 if (!IsDataAvail(szHintStart, szHintLength, pHints)) 752 if (!IsDataAvail(szHintStart, szHintLength, pHints))
692 return false; 753 return false;
693 754
694 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); 755 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset);
695 756
696 std::unique_ptr<CPDF_HintTables> pHintTables( 757 std::unique_ptr<CPDF_HintTables> pHintTables(
697 new CPDF_HintTables(this, m_pLinearized.get())); 758 new CPDF_HintTables(this, pDict));
698 std::unique_ptr<CPDF_Object> pHintStream( 759 std::unique_ptr<CPDF_Object> pHintStream(
699 ParseIndirectObjectAt(szHintStart, 0)); 760 ParseIndirectObjectAt(szHintStart, 0));
700 CPDF_Stream* pStream = ToStream(pHintStream.get()); 761 CPDF_Stream* pStream = ToStream(pHintStream.get());
701 if (pStream && pHintTables->LoadHintStream(pStream)) 762 if (pStream && pHintTables->LoadHintStream(pStream))
702 m_pHintTables = std::move(pHintTables); 763 m_pHintTables = std::move(pHintTables);
703 764
704 m_docStatus = PDF_DATAAVAIL_DONE; 765 m_docStatus = PDF_DATAAVAIL_DONE;
705 return true; 766 return true;
706 } 767 }
707 768
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 812
752 uint8_t buffer[1024]; 813 uint8_t buffer[1024];
753 m_pFileRead->ReadBlock(buffer, 0, kReqSize); 814 m_pFileRead->ReadBlock(buffer, 0, kReqSize);
754 if (IsLinearizedFile(buffer, kReqSize)) 815 if (IsLinearizedFile(buffer, kReqSize))
755 return Linearized; 816 return Linearized;
756 817
757 return NotLinearized; 818 return NotLinearized;
758 } 819 }
759 820
760 bool CPDF_DataAvail::IsLinearized() { 821 bool CPDF_DataAvail::IsLinearized() {
761 return !!m_pLinearized; 822 return m_bLinearized;
762 } 823 }
763 824
764 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { 825 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) {
765 if (m_pLinearized) 826 if (m_pLinearized)
766 return true; 827 return m_bLinearized;
767 828
768 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false)); 829 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false));
769 830
770 int32_t offset = GetHeaderOffset(file.get()); 831 int32_t offset = GetHeaderOffset(file.get());
771 if (offset == -1) { 832 if (offset == -1) {
772 m_docStatus = PDF_DATAAVAIL_ERROR; 833 m_docStatus = PDF_DATAAVAIL_ERROR;
773 return false; 834 return false;
774 } 835 }
775 836
776 m_dwHeaderOffset = offset; 837 m_dwHeaderOffset = offset;
777 m_syntaxParser.InitParser(file.get(), offset); 838 m_syntaxParser.InitParser(file.get(), offset);
778 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); 839 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9);
779 840
780 bool bNumber; 841 bool bNumber;
781 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); 842 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber);
782 if (!bNumber) 843 if (!bNumber)
783 return false; 844 return false;
784 845
785 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); 846 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str());
786 m_pLinearized = CPDF_Linearized::CreateForObject(pdfium::WrapUnique( 847 m_pLinearized =
787 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum))); 848 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum);
788 if (!m_pLinearized || 849 if (!m_pLinearized)
789 m_pLinearized->GetFileSize() != m_pFileRead->GetSize()) {
790 m_pLinearized.reset();
791 return false; 850 return false;
792 } 851
852 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
853 if (!pDict || !pDict->GetObjectFor("Linearized"))
854 return false;
855
856 CPDF_Object* pLen = pDict->GetObjectFor("L");
857 if (!pLen)
858 return false;
859
860 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize())
861 return false;
862
863 m_bLinearized = true;
864
865 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P")))
866 m_dwFirstPageNo = pNo->GetInteger();
867
793 return true; 868 return true;
794 } 869 }
795 870
796 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { 871 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) {
797 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); 872 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0);
798 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); 873 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos);
799 874
800 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { 875 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) {
801 uint8_t buffer[1024]; 876 uint8_t buffer[1024];
802 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); 877 m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 m_bPageLoadedOK = false; 1593 m_bPageLoadedOK = false;
1519 m_bAnnotsLoad = false; 1594 m_bAnnotsLoad = false;
1520 m_bNeedDownLoadResource = false; 1595 m_bNeedDownLoadResource = false;
1521 m_objs_array.clear(); 1596 m_objs_array.clear();
1522 m_ObjectSet.clear(); 1597 m_ObjectSet.clear();
1523 } 1598 }
1524 1599
1525 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) 1600 if (pdfium::ContainsKey(m_pagesLoadState, dwPage))
1526 return DataAvailable; 1601 return DataAvailable;
1527 1602
1528 if (m_pLinearized) { 1603 if (m_bLinearized) {
1529 if (dwPage == m_pLinearized->GetFirstPageNo()) { 1604 if (dwPage == m_dwFirstPageNo) {
1530 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); 1605 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints);
1531 if (nRet == DataAvailable) 1606 if (nRet == DataAvailable)
1532 m_pagesLoadState.insert(dwPage); 1607 m_pagesLoadState.insert(dwPage);
1533 return nRet; 1608 return nRet;
1534 } 1609 }
1535 1610
1536 DocAvailStatus nResult = CheckLinearizedData(pHints); 1611 DocAvailStatus nResult = CheckLinearizedData(pHints);
1537 if (nResult != DataAvailable) 1612 if (nResult != DataAvailable)
1538 return nResult; 1613 return nResult;
1539 1614
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 1724
1650 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, 1725 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos,
1651 uint32_t* pSize) { 1726 uint32_t* pSize) {
1652 if (pPos) 1727 if (pPos)
1653 *pPos = m_dwLastXRefOffset; 1728 *pPos = m_dwLastXRefOffset;
1654 if (pSize) 1729 if (pSize)
1655 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); 1730 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset);
1656 } 1731 }
1657 1732
1658 int CPDF_DataAvail::GetPageCount() const { 1733 int CPDF_DataAvail::GetPageCount() const {
1659 if (m_pLinearized) 1734 if (m_pLinearized) {
1660 return m_pLinearized->GetPageCount(); 1735 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
1736 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("N") : nullptr;
1737 return pObj ? pObj->GetInteger() : 0;
1738 }
1661 return m_pDocument ? m_pDocument->GetPageCount() : 0; 1739 return m_pDocument ? m_pDocument->GetPageCount() : 0;
1662 } 1740 }
1663 1741
1664 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { 1742 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) {
1665 if (!m_pDocument || index < 0 || index >= GetPageCount()) 1743 if (!m_pDocument || index < 0 || index >= GetPageCount())
1666 return nullptr; 1744 return nullptr;
1667 CPDF_Dictionary* page = m_pDocument->GetPage(index); 1745 CPDF_Dictionary* page = m_pDocument->GetPage(index);
1668 if (page) 1746 if (page)
1669 return page; 1747 return page;
1670 if (!m_pLinearized || !m_pHintTables) 1748 if (!m_pLinearized || !m_pHintTables)
1671 return nullptr; 1749 return nullptr;
1672 1750
1673 if (index == static_cast<int>(m_pLinearized->GetFirstPageNo())) 1751 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
1752 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr;
1753 int firstPageNum = pObj ? pObj->GetInteger() : 0;
1754 if (index == firstPageNum)
1674 return nullptr; 1755 return nullptr;
1675 FX_FILESIZE szPageStartPos = 0; 1756 FX_FILESIZE szPageStartPos = 0;
1676 FX_FILESIZE szPageLength = 0; 1757 FX_FILESIZE szPageLength = 0;
1677 uint32_t dwObjNum = 0; 1758 uint32_t dwObjNum = 0;
1678 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, 1759 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos,
1679 &szPageLength, &dwObjNum); 1760 &szPageLength, &dwObjNum);
1680 if (!bPagePosGot || !dwObjNum) 1761 if (!bPagePosGot || !dwObjNum)
1681 return nullptr; 1762 return nullptr;
1682 // We should say to the document, which object is the page. 1763 // We should say to the document, which object is the page.
1683 m_pDocument->SetPageObjNum(index, dwObjNum); 1764 m_pDocument->SetPageObjNum(index, dwObjNum);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 return FormAvailable; 1807 return FormAvailable;
1727 } 1808 }
1728 1809
1729 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} 1810 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {}
1730 1811
1731 CPDF_DataAvail::PageNode::~PageNode() { 1812 CPDF_DataAvail::PageNode::~PageNode() {
1732 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) 1813 for (int32_t i = 0; i < m_childNode.GetSize(); ++i)
1733 delete m_childNode[i]; 1814 delete m_childNode[i];
1734 m_childNode.RemoveAll(); 1815 m_childNode.RemoveAll();
1735 } 1816 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_data_avail.h ('k') | core/fpdfapi/parser/cpdf_document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698