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

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

Issue 2375343004: Assert that only 0-numbered objects are Released() (Closed)
Patch Set: brute-force delete unowned numbered object in one place 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 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0); 959 std::unique_ptr<CPDF_Object> pObject(
960 ParseIndirectObjectAt(m_pDocument, *pos, 0));
960 if (!pObject) 961 if (!pObject)
961 return FALSE; 962 return FALSE;
962 963
963 if (m_pDocument) { 964 if (m_pDocument) {
964 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot(); 965 CPDF_Dictionary* pRootDict = m_pDocument->GetRoot();
965 if (pRootDict && pRootDict->GetObjNum() == pObject->m_ObjNum) { 966 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();
970 return FALSE; 967 return FALSE;
971 }
972 if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(pObject->m_ObjNum,
973 pObject)) {
974 return FALSE;
975 }
976 } 968 }
977 969
978 CPDF_Stream* pStream = pObject->AsStream(); 970 CPDF_Stream* pStream = pObject->AsStream();
Lei Zhang 2016/09/30 23:49:01 Do you know if |pObject| is expected to be a strea
Tom Sepez 2016/10/01 00:13:11 Done.
979 if (!pStream) 971 if (!pStream)
980 return FALSE; 972 return FALSE;
981 973
974 if (m_pDocument) {
975 // Takes ownership of object (std::move someday).
976 uint32_t objnum = pObject->m_ObjNum;
977 if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(
Lei Zhang 2016/09/30 23:49:01 Or should this stay up with the other if (m_pDocum
Tom Sepez 2016/10/01 00:13:11 Done.
Lei Zhang 2016/10/01 01:24:06 So I still wonder if changing the order of AsStrea
Tom Sepez 2016/10/03 17:35:05 Done.
978 objnum, pObject.release())) {
979 return FALSE;
980 }
981 }
982
982 CPDF_Dictionary* pDict = pStream->GetDict(); 983 CPDF_Dictionary* pDict = pStream->GetDict();
983 *pos = pDict->GetIntegerFor("Prev"); 984 *pos = pDict->GetIntegerFor("Prev");
984 int32_t size = pDict->GetIntegerFor("Size"); 985 int32_t size = pDict->GetIntegerFor("Size");
985 if (size < 0) { 986 if (size < 0)
986 pStream->Release();
987 return FALSE; 987 return FALSE;
988 }
989 988
990 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone()); 989 CPDF_Dictionary* pNewTrailer = ToDictionary(pDict->Clone());
991 if (bMainXRef) { 990 if (bMainXRef) {
992 m_pTrailer = pNewTrailer; 991 m_pTrailer = pNewTrailer;
993 ShrinkObjectMap(size); 992 ShrinkObjectMap(size);
994 for (auto& it : m_ObjectInfo) 993 for (auto& it : m_ObjectInfo)
995 it.second.type = 0; 994 it.second.type = 0;
996 } else { 995 } else {
997 m_Trailers.Add(pNewTrailer); 996 m_Trailers.Add(pNewTrailer);
998 } 997 }
(...skipping 11 matching lines...) Expand all
1010 if (nStartNum >= 0 && nCount > 0) 1009 if (nStartNum >= 0 && nCount > 0)
1011 arrIndex.push_back(std::make_pair(nStartNum, nCount)); 1010 arrIndex.push_back(std::make_pair(nStartNum, nCount));
1012 } 1011 }
1013 } 1012 }
1014 } 1013 }
1015 1014
1016 if (arrIndex.size() == 0) 1015 if (arrIndex.size() == 0)
1017 arrIndex.push_back(std::make_pair(0, size)); 1016 arrIndex.push_back(std::make_pair(0, size));
1018 1017
1019 pArray = pDict->GetArrayFor("W"); 1018 pArray = pDict->GetArrayFor("W");
1020 if (!pArray) { 1019 if (!pArray)
1021 pStream->Release();
1022 return FALSE; 1020 return FALSE;
1023 }
1024 1021
1025 CFX_ArrayTemplate<uint32_t> WidthArray; 1022 CFX_ArrayTemplate<uint32_t> WidthArray;
1026 FX_SAFE_UINT32 dwAccWidth = 0; 1023 FX_SAFE_UINT32 dwAccWidth = 0;
1027 for (size_t i = 0; i < pArray->GetCount(); ++i) { 1024 for (size_t i = 0; i < pArray->GetCount(); ++i) {
1028 WidthArray.Add(pArray->GetIntegerAt(i)); 1025 WidthArray.Add(pArray->GetIntegerAt(i));
1029 dwAccWidth += WidthArray[i]; 1026 dwAccWidth += WidthArray[i];
1030 } 1027 }
1031 1028
1032 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { 1029 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3)
1033 pStream->Release();
1034 return FALSE; 1030 return FALSE;
1035 }
1036 1031
1037 uint32_t totalWidth = dwAccWidth.ValueOrDie(); 1032 uint32_t totalWidth = dwAccWidth.ValueOrDie();
1038 CPDF_StreamAcc acc; 1033 CPDF_StreamAcc acc;
1039 acc.LoadAllData(pStream); 1034 acc.LoadAllData(pStream);
1040 1035
1041 const uint8_t* pData = acc.GetData(); 1036 const uint8_t* pData = acc.GetData();
1042 uint32_t dwTotalSize = acc.GetSize(); 1037 uint32_t dwTotalSize = acc.GetSize();
1043 uint32_t segindex = 0; 1038 uint32_t segindex = 0;
1044 for (uint32_t i = 0; i < arrIndex.size(); i++) { 1039 for (uint32_t i = 0; i < arrIndex.size(); i++) {
1045 int32_t startnum = arrIndex[i].first; 1040 int32_t startnum = arrIndex[i].first;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 m_ObjectInfo[startnum + j].type = type; 1080 m_ObjectInfo[startnum + j].type = type;
1086 if (type == 0) { 1081 if (type == 0) {
1087 m_ObjectInfo[startnum + j].pos = 0; 1082 m_ObjectInfo[startnum + j].pos = 0;
1088 } else { 1083 } else {
1089 FX_FILESIZE offset = 1084 FX_FILESIZE offset =
1090 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); 1085 GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
1091 m_ObjectInfo[startnum + j].pos = offset; 1086 m_ObjectInfo[startnum + j].pos = offset;
1092 if (type == 1) { 1087 if (type == 1) {
1093 m_SortedOffset.insert(offset); 1088 m_SortedOffset.insert(offset);
1094 } else { 1089 } else {
1095 if (offset < 0 || !IsValidObjectNumber(offset)) { 1090 if (offset < 0 || !IsValidObjectNumber(offset))
1096 pStream->Release();
1097 return FALSE; 1091 return FALSE;
1098 }
1099 m_ObjectInfo[offset].type = 255; 1092 m_ObjectInfo[offset].type = 255;
1100 } 1093 }
1101 } 1094 }
1102 } 1095 }
1103 segindex += count; 1096 segindex += count;
1104 } 1097 }
1105 pStream->Release();
1106 return TRUE; 1098 return TRUE;
1107 } 1099 }
1108 1100
1109 CPDF_Array* CPDF_Parser::GetIDArray() { 1101 CPDF_Array* CPDF_Parser::GetIDArray() {
1110 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; 1102 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr;
1111 if (!pID) 1103 if (!pID)
1112 return nullptr; 1104 return nullptr;
1113 1105
1114 if (CPDF_Reference* pRef = pID->AsReference()) { 1106 if (CPDF_Reference* pRef = pID->AsReference()) {
1115 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); 1107 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum());
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1620 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1629 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1621 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1630 m_LastXRefOffset = 0; 1622 m_LastXRefOffset = 0;
1631 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1623 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1632 return FORMAT_ERROR; 1624 return FORMAT_ERROR;
1633 } 1625 }
1634 1626
1635 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1627 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1636 return SUCCESS; 1628 return SUCCESS;
1637 } 1629 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698