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

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

Issue 1476163002: Add basic checking for RebuildCrossRef (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years 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 | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp » ('j') | 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 "parser_int.h" 7 #include "parser_int.h"
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 m_pDocument->LoadDoc(); 244 m_pDocument->LoadDoc();
245 if (!m_pDocument->GetRoot()) 245 if (!m_pDocument->GetRoot())
246 return PDFPARSE_ERROR_FORMAT; 246 return PDFPARSE_ERROR_FORMAT;
247 } 247 }
248 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 248 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
249 sizeof(FX_FILESIZE), CompareFileSize); 249 sizeof(FX_FILESIZE), CompareFileSize);
250 FX_DWORD RootObjNum = GetRootObjNum(); 250 FX_DWORD RootObjNum = GetRootObjNum();
251 if (RootObjNum == 0) { 251 if (RootObjNum == 0) {
252 ReleaseEncryptHandler(); 252 ReleaseEncryptHandler();
253 RebuildCrossRef(); 253 RebuildCrossRef();
Lei Zhang 2015/11/26 00:42:41 Should we check the result, now that it can actual
Wei Li 2015/11/26 01:22:22 Done.
254 RootObjNum = GetRootObjNum(); 254 RootObjNum = GetRootObjNum();
255 if (RootObjNum == 0) 255 if (RootObjNum == 0)
256 return PDFPARSE_ERROR_FORMAT; 256 return PDFPARSE_ERROR_FORMAT;
257 257
258 dwRet = SetEncryptHandler(); 258 dwRet = SetEncryptHandler();
259 if (dwRet != PDFPARSE_ERROR_SUCCESS) 259 if (dwRet != PDFPARSE_ERROR_SUCCESS)
260 return dwRet; 260 return dwRet;
261 } 261 }
262 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { 262 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
263 CPDF_Reference* pMetadata = 263 CPDF_Reference* pMetadata =
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 last_trailer = m_Syntax.m_FileLen; 968 last_trailer = m_Syntax.m_FileLen;
969 } 969 }
970 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; 970 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset;
971 void* pResult = 971 void* pResult =
972 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 972 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
973 sizeof(FX_FILESIZE), CompareFileSize); 973 sizeof(FX_FILESIZE), CompareFileSize);
974 if (pResult == NULL) { 974 if (pResult == NULL) {
975 m_SortedOffset.Add(offset); 975 m_SortedOffset.Add(offset);
976 } 976 }
977 FX_Free(buffer); 977 FX_Free(buffer);
978 return TRUE; 978 return m_pTrailer && m_CrossRef.GetSize() > 0;
979 } 979 }
980 980
981 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, 981 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos,
982 FX_FILESIZE& prev, 982 FX_FILESIZE& prev,
983 FX_BOOL bMainXRef) { 983 FX_BOOL bMainXRef) {
984 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr); 984 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr);
985 if (!pObject) 985 if (!pObject)
986 return FALSE; 986 return FALSE;
987 987
988 if (m_pDocument) { 988 if (m_pDocument) {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); 1604 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict());
1605 if (m_pDocument->GetRoot() == NULL) { 1605 if (m_pDocument->GetRoot() == NULL) {
1606 return PDFPARSE_ERROR_FORMAT; 1606 return PDFPARSE_ERROR_FORMAT;
1607 } 1607 }
1608 } 1608 }
1609 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1609 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1610 sizeof(FX_FILESIZE), CompareFileSize); 1610 sizeof(FX_FILESIZE), CompareFileSize);
1611 FX_DWORD RootObjNum = GetRootObjNum(); 1611 FX_DWORD RootObjNum = GetRootObjNum();
1612 if (RootObjNum == 0) { 1612 if (RootObjNum == 0) {
1613 ReleaseEncryptHandler(); 1613 ReleaseEncryptHandler();
1614 RebuildCrossRef(); 1614 RebuildCrossRef();
Lei Zhang 2015/11/26 00:42:41 Ditto. In fact, this block looks a lot like the on
Wei Li 2015/11/26 01:22:22 Done. Yes, some might be put into common functions
1615 RootObjNum = GetRootObjNum(); 1615 RootObjNum = GetRootObjNum();
1616 if (RootObjNum == 0) { 1616 if (RootObjNum == 0) {
1617 return PDFPARSE_ERROR_FORMAT; 1617 return PDFPARSE_ERROR_FORMAT;
1618 } 1618 }
1619 dwRet = SetEncryptHandler(); 1619 dwRet = SetEncryptHandler();
1620 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1620 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
1621 return dwRet; 1621 return dwRet;
1622 } 1622 }
1623 } 1623 }
1624 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { 1624 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) {
(...skipping 3322 matching lines...) Expand 10 before | Expand all | Expand 10 after
4947 if (!m_pLinearizedDict) 4947 if (!m_pLinearizedDict)
4948 return -1; 4948 return -1;
4949 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); 4949 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H"));
4950 if (!pRange) 4950 if (!pRange)
4951 return -1; 4951 return -1;
4952 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4952 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4953 if (!pStreamLen) 4953 if (!pStreamLen)
4954 return -1; 4954 return -1;
4955 return pStreamLen->GetInteger(); 4955 return pStreamLen->GetInteger();
4956 } 4956 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698