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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase 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
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 CPDF_Reference* pMetadata = 266 CPDF_Reference* pMetadata =
267 ToReference(m_pDocument->GetRoot()->GetElement("Metadata")); 267 ToReference(m_pDocument->GetRoot()->GetElement("Metadata"));
268 if (pMetadata) 268 if (pMetadata)
269 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 269 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
270 } 270 }
271 return PDFPARSE_ERROR_SUCCESS; 271 return PDFPARSE_ERROR_SUCCESS;
272 } 272 }
273 FX_DWORD CPDF_Parser::SetEncryptHandler() { 273 FX_DWORD CPDF_Parser::SetEncryptHandler() {
274 ReleaseEncryptHandler(); 274 ReleaseEncryptHandler();
275 SetEncryptDictionary(NULL); 275 SetEncryptDictionary(NULL);
276 if (m_pTrailer == NULL) { 276 if (!m_pTrailer) {
277 return PDFPARSE_ERROR_FORMAT; 277 return PDFPARSE_ERROR_FORMAT;
278 } 278 }
279 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); 279 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt");
280 if (pEncryptObj) { 280 if (pEncryptObj) {
281 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { 281 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
282 SetEncryptDictionary(pEncryptDict); 282 SetEncryptDictionary(pEncryptDict);
283 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { 283 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) {
284 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); 284 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum());
285 if (pEncryptObj) 285 if (pEncryptObj)
286 SetEncryptDictionary(pEncryptObj->GetDict()); 286 SetEncryptDictionary(pEncryptObj->GetDict());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return m_CrossRef[(int32_t)m_CrossRef[objnum]]; 341 return m_CrossRef[(int32_t)m_CrossRef[objnum]];
342 } 342 }
343 return 0; 343 return 0;
344 } 344 }
345 345
346 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { 346 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) {
347 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) { 347 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) {
348 return FALSE; 348 return FALSE;
349 } 349 }
350 m_pTrailer = LoadTrailerV4(); 350 m_pTrailer = LoadTrailerV4();
351 if (m_pTrailer == NULL) { 351 if (!m_pTrailer) {
352 return FALSE; 352 return FALSE;
353 } 353 }
354 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); 354 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size");
355 if (xrefsize <= 0 || xrefsize > (1 << 20)) { 355 if (xrefsize <= 0 || xrefsize > (1 << 20)) {
356 return FALSE; 356 return FALSE;
357 } 357 }
358 m_CrossRef.SetSize(xrefsize); 358 m_CrossRef.SetSize(xrefsize);
359 m_V5Type.SetSize(xrefsize); 359 m_V5Type.SetSize(xrefsize);
360 CFX_FileSizeArray CrossRefList, XRefStreamList; 360 CFX_FileSizeArray CrossRefList, XRefStreamList;
361 CrossRefList.Add(xrefpos); 361 CrossRefList.Add(xrefpos);
(...skipping 30 matching lines...) Expand all
392 return FALSE; 392 return FALSE;
393 } 393 }
394 return TRUE; 394 return TRUE;
395 } 395 }
396 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, 396 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos,
397 FX_DWORD dwObjCount) { 397 FX_DWORD dwObjCount) {
398 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { 398 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) {
399 return FALSE; 399 return FALSE;
400 } 400 }
401 m_pTrailer = LoadTrailerV4(); 401 m_pTrailer = LoadTrailerV4();
402 if (m_pTrailer == NULL) { 402 if (!m_pTrailer) {
403 return FALSE; 403 return FALSE;
404 } 404 }
405 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); 405 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size");
406 if (xrefsize == 0) { 406 if (xrefsize == 0) {
407 return FALSE; 407 return FALSE;
408 } 408 }
409 CFX_FileSizeArray CrossRefList, XRefStreamList; 409 CFX_FileSizeArray CrossRefList, XRefStreamList;
410 CrossRefList.Add(xrefpos); 410 CrossRefList.Add(xrefpos);
411 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); 411 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm"));
412 xrefpos = GetDirectInteger(m_pTrailer, "Prev"); 412 xrefpos = GetDirectInteger(m_pTrailer, "Prev");
413 while (xrefpos) { 413 while (xrefpos) {
414 CrossRefList.InsertAt(0, xrefpos); 414 CrossRefList.InsertAt(0, xrefpos);
415 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE); 415 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE);
416 CPDF_Dictionary* pDict = LoadTrailerV4(); 416 CPDF_Dictionary* pDict = LoadTrailerV4();
417 if (pDict == NULL) { 417 if (!pDict) {
418 return FALSE; 418 return FALSE;
419 } 419 }
420 xrefpos = GetDirectInteger(pDict, "Prev"); 420 xrefpos = GetDirectInteger(pDict, "Prev");
421 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm")); 421 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm"));
422 m_Trailers.Add(pDict); 422 m_Trailers.Add(pDict);
423 } 423 }
424 for (int32_t i = 1; i < CrossRefList.GetSize(); i++) 424 for (int32_t i = 1; i < CrossRefList.GetSize(); i++)
425 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) { 425 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) {
426 return FALSE; 426 return FALSE;
427 } 427 }
428 return TRUE; 428 return TRUE;
429 } 429 }
430 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, 430 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos,
431 FX_DWORD dwObjCount) { 431 FX_DWORD dwObjCount) {
432 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; 432 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset;
433 m_Syntax.RestorePos(dwStartPos); 433 m_Syntax.RestorePos(dwStartPos);
434 void* pResult = 434 void* pResult =
435 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 435 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
436 sizeof(FX_FILESIZE), CompareFileSize); 436 sizeof(FX_FILESIZE), CompareFileSize);
437 if (pResult == NULL) { 437 if (!pResult) {
438 m_SortedOffset.Add(pos); 438 m_SortedOffset.Add(pos);
439 } 439 }
440 FX_DWORD start_objnum = 0; 440 FX_DWORD start_objnum = 0;
441 FX_DWORD count = dwObjCount; 441 FX_DWORD count = dwObjCount;
442 FX_FILESIZE SavedPos = m_Syntax.SavePos(); 442 FX_FILESIZE SavedPos = m_Syntax.SavePos();
443 const int32_t recordsize = 20; 443 const int32_t recordsize = 20;
444 std::vector<char> buf(1024 * recordsize + 1); 444 std::vector<char> buf(1024 * recordsize + 1);
445 char* pBuf = pdfium::vector_as_array(&buf); 445 char* pBuf = pdfium::vector_as_array(&buf);
446 pBuf[1024 * recordsize] = '\0'; 446 pBuf[1024 * recordsize] = '\0';
447 int32_t nBlocks = count / 1024 + 1; 447 int32_t nBlocks = count / 1024 + 1;
(...skipping 23 matching lines...) Expand all
471 m_CrossRef.SetAtGrow(objnum, offset); 471 m_CrossRef.SetAtGrow(objnum, offset);
472 int32_t version = FXSYS_atoi(pEntry + 11); 472 int32_t version = FXSYS_atoi(pEntry + 11);
473 if (version >= 1) { 473 if (version >= 1) {
474 m_bVersionUpdated = TRUE; 474 m_bVersionUpdated = TRUE;
475 } 475 }
476 m_ObjVersion.SetAtGrow(objnum, version); 476 m_ObjVersion.SetAtGrow(objnum, version);
477 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { 477 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) {
478 void* pResult = FXSYS_bsearch( 478 void* pResult = FXSYS_bsearch(
479 &m_CrossRef[objnum], m_SortedOffset.GetData(), 479 &m_CrossRef[objnum], m_SortedOffset.GetData(),
480 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); 480 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize);
481 if (pResult == NULL) { 481 if (!pResult) {
482 m_SortedOffset.Add(m_CrossRef[objnum]); 482 m_SortedOffset.Add(m_CrossRef[objnum]);
483 } 483 }
484 } 484 }
485 m_V5Type.SetAtGrow(objnum, 1); 485 m_V5Type.SetAtGrow(objnum, 1);
486 } 486 }
487 } 487 }
488 } 488 }
489 m_Syntax.RestorePos(SavedPos + count * recordsize); 489 m_Syntax.RestorePos(SavedPos + count * recordsize);
490 return TRUE; 490 return TRUE;
491 } 491 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 if (objnum > 0x1000000) { 771 if (objnum > 0x1000000) {
772 status = 0; 772 status = 0;
773 break; 773 break;
774 } 774 }
775 FX_FILESIZE obj_pos = start_pos - m_Syntax.m_HeaderOffset; 775 FX_FILESIZE obj_pos = start_pos - m_Syntax.m_HeaderOffset;
776 last_obj = start_pos; 776 last_obj = start_pos;
777 void* pResult = 777 void* pResult =
778 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), 778 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(),
779 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), 779 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE),
780 CompareFileSize); 780 CompareFileSize);
781 if (pResult == NULL) { 781 if (!pResult) {
782 m_SortedOffset.Add(obj_pos); 782 m_SortedOffset.Add(obj_pos);
783 } 783 }
784 FX_FILESIZE obj_end = 0; 784 FX_FILESIZE obj_end = 0;
785 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( 785 CPDF_Object* pObject = ParseIndirectObjectAtByStrict(
786 m_pDocument, obj_pos, objnum, NULL, &obj_end); 786 m_pDocument, obj_pos, objnum, NULL, &obj_end);
787 if (CPDF_Stream* pStream = ToStream(pObject)) { 787 if (CPDF_Stream* pStream = ToStream(pObject)) {
788 if (CPDF_Dictionary* pDict = pStream->GetDict()) { 788 if (CPDF_Dictionary* pDict = pStream->GetDict()) {
789 if ((pDict->KeyExist("Type")) && 789 if ((pDict->KeyExist("Type")) &&
790 (pDict->GetString("Type") == "XRef" && 790 (pDict->GetString("Type") == "XRef" &&
791 pDict->KeyExist("Size"))) { 791 pDict->KeyExist("Size"))) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 } 973 }
974 if (last_xref != -1 && last_xref > last_obj) { 974 if (last_xref != -1 && last_xref > last_obj) {
975 last_trailer = last_xref; 975 last_trailer = last_xref;
976 } else if (last_trailer == -1 || last_xref < last_obj) { 976 } else if (last_trailer == -1 || last_xref < last_obj) {
977 last_trailer = m_Syntax.m_FileLen; 977 last_trailer = m_Syntax.m_FileLen;
978 } 978 }
979 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; 979 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset;
980 void* pResult = 980 void* pResult =
981 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 981 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
982 sizeof(FX_FILESIZE), CompareFileSize); 982 sizeof(FX_FILESIZE), CompareFileSize);
983 if (pResult == NULL) { 983 if (!pResult) {
984 m_SortedOffset.Add(offset); 984 m_SortedOffset.Add(offset);
985 } 985 }
986 FX_Free(buffer); 986 FX_Free(buffer);
987 return m_pTrailer && m_CrossRef.GetSize() > 0; 987 return m_pTrailer && m_CrossRef.GetSize() > 0;
988 } 988 }
989 989
990 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { 990 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) {
991 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr); 991 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr);
992 if (!pObject) 992 if (!pObject)
993 return FALSE; 993 return FALSE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 if (nStartNum >= 0 && nCount > 0) { 1036 if (nStartNum >= 0 && nCount > 0) {
1037 arrIndex.push_back(std::make_pair(nStartNum, nCount)); 1037 arrIndex.push_back(std::make_pair(nStartNum, nCount));
1038 } 1038 }
1039 } 1039 }
1040 } 1040 }
1041 } 1041 }
1042 if (arrIndex.size() == 0) { 1042 if (arrIndex.size() == 0) {
1043 arrIndex.push_back(std::make_pair(0, size)); 1043 arrIndex.push_back(std::make_pair(0, size));
1044 } 1044 }
1045 pArray = pStream->GetDict()->GetArray("W"); 1045 pArray = pStream->GetDict()->GetArray("W");
1046 if (pArray == NULL) { 1046 if (!pArray) {
1047 pStream->Release(); 1047 pStream->Release();
1048 return FALSE; 1048 return FALSE;
1049 } 1049 }
1050 CFX_DWordArray WidthArray; 1050 CFX_DWordArray WidthArray;
1051 FX_SAFE_DWORD dwAccWidth = 0; 1051 FX_SAFE_DWORD dwAccWidth = 0;
1052 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { 1052 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
1053 WidthArray.Add(pArray->GetInteger(i)); 1053 WidthArray.Add(pArray->GetInteger(i));
1054 dwAccWidth += WidthArray[i]; 1054 dwAccWidth += WidthArray[i];
1055 } 1055 }
1056 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { 1056 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 if (WidthArray[0]) { 1093 if (WidthArray[0]) {
1094 type = GetVarInt(entrystart, WidthArray[0]); 1094 type = GetVarInt(entrystart, WidthArray[0]);
1095 } 1095 }
1096 if (m_V5Type[startnum + j] == 255) { 1096 if (m_V5Type[startnum + j] == 255) {
1097 FX_FILESIZE offset = 1097 FX_FILESIZE offset =
1098 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); 1098 GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
1099 m_CrossRef[startnum + j] = offset; 1099 m_CrossRef[startnum + j] = offset;
1100 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), 1100 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(),
1101 m_SortedOffset.GetSize(), 1101 m_SortedOffset.GetSize(),
1102 sizeof(FX_FILESIZE), CompareFileSize); 1102 sizeof(FX_FILESIZE), CompareFileSize);
1103 if (pResult == NULL) { 1103 if (!pResult) {
1104 m_SortedOffset.Add(offset); 1104 m_SortedOffset.Add(offset);
1105 } 1105 }
1106 continue; 1106 continue;
1107 } 1107 }
1108 if (m_V5Type[startnum + j]) { 1108 if (m_V5Type[startnum + j]) {
1109 continue; 1109 continue;
1110 } 1110 }
1111 m_V5Type[startnum + j] = type; 1111 m_V5Type[startnum + j] = type;
1112 if (type == 0) { 1112 if (type == 0) {
1113 m_CrossRef[startnum + j] = 0; 1113 m_CrossRef[startnum + j] = 0;
1114 } else { 1114 } else {
1115 FX_FILESIZE offset = 1115 FX_FILESIZE offset =
1116 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); 1116 GetVarInt(entrystart + WidthArray[0], WidthArray[1]);
1117 m_CrossRef[startnum + j] = offset; 1117 m_CrossRef[startnum + j] = offset;
1118 if (type == 1) { 1118 if (type == 1) {
1119 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), 1119 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(),
1120 m_SortedOffset.GetSize(), 1120 m_SortedOffset.GetSize(),
1121 sizeof(FX_FILESIZE), CompareFileSize); 1121 sizeof(FX_FILESIZE), CompareFileSize);
1122 if (pResult == NULL) { 1122 if (!pResult) {
1123 m_SortedOffset.Add(offset); 1123 m_SortedOffset.Add(offset);
1124 } 1124 }
1125 } else { 1125 } else {
1126 if (offset < 0 || offset >= m_V5Type.GetSize()) { 1126 if (offset < 0 || offset >= m_V5Type.GetSize()) {
1127 pStream->Release(); 1127 pStream->Release();
1128 return FALSE; 1128 return FALSE;
1129 } 1129 }
1130 m_V5Type[offset] = 255; 1130 m_V5Type[offset] = 255;
1131 } 1131 }
1132 } 1132 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 if (m_V5Type[objnum] == 0) { 1165 if (m_V5Type[objnum] == 0) {
1166 return TRUE; 1166 return TRUE;
1167 } 1167 }
1168 if (m_V5Type[objnum] == 2) { 1168 if (m_V5Type[objnum] == 2) {
1169 return TRUE; 1169 return TRUE;
1170 } 1170 }
1171 FX_FILESIZE pos = m_CrossRef[objnum]; 1171 FX_FILESIZE pos = m_CrossRef[objnum];
1172 void* pResult = 1172 void* pResult =
1173 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1173 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1174 sizeof(FX_FILESIZE), CompareFileSize); 1174 sizeof(FX_FILESIZE), CompareFileSize);
1175 if (pResult == NULL) { 1175 if (!pResult) {
1176 return TRUE; 1176 return TRUE;
1177 } 1177 }
1178 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == 1178 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() ==
1179 m_SortedOffset.GetSize() - 1) { 1179 m_SortedOffset.GetSize() - 1) {
1180 return FALSE; 1180 return FALSE;
1181 } 1181 }
1182 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; 1182 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos;
1183 FX_FILESIZE SavedPos = m_Syntax.SavePos(); 1183 FX_FILESIZE SavedPos = m_Syntax.SavePos();
1184 m_Syntax.RestorePos(pos); 1184 m_Syntax.RestorePos(pos);
1185 const char kFormStream[] = "/Form\0stream"; 1185 const char kFormStream[] = "/Form\0stream";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 objnum = (FX_DWORD)m_CrossRef[objnum]; 1254 objnum = (FX_DWORD)m_CrossRef[objnum];
1255 } 1255 }
1256 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { 1256 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) {
1257 FX_FILESIZE offset = m_CrossRef[objnum]; 1257 FX_FILESIZE offset = m_CrossRef[objnum];
1258 if (offset == 0) { 1258 if (offset == 0) {
1259 return 0; 1259 return 0;
1260 } 1260 }
1261 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), 1261 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(),
1262 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), 1262 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE),
1263 CompareFileSize); 1263 CompareFileSize);
1264 if (pResult == NULL) { 1264 if (!pResult) {
1265 return 0; 1265 return 0;
1266 } 1266 }
1267 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == 1267 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() ==
1268 m_SortedOffset.GetSize() - 1) { 1268 m_SortedOffset.GetSize() - 1) {
1269 return 0; 1269 return 0;
1270 } 1270 }
1271 return ((FX_FILESIZE*)pResult)[1] - offset; 1271 return ((FX_FILESIZE*)pResult)[1] - offset;
1272 } 1272 }
1273 return 0; 1273 return 0;
1274 } 1274 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 m_Syntax.RestorePos(SavedPos); 1337 m_Syntax.RestorePos(SavedPos);
1338 return; 1338 return;
1339 } 1339 }
1340 if (m_Syntax.GetKeyword() != "obj") { 1340 if (m_Syntax.GetKeyword() != "obj") {
1341 m_Syntax.RestorePos(SavedPos); 1341 m_Syntax.RestorePos(SavedPos);
1342 return; 1342 return;
1343 } 1343 }
1344 void* pResult = 1344 void* pResult =
1345 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1345 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1346 sizeof(FX_FILESIZE), CompareFileSize); 1346 sizeof(FX_FILESIZE), CompareFileSize);
1347 if (pResult == NULL) { 1347 if (!pResult) {
1348 m_Syntax.RestorePos(SavedPos); 1348 m_Syntax.RestorePos(SavedPos);
1349 return; 1349 return;
1350 } 1350 }
1351 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; 1351 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1];
1352 FX_BOOL bNextOffValid = FALSE; 1352 FX_BOOL bNextOffValid = FALSE;
1353 if (nextoff != pos) { 1353 if (nextoff != pos) {
1354 m_Syntax.RestorePos(nextoff); 1354 m_Syntax.RestorePos(nextoff);
1355 word = m_Syntax.GetNextWord(bIsNumber); 1355 word = m_Syntax.GetNextWord(bIsNumber);
1356 if (word == "xref") { 1356 if (word == "xref") {
1357 bNextOffValid = TRUE; 1357 bNextOffValid = TRUE;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 if (m_pEncryptDict && m_pEncryptDict->GetString("Filter") == "Standard") { 1483 if (m_pEncryptDict && m_pEncryptDict->GetString("Filter") == "Standard") {
1484 dwPermission &= 0xFFFFFFFC; 1484 dwPermission &= 0xFFFFFFFC;
1485 dwPermission |= 0xFFFFF0C0; 1485 dwPermission |= 0xFFFFF0C0;
1486 if (bCheckRevision && m_pEncryptDict->GetInteger("R") == 2) { 1486 if (bCheckRevision && m_pEncryptDict->GetInteger("R") == 2) {
1487 dwPermission &= 0xFFFFF0FF; 1487 dwPermission &= 0xFFFFF0FF;
1488 } 1488 }
1489 } 1489 }
1490 return dwPermission; 1490 return dwPermission;
1491 } 1491 }
1492 FX_BOOL CPDF_Parser::IsOwner() { 1492 FX_BOOL CPDF_Parser::IsOwner() {
1493 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); 1493 return !m_pSecurityHandler || m_pSecurityHandler->IsOwner();
1494 } 1494 }
1495 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, 1495 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler,
1496 FX_BOOL bForced) { 1496 FX_BOOL bForced) {
1497 m_bForceUseSecurityHandler = bForced; 1497 m_bForceUseSecurityHandler = bForced;
1498 m_pSecurityHandler.reset(pSecurityHandler); 1498 m_pSecurityHandler.reset(pSecurityHandler);
1499 if (m_bForceUseSecurityHandler) { 1499 if (m_bForceUseSecurityHandler) {
1500 return; 1500 return;
1501 } 1501 }
1502 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); 1502 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler());
1503 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); 1503 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) && 1577 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) &&
1578 !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { 1578 !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) {
1579 if (!RebuildCrossRef()) { 1579 if (!RebuildCrossRef()) {
1580 return PDFPARSE_ERROR_FORMAT; 1580 return PDFPARSE_ERROR_FORMAT;
1581 } 1581 }
1582 bXRefRebuilt = TRUE; 1582 bXRefRebuilt = TRUE;
1583 m_LastXRefOffset = 0; 1583 m_LastXRefOffset = 0;
1584 } 1584 }
1585 if (bLoadV4) { 1585 if (bLoadV4) {
1586 m_pTrailer = LoadTrailerV4(); 1586 m_pTrailer = LoadTrailerV4();
1587 if (m_pTrailer == NULL) { 1587 if (!m_pTrailer) {
1588 return FALSE; 1588 return FALSE;
1589 } 1589 }
1590 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); 1590 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size");
1591 if (xrefsize > 0) { 1591 if (xrefsize > 0) {
1592 m_CrossRef.SetSize(xrefsize); 1592 m_CrossRef.SetSize(xrefsize);
1593 m_V5Type.SetSize(xrefsize); 1593 m_V5Type.SetSize(xrefsize);
1594 } 1594 }
1595 } 1595 }
1596 FX_DWORD dwRet = SetEncryptHandler(); 1596 FX_DWORD dwRet = SetEncryptHandler();
1597 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1597 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
1598 return dwRet; 1598 return dwRet;
1599 } 1599 }
1600 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); 1600 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict());
1601 if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) { 1601 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) {
1602 if (bXRefRebuilt) { 1602 if (bXRefRebuilt) {
1603 return PDFPARSE_ERROR_FORMAT; 1603 return PDFPARSE_ERROR_FORMAT;
1604 } 1604 }
1605 ReleaseEncryptHandler(); 1605 ReleaseEncryptHandler();
1606 if (!RebuildCrossRef()) { 1606 if (!RebuildCrossRef()) {
1607 return PDFPARSE_ERROR_FORMAT; 1607 return PDFPARSE_ERROR_FORMAT;
1608 } 1608 }
1609 dwRet = SetEncryptHandler(); 1609 dwRet = SetEncryptHandler();
1610 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1610 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
1611 return dwRet; 1611 return dwRet;
1612 } 1612 }
1613 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); 1613 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict());
1614 if (m_pDocument->GetRoot() == NULL) { 1614 if (!m_pDocument->GetRoot()) {
1615 return PDFPARSE_ERROR_FORMAT; 1615 return PDFPARSE_ERROR_FORMAT;
1616 } 1616 }
1617 } 1617 }
1618 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1618 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1619 sizeof(FX_FILESIZE), CompareFileSize); 1619 sizeof(FX_FILESIZE), CompareFileSize);
1620 if (GetRootObjNum() == 0) { 1620 if (GetRootObjNum() == 0) {
1621 ReleaseEncryptHandler(); 1621 ReleaseEncryptHandler();
1622 if (!RebuildCrossRef() || GetRootObjNum() == 0) 1622 if (!RebuildCrossRef() || GetRootObjNum() == 0)
1623 return PDFPARSE_ERROR_FORMAT; 1623 return PDFPARSE_ERROR_FORMAT;
1624 1624
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 int iSize = m_arrayAcroforms.GetSize(); 2977 int iSize = m_arrayAcroforms.GetSize();
2978 for (int i = 0; i < iSize; ++i) { 2978 for (int i = 0; i < iSize; ++i) {
2979 m_arrayAcroforms.GetAt(i)->Release(); 2979 m_arrayAcroforms.GetAt(i)->Release();
2980 } 2980 }
2981 } 2981 }
2982 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { 2982 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) {
2983 m_pDocument = pDoc; 2983 m_pDocument = pDoc;
2984 } 2984 }
2985 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { 2985 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) {
2986 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); 2986 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser());
2987 if (pParser == NULL) { 2987 if (!pParser) {
2988 return 0; 2988 return 0;
2989 } 2989 }
2990 if (objnum >= (FX_DWORD)pParser->m_CrossRef.GetSize()) { 2990 if (objnum >= (FX_DWORD)pParser->m_CrossRef.GetSize()) {
2991 return 0; 2991 return 0;
2992 } 2992 }
2993 if (pParser->m_V5Type[objnum] == 2) { 2993 if (pParser->m_V5Type[objnum] == 2) {
2994 objnum = (FX_DWORD)pParser->m_CrossRef[objnum]; 2994 objnum = (FX_DWORD)pParser->m_CrossRef[objnum];
2995 } 2995 }
2996 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) { 2996 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) {
2997 offset = pParser->m_CrossRef[objnum]; 2997 offset = pParser->m_CrossRef[objnum];
2998 if (offset == 0) { 2998 if (offset == 0) {
2999 return 0; 2999 return 0;
3000 } 3000 }
3001 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), 3001 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(),
3002 pParser->m_SortedOffset.GetSize(), 3002 pParser->m_SortedOffset.GetSize(),
3003 sizeof(FX_FILESIZE), CompareFileSize); 3003 sizeof(FX_FILESIZE), CompareFileSize);
3004 if (pResult == NULL) { 3004 if (!pResult) {
3005 return 0; 3005 return 0;
3006 } 3006 }
3007 if ((FX_FILESIZE*)pResult - 3007 if ((FX_FILESIZE*)pResult -
3008 (FX_FILESIZE*)pParser->m_SortedOffset.GetData() == 3008 (FX_FILESIZE*)pParser->m_SortedOffset.GetData() ==
3009 pParser->m_SortedOffset.GetSize() - 1) { 3009 pParser->m_SortedOffset.GetSize() - 1) {
3010 return 0; 3010 return 0;
3011 } 3011 }
3012 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); 3012 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset);
3013 } 3013 }
3014 return 0; 3014 return 0;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3248 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, 3248 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum,
3249 IFX_DownloadHints* pHints, 3249 IFX_DownloadHints* pHints,
3250 FX_BOOL* pExistInFile) { 3250 FX_BOOL* pExistInFile) {
3251 CPDF_Object* pRet = nullptr; 3251 CPDF_Object* pRet = nullptr;
3252 FX_DWORD size = 0; 3252 FX_DWORD size = 0;
3253 FX_FILESIZE offset = 0; 3253 FX_FILESIZE offset = 0;
3254 CPDF_Parser* pParser = nullptr; 3254 CPDF_Parser* pParser = nullptr;
3255 if (pExistInFile) 3255 if (pExistInFile)
3256 *pExistInFile = TRUE; 3256 *pExistInFile = TRUE;
3257 3257
3258 if (m_pDocument == NULL) { 3258 if (m_pDocument) {
3259 size = GetObjectSize(objnum, offset);
3260 pParser = (CPDF_Parser*)(m_pDocument->GetParser());
3261 } else {
3259 size = (FX_DWORD)m_parser.GetObjectSize(objnum); 3262 size = (FX_DWORD)m_parser.GetObjectSize(objnum);
3260 offset = m_parser.GetObjectOffset(objnum); 3263 offset = m_parser.GetObjectOffset(objnum);
3261 pParser = &m_parser; 3264 pParser = &m_parser;
3262 } else {
3263 size = GetObjectSize(objnum, offset);
3264 pParser = (CPDF_Parser*)(m_pDocument->GetParser());
3265 } 3265 }
3266 if (!IsDataAvail(offset, size, pHints)) { 3266 if (!IsDataAvail(offset, size, pHints)) {
3267 return nullptr; 3267 return nullptr;
3268 } 3268 }
3269 if (pParser) { 3269 if (pParser) {
3270 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); 3270 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL);
3271 } 3271 }
3272 3272
3273 if (!pRet && pExistInFile) { 3273 if (!pRet && pExistInFile) {
3274 *pExistInFile = FALSE; 3274 *pExistInFile = FALSE;
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after
5001 if (!m_pLinearizedDict) 5001 if (!m_pLinearizedDict)
5002 return -1; 5002 return -1;
5003 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); 5003 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H");
5004 if (!pRange) 5004 if (!pRange)
5005 return -1; 5005 return -1;
5006 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 5006 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
5007 if (!pStreamLen) 5007 if (!pStreamLen)
5008 return -1; 5008 return -1;
5009 return pStreamLen->GetInteger(); 5009 return pStreamLen->GetInteger();
5010 } 5010 }
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