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

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

Issue 1414393006: Revert "Add type cast definitions for CPDF_Reference." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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 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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (RootObjNum == 0) { 251 if (RootObjNum == 0) {
252 return PDFPARSE_ERROR_FORMAT; 252 return PDFPARSE_ERROR_FORMAT;
253 } 253 }
254 dwRet = SetEncryptHandler(); 254 dwRet = SetEncryptHandler();
255 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 255 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
256 return dwRet; 256 return dwRet;
257 } 257 }
258 } 258 }
259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { 259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
260 CPDF_Reference* pMetadata = 260 CPDF_Reference* pMetadata =
261 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); 261 (CPDF_Reference*)m_pDocument->GetRoot()->GetElement(
262 if (pMetadata) 262 FX_BSTRC("Metadata"));
263 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) {
263 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 264 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
265 }
264 } 266 }
265 return PDFPARSE_ERROR_SUCCESS; 267 return PDFPARSE_ERROR_SUCCESS;
266 } 268 }
267 FX_DWORD CPDF_Parser::SetEncryptHandler() { 269 FX_DWORD CPDF_Parser::SetEncryptHandler() {
268 ReleaseEncryptHandler(); 270 ReleaseEncryptHandler();
269 SetEncryptDictionary(NULL); 271 SetEncryptDictionary(NULL);
270 if (m_pTrailer == NULL) { 272 if (m_pTrailer == NULL) {
271 return PDFPARSE_ERROR_FORMAT; 273 return PDFPARSE_ERROR_FORMAT;
272 } 274 }
273 CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt")); 275 CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt"));
274 if (pEncryptObj) { 276 if (pEncryptObj) {
275 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { 277 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
276 SetEncryptDictionary(pEncryptDict); 278 SetEncryptDictionary(pEncryptDict);
277 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { 279 } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) {
278 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); 280 pEncryptObj = m_pDocument->GetIndirectObject(
279 if (pEncryptObj) 281 ((CPDF_Reference*)pEncryptObj)->GetRefObjNum());
282 if (pEncryptObj) {
280 SetEncryptDictionary(pEncryptObj->GetDict()); 283 SetEncryptDictionary(pEncryptObj->GetDict());
284 }
281 } 285 }
282 } 286 }
283 if (m_bForceUseSecurityHandler) { 287 if (m_bForceUseSecurityHandler) {
284 FX_DWORD err = PDFPARSE_ERROR_HANDLER; 288 FX_DWORD err = PDFPARSE_ERROR_HANDLER;
285 if (!m_pSecurityHandler) { 289 if (!m_pSecurityHandler) {
286 return PDFPARSE_ERROR_HANDLER; 290 return PDFPARSE_ERROR_HANDLER;
287 } 291 }
288 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { 292 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) {
289 return err; 293 return err;
290 } 294 }
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 if (pObj) { 833 if (pObj) {
830 if (!pObj->IsDictionary() && !pObj->AsStream()) { 834 if (!pObj->IsDictionary() && !pObj->AsStream()) {
831 pObj->Release(); 835 pObj->Release();
832 } else { 836 } else {
833 CPDF_Stream* pStream = pObj->AsStream(); 837 CPDF_Stream* pStream = pObj->AsStream();
834 if (CPDF_Dictionary* pTrailer = 838 if (CPDF_Dictionary* pTrailer =
835 pStream ? pStream->GetDict() : pObj->AsDictionary()) { 839 pStream ? pStream->GetDict() : pObj->AsDictionary()) {
836 if (m_pTrailer) { 840 if (m_pTrailer) {
837 CPDF_Object* pRoot = 841 CPDF_Object* pRoot =
838 pTrailer->GetElement(FX_BSTRC("Root")); 842 pTrailer->GetElement(FX_BSTRC("Root"));
839 CPDF_Reference* pRef = ToReference(pRoot); 843 if (pRoot == NULL ||
840 if (!pRoot || 844 (pRoot->GetType() == PDFOBJ_REFERENCE &&
841 (pRef &&
842 (FX_DWORD)m_CrossRef.GetSize() > 845 (FX_DWORD)m_CrossRef.GetSize() >
843 pRef->GetRefObjNum() && 846 ((CPDF_Reference*)pRoot)->GetRefObjNum() &&
844 m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) { 847 m_CrossRef.GetAt(((CPDF_Reference*)pRoot)
848 ->GetRefObjNum()) != 0)) {
845 FX_POSITION pos = pTrailer->GetStartPos(); 849 FX_POSITION pos = pTrailer->GetStartPos();
846 while (pos) { 850 while (pos) {
847 CFX_ByteString key; 851 CFX_ByteString key;
848 CPDF_Object* pObj = 852 CPDF_Object* pObj =
849 pTrailer->GetNextElement(pos, key); 853 pTrailer->GetNextElement(pos, key);
850 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); 854 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument);
851 } 855 }
852 pObj->Release(); 856 pObj->Release();
853 } else { 857 } else {
854 pObj->Release(); 858 pObj->Release();
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 segindex += count; 1122 segindex += count;
1119 } 1123 }
1120 pStream->Release(); 1124 pStream->Release();
1121 return TRUE; 1125 return TRUE;
1122 } 1126 }
1123 CPDF_Array* CPDF_Parser::GetIDArray() { 1127 CPDF_Array* CPDF_Parser::GetIDArray() {
1124 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL; 1128 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL;
1125 if (!pID) 1129 if (!pID)
1126 return nullptr; 1130 return nullptr;
1127 1131
1128 if (CPDF_Reference* pRef = pID->AsReference()) { 1132 if (pID->GetType() == PDFOBJ_REFERENCE) {
1129 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); 1133 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum());
1130 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); 1134 m_pTrailer->SetAt(FX_BSTRC("ID"), pID);
1131 } 1135 }
1132 return ToArray(pID); 1136 return ToArray(pID);
1133 } 1137 }
1134 FX_DWORD CPDF_Parser::GetRootObjNum() { 1138 FX_DWORD CPDF_Parser::GetRootObjNum() {
1135 CPDF_Reference* pRef = ToReference( 1139 CPDF_Object* pRef =
1136 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : nullptr); 1140 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL;
1137 return pRef ? pRef->GetRefObjNum() : 0; 1141 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
1142 return 0;
1143 }
1144 return ((CPDF_Reference*)pRef)->GetRefObjNum();
1138 } 1145 }
1139 FX_DWORD CPDF_Parser::GetInfoObjNum() { 1146 FX_DWORD CPDF_Parser::GetInfoObjNum() {
1140 CPDF_Reference* pRef = ToReference( 1147 CPDF_Object* pRef =
1141 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : nullptr); 1148 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL;
1142 return pRef ? pRef->GetRefObjNum() : 0; 1149 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
1150 return 0;
1151 }
1152 return ((CPDF_Reference*)pRef)->GetRefObjNum();
1143 } 1153 }
1144 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { 1154 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) {
1145 bForm = FALSE; 1155 bForm = FALSE;
1146 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { 1156 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) {
1147 return TRUE; 1157 return TRUE;
1148 } 1158 }
1149 if (m_V5Type[objnum] == 0) { 1159 if (m_V5Type[objnum] == 0) {
1150 return TRUE; 1160 return TRUE;
1151 } 1161 }
1152 if (m_V5Type[objnum] == 2) { 1162 if (m_V5Type[objnum] == 2) {
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 RootObjNum = GetRootObjNum(); 1610 RootObjNum = GetRootObjNum();
1601 if (RootObjNum == 0) { 1611 if (RootObjNum == 0) {
1602 return PDFPARSE_ERROR_FORMAT; 1612 return PDFPARSE_ERROR_FORMAT;
1603 } 1613 }
1604 dwRet = SetEncryptHandler(); 1614 dwRet = SetEncryptHandler();
1605 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1615 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
1606 return dwRet; 1616 return dwRet;
1607 } 1617 }
1608 } 1618 }
1609 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { 1619 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) {
1610 if (CPDF_Reference* pMetadata = ToReference( 1620 CPDF_Object* pMetadata =
1611 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")))) 1621 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"));
1612 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 1622 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) {
1623 m_Syntax.m_MetadataObjnum = ((CPDF_Reference*)pMetadata)->GetRefObjNum();
1624 }
1613 } 1625 }
1614 return PDFPARSE_ERROR_SUCCESS; 1626 return PDFPARSE_ERROR_SUCCESS;
1615 } 1627 }
1616 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { 1628 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) {
1617 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { 1629 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
1618 return FALSE; 1630 return FALSE;
1619 } 1631 }
1620 while (xrefpos) 1632 while (xrefpos)
1621 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { 1633 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
1622 return FALSE; 1634 return FALSE;
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 markers = 1; 2367 markers = 1;
2356 } 2368 }
2357 return markers; 2369 return markers;
2358 } 2370 }
2359 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, 2371 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict,
2360 PARSE_CONTEXT* pContext, 2372 PARSE_CONTEXT* pContext,
2361 FX_DWORD objnum, 2373 FX_DWORD objnum,
2362 FX_DWORD gennum) { 2374 FX_DWORD gennum) {
2363 CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length")); 2375 CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length"));
2364 FX_FILESIZE len = -1; 2376 FX_FILESIZE len = -1;
2365 CPDF_Reference* pLenObjRef = ToReference(pLenObj); 2377 if (pLenObj && ((pLenObj->GetType() != PDFOBJ_REFERENCE) ||
2366 2378 ((((CPDF_Reference*)pLenObj)->GetObjList()) &&
2367 bool differingObjNum = pLenObjRef && pLenObjRef->GetObjList() && 2379 ((CPDF_Reference*)pLenObj)->GetRefObjNum() != objnum))) {
2368 pLenObjRef->GetRefObjNum() != objnum;
2369 if (pLenObj && differingObjNum)
2370 len = pLenObj->GetInteger(); 2380 len = pLenObj->GetInteger();
2371 2381 }
2372 // Locate the start of stream. 2382 // Locate the start of stream.
2373 ToNextLine(); 2383 ToNextLine();
2374 FX_FILESIZE streamStartPos = m_Pos; 2384 FX_FILESIZE streamStartPos = m_Pos;
2375 if (pContext) { 2385 if (pContext) {
2376 pContext->m_DataStart = streamStartPos; 2386 pContext->m_DataStart = streamStartPos;
2377 } 2387 }
2378 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1; 2388 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1;
2379 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1; 2389 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1;
2380 CPDF_CryptoHandler* pCryptoHandler = 2390 CPDF_CryptoHandler* pCryptoHandler =
2381 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get(); 2391 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get();
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 while (pos) { 3057 while (pos) {
3048 CPDF_Object* value; 3058 CPDF_Object* value;
3049 CFX_ByteString key; 3059 CFX_ByteString key;
3050 value = pDict->GetNextElement(pos, key); 3060 value = pDict->GetNextElement(pos, key);
3051 if (key != "Parent") { 3061 if (key != "Parent") {
3052 new_obj_array.Add(value); 3062 new_obj_array.Add(value);
3053 } 3063 }
3054 } 3064 }
3055 } break; 3065 } break;
3056 case PDFOBJ_REFERENCE: { 3066 case PDFOBJ_REFERENCE: {
3057 CPDF_Reference* pRef = pObj->AsReference(); 3067 CPDF_Reference* pRef = (CPDF_Reference*)pObj;
3058 FX_DWORD dwNum = pRef->GetRefObjNum(); 3068 FX_DWORD dwNum = pRef->GetRefObjNum();
3059 FX_FILESIZE offset; 3069 FX_FILESIZE offset;
3060 FX_DWORD original_size = GetObjectSize(dwNum, offset); 3070 FX_DWORD original_size = GetObjectSize(dwNum, offset);
3061 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; 3071 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size;
3062 if (size.ValueOrDefault(0) == 0 || offset < 0 || 3072 if (size.ValueOrDefault(0) == 0 || offset < 0 ||
3063 offset >= m_dwFileLen) { 3073 offset >= m_dwFileLen) {
3064 break; 3074 break;
3065 } 3075 }
3066 3076
3067 size += offset; 3077 size += offset;
(...skipping 21 matching lines...) Expand all
3089 new_obj_array.Add(pReferred); 3099 new_obj_array.Add(pReferred);
3090 } 3100 }
3091 } 3101 }
3092 } break; 3102 } break;
3093 } 3103 }
3094 } 3104 }
3095 if (count > 0) { 3105 if (count > 0) {
3096 int32_t iSize = new_obj_array.GetSize(); 3106 int32_t iSize = new_obj_array.GetSize();
3097 for (i = 0; i < iSize; ++i) { 3107 for (i = 0; i < iSize; ++i) {
3098 CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i]; 3108 CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i];
3099 if (CPDF_Reference* pRef = pObj->AsReference()) { 3109 int32_t type = pObj->GetType();
3110 if (type == PDFOBJ_REFERENCE) {
3111 CPDF_Reference* pRef = (CPDF_Reference*)pObj;
3100 FX_DWORD dwNum = pRef->GetRefObjNum(); 3112 FX_DWORD dwNum = pRef->GetRefObjNum();
3101 if (!m_objnum_array.Find(dwNum)) 3113 if (!m_objnum_array.Find(dwNum)) {
3102 ret_array.Add(pObj); 3114 ret_array.Add(pObj);
3115 }
3103 } else { 3116 } else {
3104 ret_array.Add(pObj); 3117 ret_array.Add(pObj);
3105 } 3118 }
3106 } 3119 }
3107 return FALSE; 3120 return FALSE;
3108 } 3121 }
3109 obj_array.RemoveAll(); 3122 obj_array.RemoveAll();
3110 obj_array.Append(new_obj_array); 3123 obj_array.Append(new_obj_array);
3111 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); 3124 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array);
3112 } 3125 }
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3360 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 3373 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
3361 return TRUE; 3374 return TRUE;
3362 } 3375 }
3363 return FALSE; 3376 return FALSE;
3364 } 3377 }
3365 CPDF_Dictionary* pDict = m_pRoot->GetDict(); 3378 CPDF_Dictionary* pDict = m_pRoot->GetDict();
3366 if (!pDict) { 3379 if (!pDict) {
3367 m_docStatus = PDF_DATAAVAIL_ERROR; 3380 m_docStatus = PDF_DATAAVAIL_ERROR;
3368 return FALSE; 3381 return FALSE;
3369 } 3382 }
3370 CPDF_Reference* pRef = ToReference(pDict->GetElement(FX_BSTRC("Pages"))); 3383 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages"));
3371 if (!pRef) { 3384 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
3372 m_docStatus = PDF_DATAAVAIL_ERROR; 3385 m_docStatus = PDF_DATAAVAIL_ERROR;
3373 return FALSE; 3386 return FALSE;
3374 } 3387 }
3375
3376 m_PagesObjNum = pRef->GetRefObjNum(); 3388 m_PagesObjNum = pRef->GetRefObjNum();
3377 CPDF_Reference* pAcroFormRef = 3389 CPDF_Reference* pAcroFormRef =
3378 ToReference(m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm"))); 3390 (CPDF_Reference*)m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm"));
3379 if (pAcroFormRef) { 3391 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) {
3380 m_bHaveAcroForm = TRUE; 3392 m_bHaveAcroForm = TRUE;
3381 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); 3393 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum();
3382 } 3394 }
3383
3384 if (m_dwInfoObjNum) { 3395 if (m_dwInfoObjNum) {
3385 m_docStatus = PDF_DATAAVAIL_INFO; 3396 m_docStatus = PDF_DATAAVAIL_INFO;
3386 } else { 3397 } else {
3387 m_docStatus = 3398 if (m_bHaveAcroForm) {
3388 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; 3399 m_docStatus = PDF_DATAAVAIL_ACROFORM;
3400 } else {
3401 m_docStatus = PDF_DATAAVAIL_PAGETREE;
3402 }
3389 } 3403 }
3390 return TRUE; 3404 return TRUE;
3391 } 3405 }
3392 FX_BOOL CPDF_DataAvail::PreparePageItem() { 3406 FX_BOOL CPDF_DataAvail::PreparePageItem() {
3393 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); 3407 CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
3394 CPDF_Reference* pRef = 3408 CPDF_Reference* pRef =
3395 ToReference(pRoot ? pRoot->GetElement(FX_BSTRC("Pages")) : nullptr); 3409 pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL;
3396 if (!pRef) { 3410 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
3397 m_docStatus = PDF_DATAAVAIL_ERROR; 3411 m_docStatus = PDF_DATAAVAIL_ERROR;
3398 return FALSE; 3412 return FALSE;
3399 } 3413 }
3400
3401 m_PagesObjNum = pRef->GetRefObjNum(); 3414 m_PagesObjNum = pRef->GetRefObjNum();
3402 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); 3415 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser();
3403 m_docStatus = PDF_DATAAVAIL_PAGETREE; 3416 m_docStatus = PDF_DATAAVAIL_PAGETREE;
3404 return TRUE; 3417 return TRUE;
3405 } 3418 }
3406 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { 3419 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) {
3407 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) 3420 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end())
3408 return FALSE; 3421 return FALSE;
3409 3422
3410 m_pageMapCheckState.insert(iPage); 3423 m_pageMapCheckState.insert(iPage);
(...skipping 12 matching lines...) Expand all
3423 if (!pObj) { 3436 if (!pObj) {
3424 if (bExist) { 3437 if (bExist) {
3425 UnavailObjList.Add(dwPageObjNum); 3438 UnavailObjList.Add(dwPageObjNum);
3426 } 3439 }
3427 continue; 3440 continue;
3428 } 3441 }
3429 if (pObj->IsArray()) { 3442 if (pObj->IsArray()) {
3430 CPDF_Array* pArray = pObj->GetArray(); 3443 CPDF_Array* pArray = pObj->GetArray();
3431 if (pArray) { 3444 if (pArray) {
3432 int32_t iSize = pArray->GetCount(); 3445 int32_t iSize = pArray->GetCount();
3446 CPDF_Object* pItem = NULL;
3433 for (int32_t j = 0; j < iSize; ++j) { 3447 for (int32_t j = 0; j < iSize; ++j) {
3434 if (CPDF_Reference* pRef = ToReference(pArray->GetElement(j))) 3448 pItem = pArray->GetElement(j);
3435 UnavailObjList.Add(pRef->GetRefObjNum()); 3449 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) {
3450 UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum());
3451 }
3436 } 3452 }
3437 } 3453 }
3438 } 3454 }
3439 if (!pObj->IsDictionary()) { 3455 if (!pObj->IsDictionary()) {
3440 pObj->Release(); 3456 pObj->Release();
3441 continue; 3457 continue;
3442 } 3458 }
3443 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); 3459 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type"));
3444 if (type == FX_BSTRC("Pages")) { 3460 if (type == FX_BSTRC("Pages")) {
3445 m_PagesArray.Add(pObj); 3461 m_PagesArray.Add(pObj);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3480 if (!pParser) { 3496 if (!pParser) {
3481 m_docStatus = PDF_DATAAVAIL_ERROR; 3497 m_docStatus = PDF_DATAAVAIL_ERROR;
3482 return FALSE; 3498 return FALSE;
3483 } 3499 }
3484 CPDF_Dictionary* pDict = pPages->GetDict(); 3500 CPDF_Dictionary* pDict = pPages->GetDict();
3485 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; 3501 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL;
3486 if (!pKids) { 3502 if (!pKids) {
3487 return TRUE; 3503 return TRUE;
3488 } 3504 }
3489 switch (pKids->GetType()) { 3505 switch (pKids->GetType()) {
3490 case PDFOBJ_REFERENCE: 3506 case PDFOBJ_REFERENCE: {
3491 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); 3507 CPDF_Reference* pKid = (CPDF_Reference*)pKids;
3492 break; 3508 m_PageObjList.Add(pKid->GetRefObjNum());
3509 } break;
3493 case PDFOBJ_ARRAY: { 3510 case PDFOBJ_ARRAY: {
3494 CPDF_Array* pKidsArray = pKids->AsArray(); 3511 CPDF_Array* pKidsArray = pKids->AsArray();
3495 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { 3512 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
3496 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i))) 3513 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i);
3497 m_PageObjList.Add(pRef->GetRefObjNum()); 3514 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) {
3515 m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum());
3516 }
3498 } 3517 }
3499 } break; 3518 } break;
3500 default: 3519 default:
3501 m_docStatus = PDF_DATAAVAIL_ERROR; 3520 m_docStatus = PDF_DATAAVAIL_ERROR;
3502 return FALSE; 3521 return FALSE;
3503 } 3522 }
3504 return TRUE; 3523 return TRUE;
3505 } 3524 }
3506 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) { 3525 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) {
3507 FX_BOOL bExist = FALSE; 3526 FX_BOOL bExist = FALSE;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
3986 if (!pTrailer) { 4005 if (!pTrailer) {
3987 m_Pos += m_syntaxParser.SavePos(); 4006 m_Pos += m_syntaxParser.SavePos();
3988 pHints->AddSegment(m_Pos, iTrailerSize); 4007 pHints->AddSegment(m_Pos, iTrailerSize);
3989 return FALSE; 4008 return FALSE;
3990 } 4009 }
3991 if (!pTrailer->IsDictionary()) 4010 if (!pTrailer->IsDictionary())
3992 return FALSE; 4011 return FALSE;
3993 4012
3994 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); 4013 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict();
3995 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); 4014 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt");
3996 if (ToReference(pEncrypt)) { 4015 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) {
3997 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 4016 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
3998 return TRUE; 4017 return TRUE;
3999 } 4018 }
4000 4019
4001 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, FX_BSTRC("Prev")); 4020 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, FX_BSTRC("Prev"));
4002 if (xrefpos) { 4021 if (xrefpos) {
4003 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, FX_BSTRC("XRefStm")); 4022 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, FX_BSTRC("XRefStm"));
4004 if (m_dwPrevXRefOffset) { 4023 if (m_dwPrevXRefOffset) {
4005 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 4024 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
4006 } else { 4025 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4065 4084
4066 CPDF_Array* pArray = pPages->AsArray(); 4085 CPDF_Array* pArray = pPages->AsArray();
4067 if (!pArray) { 4086 if (!pArray) {
4068 pPages->Release(); 4087 pPages->Release();
4069 m_docStatus = PDF_DATAAVAIL_ERROR; 4088 m_docStatus = PDF_DATAAVAIL_ERROR;
4070 return FALSE; 4089 return FALSE;
4071 } 4090 }
4072 4091
4073 pPageNode->m_type = PDF_PAGENODE_PAGES; 4092 pPageNode->m_type = PDF_PAGENODE_PAGES;
4074 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { 4093 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) {
4075 CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); 4094 CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i);
4076 if (!pKid) 4095 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) {
4077 continue; 4096 continue;
4078 4097 }
4079 CPDF_PageNode* pNode = new CPDF_PageNode(); 4098 CPDF_PageNode* pNode = new CPDF_PageNode();
4080 pPageNode->m_childNode.Add(pNode); 4099 pPageNode->m_childNode.Add(pNode);
4081 pNode->m_dwPageNo = pKid->GetRefObjNum(); 4100 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum();
4082 } 4101 }
4083 pPages->Release(); 4102 pPages->Release();
4084 return TRUE; 4103 return TRUE;
4085 } 4104 }
4086 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, 4105 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
4087 CPDF_PageNode* pPageNode, 4106 CPDF_PageNode* pPageNode,
4088 IFX_DownloadHints* pHints) { 4107 IFX_DownloadHints* pHints) {
4089 FX_BOOL bExist = FALSE; 4108 FX_BOOL bExist = FALSE;
4090 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); 4109 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist);
4091 if (!bExist) { 4110 if (!bExist) {
(...skipping 23 matching lines...) Expand all
4115 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type")); 4134 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type"));
4116 if (type == FX_BSTRC("Pages")) { 4135 if (type == FX_BSTRC("Pages")) {
4117 pPageNode->m_type = PDF_PAGENODE_PAGES; 4136 pPageNode->m_type = PDF_PAGENODE_PAGES;
4118 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids")); 4137 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids"));
4119 if (!pKids) { 4138 if (!pKids) {
4120 m_docStatus = PDF_DATAAVAIL_PAGE; 4139 m_docStatus = PDF_DATAAVAIL_PAGE;
4121 return TRUE; 4140 return TRUE;
4122 } 4141 }
4123 switch (pKids->GetType()) { 4142 switch (pKids->GetType()) {
4124 case PDFOBJ_REFERENCE: { 4143 case PDFOBJ_REFERENCE: {
4125 CPDF_Reference* pKid = pKids->AsReference(); 4144 CPDF_Reference* pKid = (CPDF_Reference*)pKids;
4126 CPDF_PageNode* pNode = new CPDF_PageNode(); 4145 CPDF_PageNode* pNode = new CPDF_PageNode();
4127 pPageNode->m_childNode.Add(pNode); 4146 pPageNode->m_childNode.Add(pNode);
4128 pNode->m_dwPageNo = pKid->GetRefObjNum(); 4147 pNode->m_dwPageNo = pKid->GetRefObjNum();
4129 } break; 4148 } break;
4130 case PDFOBJ_ARRAY: { 4149 case PDFOBJ_ARRAY: {
4131 CPDF_Array* pKidsArray = pKids->AsArray(); 4150 CPDF_Array* pKidsArray = pKids->AsArray();
4132 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { 4151 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
4133 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); 4152 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i);
4134 if (!pKid) 4153 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) {
4135 continue; 4154 continue;
4136 4155 }
4137 CPDF_PageNode* pNode = new CPDF_PageNode(); 4156 CPDF_PageNode* pNode = new CPDF_PageNode();
4138 pPageNode->m_childNode.Add(pNode); 4157 pPageNode->m_childNode.Add(pNode);
4139 pNode->m_dwPageNo = pKid->GetRefObjNum(); 4158 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum();
4140 } 4159 }
4141 } break; 4160 } break;
4142 default: 4161 default:
4143 break; 4162 break;
4144 } 4163 }
4145 } else if (type == FX_BSTRC("Page")) { 4164 } else if (type == FX_BSTRC("Page")) {
4146 pPageNode->m_type = PDF_PAGENODE_PAGE; 4165 pPageNode->m_type = PDF_PAGENODE_PAGE;
4147 } else { 4166 } else {
4148 pPage->Release(); 4167 pPage->Release();
4149 m_docStatus = PDF_DATAAVAIL_ERROR; 4168 m_docStatus = PDF_DATAAVAIL_ERROR;
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
4568 return FALSE; 4587 return FALSE;
4569 } 4588 }
4570 CPDF_PageNode::~CPDF_PageNode() { 4589 CPDF_PageNode::~CPDF_PageNode() {
4571 int32_t iSize = m_childNode.GetSize(); 4590 int32_t iSize = m_childNode.GetSize();
4572 for (int32_t i = 0; i < iSize; ++i) { 4591 for (int32_t i = 0; i < iSize; ++i) {
4573 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; 4592 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i];
4574 delete pNode; 4593 delete pNode;
4575 } 4594 }
4576 m_childNode.RemoveAll(); 4595 m_childNode.RemoveAll();
4577 } 4596 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698