OLD | NEW |
---|---|
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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 CPDF_Reference* pMetadata = | 260 CPDF_Reference* pMetadata = |
261 ToReference(m_pDocument->GetRoot()->GetElement("Metadata")); | 261 ToReference(m_pDocument->GetRoot()->GetElement("Metadata")); |
262 if (pMetadata) | 262 if (pMetadata) |
263 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); | 263 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
264 } | 264 } |
265 return PDFPARSE_ERROR_SUCCESS; | 265 return PDFPARSE_ERROR_SUCCESS; |
266 } | 266 } |
267 FX_DWORD CPDF_Parser::SetEncryptHandler() { | 267 FX_DWORD CPDF_Parser::SetEncryptHandler() { |
268 ReleaseEncryptHandler(); | 268 ReleaseEncryptHandler(); |
269 SetEncryptDictionary(NULL); | 269 SetEncryptDictionary(NULL); |
270 if (m_pTrailer == NULL) { | 270 if (!m_pTrailer) { |
271 return PDFPARSE_ERROR_FORMAT; | 271 return PDFPARSE_ERROR_FORMAT; |
272 } | 272 } |
273 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); | 273 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); |
274 if (pEncryptObj) { | 274 if (pEncryptObj) { |
275 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { | 275 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
276 SetEncryptDictionary(pEncryptDict); | 276 SetEncryptDictionary(pEncryptDict); |
277 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { | 277 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
278 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); | 278 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
279 if (pEncryptObj) | 279 if (pEncryptObj) |
280 SetEncryptDictionary(pEncryptObj->GetDict()); | 280 SetEncryptDictionary(pEncryptObj->GetDict()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 return m_CrossRef[(int32_t)m_CrossRef[objnum]]; | 335 return m_CrossRef[(int32_t)m_CrossRef[objnum]]; |
336 } | 336 } |
337 return 0; | 337 return 0; |
338 } | 338 } |
339 | 339 |
340 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { | 340 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { |
341 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) { | 341 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) { |
342 return FALSE; | 342 return FALSE; |
343 } | 343 } |
344 m_pTrailer = LoadTrailerV4(); | 344 m_pTrailer = LoadTrailerV4(); |
345 if (m_pTrailer == NULL) { | 345 if (!m_pTrailer) { |
346 return FALSE; | 346 return FALSE; |
347 } | 347 } |
348 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 348 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
349 if (xrefsize <= 0 || xrefsize > (1 << 20)) { | 349 if (xrefsize <= 0 || xrefsize > (1 << 20)) { |
350 return FALSE; | 350 return FALSE; |
351 } | 351 } |
352 m_CrossRef.SetSize(xrefsize); | 352 m_CrossRef.SetSize(xrefsize); |
353 m_V5Type.SetSize(xrefsize); | 353 m_V5Type.SetSize(xrefsize); |
354 CFX_FileSizeArray CrossRefList, XRefStreamList; | 354 CFX_FileSizeArray CrossRefList, XRefStreamList; |
355 CrossRefList.Add(xrefpos); | 355 CrossRefList.Add(xrefpos); |
(...skipping 30 matching lines...) Expand all Loading... | |
386 return FALSE; | 386 return FALSE; |
387 } | 387 } |
388 return TRUE; | 388 return TRUE; |
389 } | 389 } |
390 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, | 390 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, |
391 FX_DWORD dwObjCount) { | 391 FX_DWORD dwObjCount) { |
392 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { | 392 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { |
393 return FALSE; | 393 return FALSE; |
394 } | 394 } |
395 m_pTrailer = LoadTrailerV4(); | 395 m_pTrailer = LoadTrailerV4(); |
396 if (m_pTrailer == NULL) { | 396 if (!m_pTrailer) { |
397 return FALSE; | 397 return FALSE; |
398 } | 398 } |
399 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 399 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
400 if (xrefsize == 0) { | 400 if (xrefsize == 0) { |
401 return FALSE; | 401 return FALSE; |
402 } | 402 } |
403 CFX_FileSizeArray CrossRefList, XRefStreamList; | 403 CFX_FileSizeArray CrossRefList, XRefStreamList; |
404 CrossRefList.Add(xrefpos); | 404 CrossRefList.Add(xrefpos); |
405 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); | 405 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); |
406 xrefpos = GetDirectInteger(m_pTrailer, "Prev"); | 406 xrefpos = GetDirectInteger(m_pTrailer, "Prev"); |
407 while (xrefpos) { | 407 while (xrefpos) { |
408 CrossRefList.InsertAt(0, xrefpos); | 408 CrossRefList.InsertAt(0, xrefpos); |
409 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE); | 409 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE); |
410 CPDF_Dictionary* pDict = LoadTrailerV4(); | 410 CPDF_Dictionary* pDict = LoadTrailerV4(); |
411 if (pDict == NULL) { | 411 if (!pDict) { |
412 return FALSE; | 412 return FALSE; |
413 } | 413 } |
414 xrefpos = GetDirectInteger(pDict, "Prev"); | 414 xrefpos = GetDirectInteger(pDict, "Prev"); |
415 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm")); | 415 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm")); |
416 m_Trailers.Add(pDict); | 416 m_Trailers.Add(pDict); |
417 } | 417 } |
418 for (int32_t i = 1; i < CrossRefList.GetSize(); i++) | 418 for (int32_t i = 1; i < CrossRefList.GetSize(); i++) |
419 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) { | 419 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) { |
420 return FALSE; | 420 return FALSE; |
421 } | 421 } |
422 return TRUE; | 422 return TRUE; |
423 } | 423 } |
424 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, | 424 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, |
425 FX_DWORD dwObjCount) { | 425 FX_DWORD dwObjCount) { |
426 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; | 426 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; |
427 m_Syntax.RestorePos(dwStartPos); | 427 m_Syntax.RestorePos(dwStartPos); |
428 void* pResult = | 428 void* pResult = |
429 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 429 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
430 sizeof(FX_FILESIZE), CompareFileSize); | 430 sizeof(FX_FILESIZE), CompareFileSize); |
431 if (pResult == NULL) { | 431 if (!pResult) { |
432 m_SortedOffset.Add(pos); | 432 m_SortedOffset.Add(pos); |
433 } | 433 } |
434 FX_DWORD start_objnum = 0; | 434 FX_DWORD start_objnum = 0; |
435 FX_DWORD count = dwObjCount; | 435 FX_DWORD count = dwObjCount; |
436 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 436 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
437 const int32_t recordsize = 20; | 437 const int32_t recordsize = 20; |
438 std::vector<char> buf(1024 * recordsize + 1); | 438 std::vector<char> buf(1024 * recordsize + 1); |
439 char* pBuf = pdfium::vector_as_array(&buf); | 439 char* pBuf = pdfium::vector_as_array(&buf); |
440 pBuf[1024 * recordsize] = '\0'; | 440 pBuf[1024 * recordsize] = '\0'; |
441 int32_t nBlocks = count / 1024 + 1; | 441 int32_t nBlocks = count / 1024 + 1; |
(...skipping 23 matching lines...) Expand all Loading... | |
465 m_CrossRef.SetAtGrow(objnum, offset); | 465 m_CrossRef.SetAtGrow(objnum, offset); |
466 int32_t version = FXSYS_atoi(pEntry + 11); | 466 int32_t version = FXSYS_atoi(pEntry + 11); |
467 if (version >= 1) { | 467 if (version >= 1) { |
468 m_bVersionUpdated = TRUE; | 468 m_bVersionUpdated = TRUE; |
469 } | 469 } |
470 m_ObjVersion.SetAtGrow(objnum, version); | 470 m_ObjVersion.SetAtGrow(objnum, version); |
471 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 471 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { |
472 void* pResult = FXSYS_bsearch( | 472 void* pResult = FXSYS_bsearch( |
473 &m_CrossRef[objnum], m_SortedOffset.GetData(), | 473 &m_CrossRef[objnum], m_SortedOffset.GetData(), |
474 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); | 474 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); |
475 if (pResult == NULL) { | 475 if (!pResult) { |
476 m_SortedOffset.Add(m_CrossRef[objnum]); | 476 m_SortedOffset.Add(m_CrossRef[objnum]); |
477 } | 477 } |
478 } | 478 } |
479 m_V5Type.SetAtGrow(objnum, 1); | 479 m_V5Type.SetAtGrow(objnum, 1); |
480 } | 480 } |
481 } | 481 } |
482 } | 482 } |
483 m_Syntax.RestorePos(SavedPos + count * recordsize); | 483 m_Syntax.RestorePos(SavedPos + count * recordsize); |
484 return TRUE; | 484 return TRUE; |
485 } | 485 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 if (objnum > 0x1000000) { | 765 if (objnum > 0x1000000) { |
766 status = 0; | 766 status = 0; |
767 break; | 767 break; |
768 } | 768 } |
769 FX_FILESIZE obj_pos = start_pos - m_Syntax.m_HeaderOffset; | 769 FX_FILESIZE obj_pos = start_pos - m_Syntax.m_HeaderOffset; |
770 last_obj = start_pos; | 770 last_obj = start_pos; |
771 void* pResult = | 771 void* pResult = |
772 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), | 772 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), |
773 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 773 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
774 CompareFileSize); | 774 CompareFileSize); |
775 if (pResult == NULL) { | 775 if (!pResult) { |
776 m_SortedOffset.Add(obj_pos); | 776 m_SortedOffset.Add(obj_pos); |
777 } | 777 } |
778 FX_FILESIZE obj_end = 0; | 778 FX_FILESIZE obj_end = 0; |
779 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( | 779 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( |
780 m_pDocument, obj_pos, objnum, NULL, &obj_end); | 780 m_pDocument, obj_pos, objnum, NULL, &obj_end); |
781 if (CPDF_Stream* pStream = ToStream(pObject)) { | 781 if (CPDF_Stream* pStream = ToStream(pObject)) { |
782 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 782 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
783 if ((pDict->KeyExist("Type")) && | 783 if ((pDict->KeyExist("Type")) && |
784 (pDict->GetString("Type") == "XRef" && | 784 (pDict->GetString("Type") == "XRef" && |
785 pDict->KeyExist("Size"))) { | 785 pDict->KeyExist("Size"))) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 } | 967 } |
968 if (last_xref != -1 && last_xref > last_obj) { | 968 if (last_xref != -1 && last_xref > last_obj) { |
969 last_trailer = last_xref; | 969 last_trailer = last_xref; |
970 } else if (last_trailer == -1 || last_xref < last_obj) { | 970 } else if (last_trailer == -1 || last_xref < last_obj) { |
971 last_trailer = m_Syntax.m_FileLen; | 971 last_trailer = m_Syntax.m_FileLen; |
972 } | 972 } |
973 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; | 973 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; |
974 void* pResult = | 974 void* pResult = |
975 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 975 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
976 sizeof(FX_FILESIZE), CompareFileSize); | 976 sizeof(FX_FILESIZE), CompareFileSize); |
977 if (pResult == NULL) { | 977 if (!pResult) { |
978 m_SortedOffset.Add(offset); | 978 m_SortedOffset.Add(offset); |
979 } | 979 } |
980 FX_Free(buffer); | 980 FX_Free(buffer); |
981 return m_pTrailer && m_CrossRef.GetSize() > 0; | 981 return m_pTrailer && m_CrossRef.GetSize() > 0; |
982 } | 982 } |
983 | 983 |
984 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { | 984 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { |
985 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr); | 985 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr); |
986 if (!pObject) | 986 if (!pObject) |
987 return FALSE; | 987 return FALSE; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 if (nStartNum >= 0 && nCount > 0) { | 1029 if (nStartNum >= 0 && nCount > 0) { |
1030 arrIndex.push_back(std::make_pair(nStartNum, nCount)); | 1030 arrIndex.push_back(std::make_pair(nStartNum, nCount)); |
1031 } | 1031 } |
1032 } | 1032 } |
1033 } | 1033 } |
1034 } | 1034 } |
1035 if (arrIndex.size() == 0) { | 1035 if (arrIndex.size() == 0) { |
1036 arrIndex.push_back(std::make_pair(0, size)); | 1036 arrIndex.push_back(std::make_pair(0, size)); |
1037 } | 1037 } |
1038 pArray = pStream->GetDict()->GetArray("W"); | 1038 pArray = pStream->GetDict()->GetArray("W"); |
1039 if (pArray == NULL) { | 1039 if (!pArray) { |
1040 pStream->Release(); | 1040 pStream->Release(); |
1041 return FALSE; | 1041 return FALSE; |
1042 } | 1042 } |
1043 CFX_DWordArray WidthArray; | 1043 CFX_DWordArray WidthArray; |
1044 FX_SAFE_DWORD dwAccWidth = 0; | 1044 FX_SAFE_DWORD dwAccWidth = 0; |
1045 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 1045 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { |
1046 WidthArray.Add(pArray->GetInteger(i)); | 1046 WidthArray.Add(pArray->GetInteger(i)); |
1047 dwAccWidth += WidthArray[i]; | 1047 dwAccWidth += WidthArray[i]; |
1048 } | 1048 } |
1049 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { | 1049 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 if (WidthArray[0]) { | 1086 if (WidthArray[0]) { |
1087 type = GetVarInt(entrystart, WidthArray[0]); | 1087 type = GetVarInt(entrystart, WidthArray[0]); |
1088 } | 1088 } |
1089 if (m_V5Type[startnum + j] == 255) { | 1089 if (m_V5Type[startnum + j] == 255) { |
1090 FX_FILESIZE offset = | 1090 FX_FILESIZE offset = |
1091 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1091 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
1092 m_CrossRef[startnum + j] = offset; | 1092 m_CrossRef[startnum + j] = offset; |
1093 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1093 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
1094 m_SortedOffset.GetSize(), | 1094 m_SortedOffset.GetSize(), |
1095 sizeof(FX_FILESIZE), CompareFileSize); | 1095 sizeof(FX_FILESIZE), CompareFileSize); |
1096 if (pResult == NULL) { | 1096 if (!pResult) { |
1097 m_SortedOffset.Add(offset); | 1097 m_SortedOffset.Add(offset); |
1098 } | 1098 } |
1099 continue; | 1099 continue; |
1100 } | 1100 } |
1101 if (m_V5Type[startnum + j]) { | 1101 if (m_V5Type[startnum + j]) { |
1102 continue; | 1102 continue; |
1103 } | 1103 } |
1104 m_V5Type[startnum + j] = type; | 1104 m_V5Type[startnum + j] = type; |
1105 if (type == 0) { | 1105 if (type == 0) { |
1106 m_CrossRef[startnum + j] = 0; | 1106 m_CrossRef[startnum + j] = 0; |
1107 } else { | 1107 } else { |
1108 FX_FILESIZE offset = | 1108 FX_FILESIZE offset = |
1109 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1109 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
1110 m_CrossRef[startnum + j] = offset; | 1110 m_CrossRef[startnum + j] = offset; |
1111 if (type == 1) { | 1111 if (type == 1) { |
1112 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1112 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
1113 m_SortedOffset.GetSize(), | 1113 m_SortedOffset.GetSize(), |
1114 sizeof(FX_FILESIZE), CompareFileSize); | 1114 sizeof(FX_FILESIZE), CompareFileSize); |
1115 if (pResult == NULL) { | 1115 if (!pResult) { |
1116 m_SortedOffset.Add(offset); | 1116 m_SortedOffset.Add(offset); |
1117 } | 1117 } |
1118 } else { | 1118 } else { |
1119 if (offset < 0 || offset >= m_V5Type.GetSize()) { | 1119 if (offset < 0 || offset >= m_V5Type.GetSize()) { |
1120 pStream->Release(); | 1120 pStream->Release(); |
1121 return FALSE; | 1121 return FALSE; |
1122 } | 1122 } |
1123 m_V5Type[offset] = 255; | 1123 m_V5Type[offset] = 255; |
1124 } | 1124 } |
1125 } | 1125 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1158 if (m_V5Type[objnum] == 0) { | 1158 if (m_V5Type[objnum] == 0) { |
1159 return TRUE; | 1159 return TRUE; |
1160 } | 1160 } |
1161 if (m_V5Type[objnum] == 2) { | 1161 if (m_V5Type[objnum] == 2) { |
1162 return TRUE; | 1162 return TRUE; |
1163 } | 1163 } |
1164 FX_FILESIZE pos = m_CrossRef[objnum]; | 1164 FX_FILESIZE pos = m_CrossRef[objnum]; |
1165 void* pResult = | 1165 void* pResult = |
1166 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1166 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
1167 sizeof(FX_FILESIZE), CompareFileSize); | 1167 sizeof(FX_FILESIZE), CompareFileSize); |
1168 if (pResult == NULL) { | 1168 if (!pResult) { |
1169 return TRUE; | 1169 return TRUE; |
1170 } | 1170 } |
1171 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1171 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == |
1172 m_SortedOffset.GetSize() - 1) { | 1172 m_SortedOffset.GetSize() - 1) { |
1173 return FALSE; | 1173 return FALSE; |
1174 } | 1174 } |
1175 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; | 1175 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; |
1176 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1176 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1177 m_Syntax.RestorePos(pos); | 1177 m_Syntax.RestorePos(pos); |
1178 bForm = m_Syntax.SearchMultiWord("/Form\0stream", TRUE, size) == 0; | 1178 bForm = m_Syntax.SearchMultiWord("/Form\0stream", TRUE, size) == 0; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 objnum = (FX_DWORD)m_CrossRef[objnum]; | 1245 objnum = (FX_DWORD)m_CrossRef[objnum]; |
1246 } | 1246 } |
1247 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1247 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
1248 FX_FILESIZE offset = m_CrossRef[objnum]; | 1248 FX_FILESIZE offset = m_CrossRef[objnum]; |
1249 if (offset == 0) { | 1249 if (offset == 0) { |
1250 return 0; | 1250 return 0; |
1251 } | 1251 } |
1252 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1252 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
1253 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 1253 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
1254 CompareFileSize); | 1254 CompareFileSize); |
1255 if (pResult == NULL) { | 1255 if (!pResult) { |
1256 return 0; | 1256 return 0; |
1257 } | 1257 } |
1258 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1258 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == |
1259 m_SortedOffset.GetSize() - 1) { | 1259 m_SortedOffset.GetSize() - 1) { |
1260 return 0; | 1260 return 0; |
1261 } | 1261 } |
1262 return ((FX_FILESIZE*)pResult)[1] - offset; | 1262 return ((FX_FILESIZE*)pResult)[1] - offset; |
1263 } | 1263 } |
1264 return 0; | 1264 return 0; |
1265 } | 1265 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1328 m_Syntax.RestorePos(SavedPos); | 1328 m_Syntax.RestorePos(SavedPos); |
1329 return; | 1329 return; |
1330 } | 1330 } |
1331 if (m_Syntax.GetKeyword() != "obj") { | 1331 if (m_Syntax.GetKeyword() != "obj") { |
1332 m_Syntax.RestorePos(SavedPos); | 1332 m_Syntax.RestorePos(SavedPos); |
1333 return; | 1333 return; |
1334 } | 1334 } |
1335 void* pResult = | 1335 void* pResult = |
1336 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1336 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
1337 sizeof(FX_FILESIZE), CompareFileSize); | 1337 sizeof(FX_FILESIZE), CompareFileSize); |
1338 if (pResult == NULL) { | 1338 if (!pResult) { |
1339 m_Syntax.RestorePos(SavedPos); | 1339 m_Syntax.RestorePos(SavedPos); |
1340 return; | 1340 return; |
1341 } | 1341 } |
1342 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; | 1342 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; |
1343 FX_BOOL bNextOffValid = FALSE; | 1343 FX_BOOL bNextOffValid = FALSE; |
1344 if (nextoff != pos) { | 1344 if (nextoff != pos) { |
1345 m_Syntax.RestorePos(nextoff); | 1345 m_Syntax.RestorePos(nextoff); |
1346 word = m_Syntax.GetNextWord(bIsNumber); | 1346 word = m_Syntax.GetNextWord(bIsNumber); |
1347 if (word == "xref") { | 1347 if (word == "xref") { |
1348 bNextOffValid = TRUE; | 1348 bNextOffValid = TRUE; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1474 if (m_pEncryptDict && m_pEncryptDict->GetString("Filter") == "Standard") { | 1474 if (m_pEncryptDict && m_pEncryptDict->GetString("Filter") == "Standard") { |
1475 dwPermission &= 0xFFFFFFFC; | 1475 dwPermission &= 0xFFFFFFFC; |
1476 dwPermission |= 0xFFFFF0C0; | 1476 dwPermission |= 0xFFFFF0C0; |
1477 if (bCheckRevision && m_pEncryptDict->GetInteger("R") == 2) { | 1477 if (bCheckRevision && m_pEncryptDict->GetInteger("R") == 2) { |
1478 dwPermission &= 0xFFFFF0FF; | 1478 dwPermission &= 0xFFFFF0FF; |
1479 } | 1479 } |
1480 } | 1480 } |
1481 return dwPermission; | 1481 return dwPermission; |
1482 } | 1482 } |
1483 FX_BOOL CPDF_Parser::IsOwner() { | 1483 FX_BOOL CPDF_Parser::IsOwner() { |
1484 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); | 1484 return m_pSecurityHandler ? m_pSecurityHandler->IsOwner() : TRUE; |
Tom Sepez
2015/12/14 18:27:00
nit: return !m_pSecurityHandler || m_pSecurityHand
Lei Zhang
2015/12/15 01:58:35
Mmmmhmm
| |
1485 } | 1485 } |
1486 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, | 1486 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, |
1487 FX_BOOL bForced) { | 1487 FX_BOOL bForced) { |
1488 m_bForceUseSecurityHandler = bForced; | 1488 m_bForceUseSecurityHandler = bForced; |
1489 m_pSecurityHandler.reset(pSecurityHandler); | 1489 m_pSecurityHandler.reset(pSecurityHandler); |
1490 if (m_bForceUseSecurityHandler) { | 1490 if (m_bForceUseSecurityHandler) { |
1491 return; | 1491 return; |
1492 } | 1492 } |
1493 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); | 1493 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); |
1494 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 1494 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1568 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) && | 1568 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) && |
1569 !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { | 1569 !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { |
1570 if (!RebuildCrossRef()) { | 1570 if (!RebuildCrossRef()) { |
1571 return PDFPARSE_ERROR_FORMAT; | 1571 return PDFPARSE_ERROR_FORMAT; |
1572 } | 1572 } |
1573 bXRefRebuilt = TRUE; | 1573 bXRefRebuilt = TRUE; |
1574 m_LastXRefOffset = 0; | 1574 m_LastXRefOffset = 0; |
1575 } | 1575 } |
1576 if (bLoadV4) { | 1576 if (bLoadV4) { |
1577 m_pTrailer = LoadTrailerV4(); | 1577 m_pTrailer = LoadTrailerV4(); |
1578 if (m_pTrailer == NULL) { | 1578 if (!m_pTrailer) { |
1579 return FALSE; | 1579 return FALSE; |
1580 } | 1580 } |
1581 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 1581 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
1582 if (xrefsize > 0) { | 1582 if (xrefsize > 0) { |
1583 m_CrossRef.SetSize(xrefsize); | 1583 m_CrossRef.SetSize(xrefsize); |
1584 m_V5Type.SetSize(xrefsize); | 1584 m_V5Type.SetSize(xrefsize); |
1585 } | 1585 } |
1586 } | 1586 } |
1587 FX_DWORD dwRet = SetEncryptHandler(); | 1587 FX_DWORD dwRet = SetEncryptHandler(); |
1588 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1588 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
1589 return dwRet; | 1589 return dwRet; |
1590 } | 1590 } |
1591 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); | 1591 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); |
1592 if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) { | 1592 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { |
1593 if (bXRefRebuilt) { | 1593 if (bXRefRebuilt) { |
1594 return PDFPARSE_ERROR_FORMAT; | 1594 return PDFPARSE_ERROR_FORMAT; |
1595 } | 1595 } |
1596 ReleaseEncryptHandler(); | 1596 ReleaseEncryptHandler(); |
1597 if (!RebuildCrossRef()) { | 1597 if (!RebuildCrossRef()) { |
1598 return PDFPARSE_ERROR_FORMAT; | 1598 return PDFPARSE_ERROR_FORMAT; |
1599 } | 1599 } |
1600 dwRet = SetEncryptHandler(); | 1600 dwRet = SetEncryptHandler(); |
1601 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1601 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
1602 return dwRet; | 1602 return dwRet; |
1603 } | 1603 } |
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()) { |
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 if (GetRootObjNum() == 0) { | 1611 if (GetRootObjNum() == 0) { |
1612 ReleaseEncryptHandler(); | 1612 ReleaseEncryptHandler(); |
1613 if (!RebuildCrossRef() || GetRootObjNum() == 0) | 1613 if (!RebuildCrossRef() || GetRootObjNum() == 0) |
1614 return PDFPARSE_ERROR_FORMAT; | 1614 return PDFPARSE_ERROR_FORMAT; |
1615 | 1615 |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2965 int iSize = m_arrayAcroforms.GetSize(); | 2965 int iSize = m_arrayAcroforms.GetSize(); |
2966 for (int i = 0; i < iSize; ++i) { | 2966 for (int i = 0; i < iSize; ++i) { |
2967 m_arrayAcroforms.GetAt(i)->Release(); | 2967 m_arrayAcroforms.GetAt(i)->Release(); |
2968 } | 2968 } |
2969 } | 2969 } |
2970 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 2970 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
2971 m_pDocument = pDoc; | 2971 m_pDocument = pDoc; |
2972 } | 2972 } |
2973 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { | 2973 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { |
2974 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); | 2974 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); |
2975 if (pParser == NULL) { | 2975 if (!pParser) { |
2976 return 0; | 2976 return 0; |
2977 } | 2977 } |
2978 if (objnum >= (FX_DWORD)pParser->m_CrossRef.GetSize()) { | 2978 if (objnum >= (FX_DWORD)pParser->m_CrossRef.GetSize()) { |
2979 return 0; | 2979 return 0; |
2980 } | 2980 } |
2981 if (pParser->m_V5Type[objnum] == 2) { | 2981 if (pParser->m_V5Type[objnum] == 2) { |
2982 objnum = (FX_DWORD)pParser->m_CrossRef[objnum]; | 2982 objnum = (FX_DWORD)pParser->m_CrossRef[objnum]; |
2983 } | 2983 } |
2984 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) { | 2984 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) { |
2985 offset = pParser->m_CrossRef[objnum]; | 2985 offset = pParser->m_CrossRef[objnum]; |
2986 if (offset == 0) { | 2986 if (offset == 0) { |
2987 return 0; | 2987 return 0; |
2988 } | 2988 } |
2989 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), | 2989 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), |
2990 pParser->m_SortedOffset.GetSize(), | 2990 pParser->m_SortedOffset.GetSize(), |
2991 sizeof(FX_FILESIZE), CompareFileSize); | 2991 sizeof(FX_FILESIZE), CompareFileSize); |
2992 if (pResult == NULL) { | 2992 if (!pResult) { |
2993 return 0; | 2993 return 0; |
2994 } | 2994 } |
2995 if ((FX_FILESIZE*)pResult - | 2995 if ((FX_FILESIZE*)pResult - |
2996 (FX_FILESIZE*)pParser->m_SortedOffset.GetData() == | 2996 (FX_FILESIZE*)pParser->m_SortedOffset.GetData() == |
2997 pParser->m_SortedOffset.GetSize() - 1) { | 2997 pParser->m_SortedOffset.GetSize() - 1) { |
2998 return 0; | 2998 return 0; |
2999 } | 2999 } |
3000 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); | 3000 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); |
3001 } | 3001 } |
3002 return 0; | 3002 return 0; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3236 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, | 3236 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, |
3237 IFX_DownloadHints* pHints, | 3237 IFX_DownloadHints* pHints, |
3238 FX_BOOL* pExistInFile) { | 3238 FX_BOOL* pExistInFile) { |
3239 CPDF_Object* pRet = nullptr; | 3239 CPDF_Object* pRet = nullptr; |
3240 FX_DWORD size = 0; | 3240 FX_DWORD size = 0; |
3241 FX_FILESIZE offset = 0; | 3241 FX_FILESIZE offset = 0; |
3242 CPDF_Parser* pParser = nullptr; | 3242 CPDF_Parser* pParser = nullptr; |
3243 if (pExistInFile) | 3243 if (pExistInFile) |
3244 *pExistInFile = TRUE; | 3244 *pExistInFile = TRUE; |
3245 | 3245 |
3246 if (m_pDocument == NULL) { | 3246 if (m_pDocument) { |
3247 size = GetObjectSize(objnum, offset); | |
3248 pParser = (CPDF_Parser*)(m_pDocument->GetParser()); | |
3249 } else { | |
3247 size = (FX_DWORD)m_parser.GetObjectSize(objnum); | 3250 size = (FX_DWORD)m_parser.GetObjectSize(objnum); |
3248 offset = m_parser.GetObjectOffset(objnum); | 3251 offset = m_parser.GetObjectOffset(objnum); |
3249 pParser = &m_parser; | 3252 pParser = &m_parser; |
3250 } else { | |
3251 size = GetObjectSize(objnum, offset); | |
3252 pParser = (CPDF_Parser*)(m_pDocument->GetParser()); | |
3253 } | 3253 } |
3254 if (!IsDataAvail(offset, size, pHints)) { | 3254 if (!IsDataAvail(offset, size, pHints)) { |
3255 return nullptr; | 3255 return nullptr; |
3256 } | 3256 } |
3257 if (pParser) { | 3257 if (pParser) { |
3258 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); | 3258 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); |
3259 } | 3259 } |
3260 | 3260 |
3261 if (!pRet && pExistInFile) { | 3261 if (!pRet && pExistInFile) { |
3262 *pExistInFile = FALSE; | 3262 *pExistInFile = FALSE; |
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4939 if (!m_pLinearizedDict) | 4939 if (!m_pLinearizedDict) |
4940 return -1; | 4940 return -1; |
4941 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4941 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4942 if (!pRange) | 4942 if (!pRange) |
4943 return -1; | 4943 return -1; |
4944 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4944 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4945 if (!pStreamLen) | 4945 if (!pStreamLen) |
4946 return -1; | 4946 return -1; |
4947 return pStreamLen->GetInteger(); | 4947 return pStreamLen->GetInteger(); |
4948 } | 4948 } |
OLD | NEW |