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/include/cpdf_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 m_SortedOffset.insert(last_trailer - m_pSyntax->m_HeaderOffset); | 972 m_SortedOffset.insert(last_trailer - m_pSyntax->m_HeaderOffset); |
973 return m_pTrailer && !m_ObjectInfo.empty(); | 973 return m_pTrailer && !m_ObjectInfo.empty(); |
974 } | 974 } |
975 | 975 |
976 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { | 976 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { |
977 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0); | 977 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0); |
978 if (!pObject) | 978 if (!pObject) |
979 return FALSE; | 979 return FALSE; |
980 | 980 |
981 if (m_pDocument) { | 981 if (m_pDocument) { |
982 FX_BOOL bInserted = FALSE; | 982 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot(); |
983 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 983 if (pRootDict && pRootDict->GetObjNum() == pObject->m_ObjNum) { |
984 if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) { | |
985 bInserted = m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject); | |
986 } else { | |
987 if (pObject->IsStream()) | 984 if (pObject->IsStream()) |
988 pObject->Release(); | 985 pObject->Release(); |
| 986 return FALSE; |
989 } | 987 } |
990 | 988 if (!m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject)) |
991 if (!bInserted) | |
992 return FALSE; | 989 return FALSE; |
993 } | 990 } |
994 | 991 |
995 CPDF_Stream* pStream = pObject->AsStream(); | 992 CPDF_Stream* pStream = pObject->AsStream(); |
996 if (!pStream) | 993 if (!pStream) |
997 return FALSE; | 994 return FALSE; |
998 | 995 |
999 *pos = pStream->GetDict()->GetIntegerBy("Prev"); | 996 CPDF_Dictionary* pDict = pStream->GetDict(); |
1000 int32_t size = pStream->GetDict()->GetIntegerBy("Size"); | 997 *pos = pDict->GetIntegerBy("Prev"); |
| 998 int32_t size = pDict->GetIntegerBy("Size"); |
1001 if (size < 0) { | 999 if (size < 0) { |
1002 pStream->Release(); | 1000 pStream->Release(); |
1003 return FALSE; | 1001 return FALSE; |
1004 } | 1002 } |
1005 | 1003 |
| 1004 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone()); |
1006 if (bMainXRef) { | 1005 if (bMainXRef) { |
1007 m_pTrailer = ToDictionary(pStream->GetDict()->Clone()); | 1006 m_pTrailer = pNewTrailer; |
1008 ShrinkObjectMap(size); | 1007 ShrinkObjectMap(size); |
1009 for (auto& it : m_ObjectInfo) | 1008 for (auto& it : m_ObjectInfo) |
1010 it.second.type = 0; | 1009 it.second.type = 0; |
1011 } else { | 1010 } else { |
1012 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); | 1011 m_Trailers.Add(pNewTrailer); |
1013 } | 1012 } |
1014 | 1013 |
1015 std::vector<std::pair<int32_t, int32_t>> arrIndex; | 1014 std::vector<std::pair<int32_t, int32_t>> arrIndex; |
1016 CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index"); | 1015 CPDF_Array* pArray = pDict->GetArrayBy("Index"); |
1017 if (pArray) { | 1016 if (pArray) { |
1018 for (size_t i = 0; i < pArray->GetCount() / 2; i++) { | 1017 for (size_t i = 0; i < pArray->GetCount() / 2; i++) { |
1019 CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2); | 1018 CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2); |
1020 CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1); | 1019 CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1); |
1021 | 1020 |
1022 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { | 1021 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { |
1023 int nStartNum = pStartNumObj->GetInteger(); | 1022 int nStartNum = pStartNumObj->GetInteger(); |
1024 int nCount = pCountObj->GetInteger(); | 1023 int nCount = pCountObj->GetInteger(); |
1025 if (nStartNum >= 0 && nCount > 0) | 1024 if (nStartNum >= 0 && nCount > 0) |
1026 arrIndex.push_back(std::make_pair(nStartNum, nCount)); | 1025 arrIndex.push_back(std::make_pair(nStartNum, nCount)); |
1027 } | 1026 } |
1028 } | 1027 } |
1029 } | 1028 } |
1030 | 1029 |
1031 if (arrIndex.size() == 0) | 1030 if (arrIndex.size() == 0) |
1032 arrIndex.push_back(std::make_pair(0, size)); | 1031 arrIndex.push_back(std::make_pair(0, size)); |
1033 | 1032 |
1034 pArray = pStream->GetDict()->GetArrayBy("W"); | 1033 pArray = pDict->GetArrayBy("W"); |
1035 if (!pArray) { | 1034 if (!pArray) { |
1036 pStream->Release(); | 1035 pStream->Release(); |
1037 return FALSE; | 1036 return FALSE; |
1038 } | 1037 } |
1039 | 1038 |
1040 CFX_ArrayTemplate<uint32_t> WidthArray; | 1039 CFX_ArrayTemplate<uint32_t> WidthArray; |
1041 FX_SAFE_UINT32 dwAccWidth = 0; | 1040 FX_SAFE_UINT32 dwAccWidth = 0; |
1042 for (size_t i = 0; i < pArray->GetCount(); i++) { | 1041 for (size_t i = 0; i < pArray->GetCount(); ++i) { |
1043 WidthArray.Add(pArray->GetIntegerAt(i)); | 1042 WidthArray.Add(pArray->GetIntegerAt(i)); |
1044 dwAccWidth += WidthArray[i]; | 1043 dwAccWidth += WidthArray[i]; |
1045 } | 1044 } |
1046 | 1045 |
1047 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { | 1046 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { |
1048 pStream->Release(); | 1047 pStream->Release(); |
1049 return FALSE; | 1048 return FALSE; |
1050 } | 1049 } |
1051 | 1050 |
1052 uint32_t totalWidth = dwAccWidth.ValueOrDie(); | 1051 uint32_t totalWidth = dwAccWidth.ValueOrDie(); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1668 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1670 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1669 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1671 m_LastXRefOffset = 0; | 1670 m_LastXRefOffset = 0; |
1672 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1671 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1673 return FORMAT_ERROR; | 1672 return FORMAT_ERROR; |
1674 } | 1673 } |
1675 | 1674 |
1676 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1675 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1677 return SUCCESS; | 1676 return SUCCESS; |
1678 } | 1677 } |
OLD | NEW |