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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 ParseIndirectObjectAtByStrict(m_pDocument, obj_pos, objnum, | 730 ParseIndirectObjectAtByStrict(m_pDocument, obj_pos, objnum, |
731 &obj_end); | 731 &obj_end); |
732 if (CPDF_Stream* pStream = ToStream(pObject.get())) { | 732 if (CPDF_Stream* pStream = ToStream(pObject.get())) { |
733 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 733 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
734 if ((pDict->KeyExist("Type")) && | 734 if ((pDict->KeyExist("Type")) && |
735 (pDict->GetStringFor("Type") == "XRef" && | 735 (pDict->GetStringFor("Type") == "XRef" && |
736 pDict->KeyExist("Size"))) { | 736 pDict->KeyExist("Size"))) { |
737 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); | 737 CPDF_Object* pRoot = pDict->GetObjectFor("Root"); |
738 if (pRoot && pRoot->GetDict() && | 738 if (pRoot && pRoot->GetDict() && |
739 pRoot->GetDict()->GetObjectFor("Pages")) { | 739 pRoot->GetDict()->GetObjectFor("Pages")) { |
740 m_pTrailer = | 740 m_pTrailer = ToDictionary(pDict->Clone()); |
741 ToDictionary(pdfium::WrapUnique(pDict->Clone())); | |
742 } | 741 } |
743 } | 742 } |
744 } | 743 } |
745 } | 744 } |
746 | 745 |
747 FX_FILESIZE offset = 0; | 746 FX_FILESIZE offset = 0; |
748 m_pSyntax->RestorePos(obj_pos); | 747 m_pSyntax->RestorePos(obj_pos); |
749 offset = m_pSyntax->FindTag("obj", 0); | 748 offset = m_pSyntax->FindTag("obj", 0); |
750 if (offset == -1) | 749 if (offset == -1) |
751 offset = 0; | 750 offset = 0; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 while (it != pTrailer->end()) { | 803 while (it != pTrailer->end()) { |
805 const CFX_ByteString& key = it->first; | 804 const CFX_ByteString& key = it->first; |
806 CPDF_Object* pElement = it->second; | 805 CPDF_Object* pElement = it->second; |
807 ++it; | 806 ++it; |
808 uint32_t dwObjNum = | 807 uint32_t dwObjNum = |
809 pElement ? pElement->GetObjNum() : 0; | 808 pElement ? pElement->GetObjNum() : 0; |
810 if (dwObjNum) { | 809 if (dwObjNum) { |
811 m_pTrailer->SetReferenceFor(key, m_pDocument, | 810 m_pTrailer->SetReferenceFor(key, m_pDocument, |
812 dwObjNum); | 811 dwObjNum); |
813 } else { | 812 } else { |
814 m_pTrailer->SetFor(key, pElement->Clone()); | 813 m_pTrailer->SetFor(key, |
| 814 pElement->Clone().release()); |
815 } | 815 } |
816 } | 816 } |
817 } | 817 } |
818 } else { | 818 } else { |
819 if (pObj->IsStream()) { | 819 if (pObj->IsStream()) { |
820 m_pTrailer = | 820 m_pTrailer = ToDictionary(pTrailer->Clone()); |
821 ToDictionary(pdfium::WrapUnique(pTrailer->Clone())); | |
822 } else { | 821 } else { |
823 m_pTrailer = ToDictionary(std::move(pObj)); | 822 m_pTrailer = ToDictionary(std::move(pObj)); |
824 } | 823 } |
825 | 824 |
826 FX_FILESIZE dwSavePos = m_pSyntax->SavePos(); | 825 FX_FILESIZE dwSavePos = m_pSyntax->SavePos(); |
827 CFX_ByteString strWord = m_pSyntax->GetKeyword(); | 826 CFX_ByteString strWord = m_pSyntax->GetKeyword(); |
828 if (!strWord.Compare("startxref")) { | 827 if (!strWord.Compare("startxref")) { |
829 bool bNumber; | 828 bool bNumber; |
830 CFX_ByteString bsOffset = | 829 CFX_ByteString bsOffset = |
831 m_pSyntax->GetNextWord(&bNumber); | 830 m_pSyntax->GetNextWord(&bNumber); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 CPDF_Stream* pStream = pUnownedObject->AsStream(); | 951 CPDF_Stream* pStream = pUnownedObject->AsStream(); |
953 if (!pStream) | 952 if (!pStream) |
954 return false; | 953 return false; |
955 | 954 |
956 CPDF_Dictionary* pDict = pStream->GetDict(); | 955 CPDF_Dictionary* pDict = pStream->GetDict(); |
957 *pos = pDict->GetIntegerFor("Prev"); | 956 *pos = pDict->GetIntegerFor("Prev"); |
958 int32_t size = pDict->GetIntegerFor("Size"); | 957 int32_t size = pDict->GetIntegerFor("Size"); |
959 if (size < 0) | 958 if (size < 0) |
960 return false; | 959 return false; |
961 | 960 |
962 std::unique_ptr<CPDF_Dictionary> pNewTrailer = | 961 std::unique_ptr<CPDF_Dictionary> pNewTrailer = ToDictionary(pDict->Clone()); |
963 ToDictionary(pdfium::WrapUnique(pDict->Clone())); | |
964 if (bMainXRef) { | 962 if (bMainXRef) { |
965 m_pTrailer = std::move(pNewTrailer); | 963 m_pTrailer = std::move(pNewTrailer); |
966 ShrinkObjectMap(size); | 964 ShrinkObjectMap(size); |
967 for (auto& it : m_ObjectInfo) | 965 for (auto& it : m_ObjectInfo) |
968 it.second.type = 0; | 966 it.second.type = 0; |
969 } else { | 967 } else { |
970 m_Trailers.push_back(std::move(pNewTrailer)); | 968 m_Trailers.push_back(std::move(pNewTrailer)); |
971 } | 969 } |
972 | 970 |
973 std::vector<std::pair<int32_t, int32_t>> arrIndex; | 971 std::vector<std::pair<int32_t, int32_t>> arrIndex; |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1570 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1573 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1571 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1574 m_LastXRefOffset = 0; | 1572 m_LastXRefOffset = 0; |
1575 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1573 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1576 return FORMAT_ERROR; | 1574 return FORMAT_ERROR; |
1577 } | 1575 } |
1578 | 1576 |
1579 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1577 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1580 return SUCCESS; | 1578 return SUCCESS; |
1581 } | 1579 } |
OLD | NEW |