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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_parser.cpp

Issue 2387193003: Revert of Assert that only 0-numbered objects are Released() (Closed)
Patch Set: Created 4 years, 2 months 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
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/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 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 if (last_xref != -1 && last_xref > last_obj) 949 if (last_xref != -1 && last_xref > last_obj)
950 last_trailer = last_xref; 950 last_trailer = last_xref;
951 else if (last_trailer == -1 || last_xref < last_obj) 951 else if (last_trailer == -1 || last_xref < last_obj)
952 last_trailer = m_pSyntax->m_FileLen; 952 last_trailer = m_pSyntax->m_FileLen;
953 953
954 m_SortedOffset.insert(last_trailer - m_pSyntax->m_HeaderOffset); 954 m_SortedOffset.insert(last_trailer - m_pSyntax->m_HeaderOffset);
955 return m_pTrailer && !m_ObjectInfo.empty(); 955 return m_pTrailer && !m_ObjectInfo.empty();
956 } 956 }
957 957
958 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { 958 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) {
959 std::unique_ptr<CPDF_Object> pObject( 959 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0);
960 ParseIndirectObjectAt(m_pDocument, *pos, 0));
961 if (!pObject) 960 if (!pObject)
962 return FALSE; 961 return FALSE;
963 962
964 CPDF_Object* pUnownedObject = pObject.get();
965
966 if (m_pDocument) { 963 if (m_pDocument) {
967 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot(); 964 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot();
968 if (pRootDict && pRootDict->GetObjNum() == pObject->m_ObjNum) 965 if (pRootDict && pRootDict->GetObjNum() == pObject->m_ObjNum) {
966 // If |pObject| has an objnum assigned then this will leak as Release()
967 // will early exit.
968 if (pObject->IsStream())
969 pObject->Release();
969 return FALSE; 970 return FALSE;
970 // Takes ownership of object (std::move someday). 971 }
971 uint32_t objnum = pObject->m_ObjNum; 972 if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(pObject->m_ObjNum,
972 if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration( 973 pObject)) {
973 objnum, pObject.release())) {
974 return FALSE; 974 return FALSE;
975 } 975 }
976 } 976 }
977 977
978 CPDF_Stream* pStream = pUnownedObject->AsStream(); 978 CPDF_Stream* pStream = pObject->AsStream();
979 if (!pStream) 979 if (!pStream)
980 return FALSE; 980 return FALSE;
981 981
982 CPDF_Dictionary* pDict = pStream->GetDict(); 982 CPDF_Dictionary* pDict = pStream->GetDict();
983 *pos = pDict->GetIntegerFor("Prev"); 983 *pos = pDict->GetIntegerFor("Prev");
984 int32_t size = pDict->GetIntegerFor("Size"); 984 int32_t size = pDict->GetIntegerFor("Size");
985 if (size < 0) 985 if (size < 0) {
986 pStream->Release();
986 return FALSE; 987 return FALSE;
988 }
987 989
988 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone()); 990 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone());
989 if (bMainXRef) { 991 if (bMainXRef) {
990 m_pTrailer = pNewTrailer; 992 m_pTrailer = pNewTrailer;
991 ShrinkObjectMap(size); 993 ShrinkObjectMap(size);
992 for (auto& it : m_ObjectInfo) 994 for (auto& it : m_ObjectInfo)
993 it.second.type = 0; 995 it.second.type = 0;
994 } else { 996 } else {
995 m_Trailers.Add(pNewTrailer); 997 m_Trailers.Add(pNewTrailer);
996 } 998 }
(...skipping 11 matching lines...) Expand all
1008 if (nStartNum >= 0 && nCount > 0) 1010 if (nStartNum >= 0 && nCount > 0)
1009 arrIndex.push_back(std::make_pair(nStartNum, nCount)); 1011 arrIndex.push_back(std::make_pair(nStartNum, nCount));
1010 } 1012 }
1011 } 1013 }
1012 } 1014 }
1013 1015
1014 if (arrIndex.size() == 0) 1016 if (arrIndex.size() == 0)
1015 arrIndex.push_back(std::make_pair(0, size)); 1017 arrIndex.push_back(std::make_pair(0, size));
1016 1018
1017 pArray = pDict->GetArrayFor("W"); 1019 pArray = pDict->GetArrayFor("W");
1018 if (!pArray) 1020 if (!pArray) {
1021 pStream->Release();
1019 return FALSE; 1022 return FALSE;
1023 }
1020 1024
1021 CFX_ArrayTemplate<uint32_t> WidthArray; 1025 CFX_ArrayTemplate<uint32_t> WidthArray;
1022 FX_SAFE_UINT32 dwAccWidth = 0; 1026 FX_SAFE_UINT32 dwAccWidth = 0;
1023 for (size_t i = 0; i < pArray->GetCount(); ++i) { 1027 for (size_t i = 0; i < pArray->GetCount(); ++i) {
1024 WidthArray.Add(pArray->GetIntegerAt(i)); 1028 WidthArray.Add(pArray->GetIntegerAt(i));
1025 dwAccWidth += WidthArray[i]; 1029 dwAccWidth += WidthArray[i];
1026 } 1030 }
1027 1031
1028 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) 1032 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) {
1033 pStream->Release();
1029 return FALSE; 1034 return FALSE;
1035 }
1030 1036
1031 uint32_t totalWidth = dwAccWidth.ValueOrDie(); 1037 uint32_t totalWidth = dwAccWidth.ValueOrDie();
1032 CPDF_StreamAcc acc; 1038 CPDF_StreamAcc acc;
1033 acc.LoadAllData(pStream); 1039 acc.LoadAllData(pStream);
1034 1040
1035 const uint8_t* pData = acc.GetData(); 1041 const uint8_t* pData = acc.GetData();
1036 uint32_t dwTotalSize = acc.GetSize(); 1042 uint32_t dwTotalSize = acc.GetSize();
1037 uint32_t segindex = 0; 1043 uint32_t segindex = 0;
1038 for (uint32_t i = 0; i < arrIndex.size(); i++) { 1044 for (uint32_t i = 0; i < arrIndex.size(); i++) {
1039 int32_t startnum = arrIndex[i].first; 1045 int32_t startnum = arrIndex[i].first;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 m_ObjectInfo[startnum + j].type = type; 1085 m_ObjectInfo[startnum + j].type = type;
1080 if (type == 0) { 1086 if (type == 0) {
1081 m_ObjectInfo[startnum + j].pos = 0; 1087 m_ObjectInfo[startnum + j].pos = 0;
1082 } else { 1088 } else {
1083 FX_FILESIZE offset = 1089 FX_FILESIZE offset =
1084 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); 1090 GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
1085 m_ObjectInfo[startnum + j].pos = offset; 1091 m_ObjectInfo[startnum + j].pos = offset;
1086 if (type == 1) { 1092 if (type == 1) {
1087 m_SortedOffset.insert(offset); 1093 m_SortedOffset.insert(offset);
1088 } else { 1094 } else {
1089 if (offset < 0 || !IsValidObjectNumber(offset)) 1095 if (offset < 0 || !IsValidObjectNumber(offset)) {
1096 pStream->Release();
1090 return FALSE; 1097 return FALSE;
1098 }
1091 m_ObjectInfo[offset].type = 255; 1099 m_ObjectInfo[offset].type = 255;
1092 } 1100 }
1093 } 1101 }
1094 } 1102 }
1095 segindex += count; 1103 segindex += count;
1096 } 1104 }
1105 pStream->Release();
1097 return TRUE; 1106 return TRUE;
1098 } 1107 }
1099 1108
1100 CPDF_Array* CPDF_Parser::GetIDArray() { 1109 CPDF_Array* CPDF_Parser::GetIDArray() {
1101 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; 1110 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr;
1102 if (!pID) 1111 if (!pID)
1103 return nullptr; 1112 return nullptr;
1104 1113
1105 if (CPDF_Reference* pRef = pID->AsReference()) { 1114 if (CPDF_Reference* pRef = pID->AsReference()) {
1106 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); 1115 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum());
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1628 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1620 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1629 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1621 m_LastXRefOffset = 0; 1630 m_LastXRefOffset = 0;
1622 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1631 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1623 return FORMAT_ERROR; 1632 return FORMAT_ERROR;
1624 } 1633 }
1625 1634
1626 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1635 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1627 return SUCCESS; 1636 return SUCCESS;
1628 } 1637 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_stream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698