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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 579363002: Fix Regression: Incomplete file loading is seen for multi page pdf files. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Strange spacing. Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../../include/fpdfapi/fpdf_parser.h" 7 #include "../../../include/fpdfapi/fpdf_parser.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fpdfapi/fpdf_page.h" 9 #include "../../../include/fpdfapi/fpdf_page.h"
10 #include "../../../../third_party/numerics/safe_math.h" 10 #include "../../../../third_party/numerics/safe_math.h"
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 1020 }
1021 if (bMainXRef) { 1021 if (bMainXRef) {
1022 m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone(); 1022 m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone();
1023 m_CrossRef.SetSize(size); 1023 m_CrossRef.SetSize(size);
1024 if (m_V5Type.SetSize(size)) { 1024 if (m_V5Type.SetSize(size)) {
1025 FXSYS_memset32(m_V5Type.GetData(), 0, size); 1025 FXSYS_memset32(m_V5Type.GetData(), 0, size);
1026 } 1026 }
1027 } else { 1027 } else {
1028 m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone()); 1028 m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone());
1029 } 1029 }
1030 FX_DWORD nSegs = 0; 1030 std::vector<std::pair<FX_INT32, FX_INT32> > arrIndex;
1031 std::vector <std::pair <FX_INT32, FX_INT32>> arrIndex;
1032 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index")); 1031 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index"));
1033 if (pArray) { 1032 if (pArray) {
1034 FX_DWORD nPairSize = pArray->GetCount() / 2; 1033 FX_DWORD nPairSize = pArray->GetCount() / 2;
1035 CPDF_Object* pStartNumObj = NULL;
1036 CPDF_Object* pCountObj = NULL;
1037 for (FX_DWORD i = 0; i < nPairSize; i++) { 1034 for (FX_DWORD i = 0; i < nPairSize; i++) {
1038 pStartNumObj = pArray->GetElement(i * 2); 1035 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2);
1039 pCountObj = pArray->GetElement(i * 2 + 1); 1036 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1);
1040 if (pStartNumObj && pStartNumObj->GetType() == PDFOBJ_NUMBER 1037 if (pStartNumObj && pStartNumObj->GetType() == PDFOBJ_NUMBER
1041 && pCountObj && pCountObj->GetType() == PDFOBJ_NUMBER) { 1038 && pCountObj && pCountObj->GetType() == PDFOBJ_NUMBER) {
1042 arrIndex.push_back(std::make_pair(pStartNumObj->GetInteger(), pC ountObj->GetInteger())); 1039 arrIndex.push_back(std::make_pair(pStartNumObj->GetInteger(), pC ountObj->GetInteger()));
1043 } 1040 }
1044 } 1041 }
1045 nSegs = arrIndex.size(); 1042 }
1046 if (nSegs == 0) { 1043 if (arrIndex.size() == 0) {
1047 arrIndex.push_back(std::make_pair(0, size)); 1044 arrIndex.push_back(std::make_pair(0, size));
1048 nSegs = 1;
1049 }
1050 } 1045 }
1051 pArray = pStream->GetDict()->GetArray(FX_BSTRC("W")); 1046 pArray = pStream->GetDict()->GetArray(FX_BSTRC("W"));
1052 if (pArray == NULL) { 1047 if (pArray == NULL) {
1053 pStream->Release(); 1048 pStream->Release();
1054 return FALSE; 1049 return FALSE;
1055 } 1050 }
1056 CFX_DWordArray WidthArray; 1051 CFX_DWordArray WidthArray;
1057 FX_SAFE_DWORD dwAccWidth = 0; 1052 FX_SAFE_DWORD dwAccWidth = 0;
1058 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) { 1053 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {
1059 WidthArray.Add(pArray->GetInteger(i)); 1054 WidthArray.Add(pArray->GetInteger(i));
1060 dwAccWidth += WidthArray[i]; 1055 dwAccWidth += WidthArray[i];
1061 } 1056 }
1062 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { 1057 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) {
1063 pStream->Release(); 1058 pStream->Release();
1064 return FALSE; 1059 return FALSE;
1065 } 1060 }
1066 FX_DWORD totalWidth = dwAccWidth.ValueOrDie(); 1061 FX_DWORD totalWidth = dwAccWidth.ValueOrDie();
1067 CPDF_StreamAcc acc; 1062 CPDF_StreamAcc acc;
1068 acc.LoadAllData(pStream); 1063 acc.LoadAllData(pStream);
1069 FX_LPCBYTE pData = acc.GetData(); 1064 FX_LPCBYTE pData = acc.GetData();
1070 FX_DWORD dwTotalSize = acc.GetSize(); 1065 FX_DWORD dwTotalSize = acc.GetSize();
1071 FX_DWORD segindex = 0; 1066 FX_DWORD segindex = 0;
1072 for (FX_DWORD i = 0; i < nSegs; i ++) { 1067 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) {
1073 FX_INT32 startnum = arrIndex[i].first; 1068 FX_INT32 startnum = arrIndex[i].first;
1074 if (startnum < 0) { 1069 if (startnum < 0) {
1075 continue; 1070 continue;
1076 } 1071 }
1077 m_dwXrefStartObjNum = base::checked_cast<FX_DWORD, FX_INT32> (startnum); 1072 m_dwXrefStartObjNum = base::checked_cast<FX_DWORD, FX_INT32> (startnum);
1078 FX_DWORD count = base::checked_cast<FX_DWORD, FX_INT32> (arrIndex[i].sec ond); 1073 FX_DWORD count = base::checked_cast<FX_DWORD, FX_INT32> (arrIndex[i].sec ond);
1079 FX_SAFE_DWORD dwCaculatedSize = segindex; 1074 FX_SAFE_DWORD dwCaculatedSize = segindex;
1080 dwCaculatedSize += count; 1075 dwCaculatedSize += count;
1081 dwCaculatedSize *= totalWidth; 1076 dwCaculatedSize *= totalWidth;
1082 if (!dwCaculatedSize.IsValid() || dwCaculatedSize.ValueOrDie() > dwTotal Size) { 1077 if (!dwCaculatedSize.IsValid() || dwCaculatedSize.ValueOrDie() > dwTotal Size) {
(...skipping 3353 matching lines...) Expand 10 before | Expand all | Expand 10 after
4436 { 4431 {
4437 FX_INT32 iSize = m_childNode.GetSize(); 4432 FX_INT32 iSize = m_childNode.GetSize();
4438 for (FX_INT32 i = 0; i < iSize; ++i) { 4433 for (FX_INT32 i = 0; i < iSize; ++i) {
4439 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; 4434 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i];
4440 if (pNode) { 4435 if (pNode) {
4441 delete pNode; 4436 delete pNode;
4442 } 4437 }
4443 } 4438 }
4444 m_childNode.RemoveAll(); 4439 m_childNode.RemoveAll();
4445 } 4440 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698