| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/include/fpdfapi/fpdf_module.h" | 13 #include "core/include/fpdfapi/fpdf_module.h" |
| 14 #include "core/include/fpdfapi/fpdf_page.h" | 14 #include "core/include/fpdfapi/fpdf_page.h" |
| 15 #include "core/include/fpdfapi/fpdf_parser.h" | 15 #include "core/include/fpdfapi/fpdf_parser.h" |
| 16 #include "core/include/fxcrt/fx_ext.h" | 16 #include "core/include/fxcrt/fx_ext.h" |
| 17 #include "core/include/fxcrt/fx_safe_types.h" | 17 #include "core/include/fxcrt/fx_safe_types.h" |
| 18 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 18 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
| 19 #include "third_party/base/nonstd_unique_ptr.h" | 19 #include "third_party/base/nonstd_unique_ptr.h" |
| 20 #include "third_party/base/stl_util.h" | 20 #include "third_party/base/stl_util.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // A limit on the size of the xref table. Theoretical limits are higher, but |
| 25 // this may be large enough in practice. |
| 26 const int32_t kMaxXRefSize = 1048576; |
| 27 |
| 28 // A limit on the maximum object number in the xref table. Theoretical limits |
| 29 // are higher, but this may be large enough in practice. |
| 30 const FX_DWORD kMaxObjectNumber = 1048576; |
| 31 |
| 24 struct SearchTagRecord { | 32 struct SearchTagRecord { |
| 25 const char* m_pTag; | 33 const char* m_pTag; |
| 26 FX_DWORD m_Len; | 34 FX_DWORD m_Len; |
| 27 FX_DWORD m_Offset; | 35 FX_DWORD m_Offset; |
| 28 }; | 36 }; |
| 29 | 37 |
| 30 int CompareFileSize(const void* p1, const void* p2) { | 38 int CompareFileSize(const void* p1, const void* p2) { |
| 31 return *(FX_FILESIZE*)p1 - *(FX_FILESIZE*)p2; | 39 return *(FX_FILESIZE*)p1 - *(FX_FILESIZE*)p2; |
| 32 } | 40 } |
| 33 | 41 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 m_pLinearized = NULL; | 117 m_pLinearized = NULL; |
| 110 m_dwFirstPageNo = 0; | 118 m_dwFirstPageNo = 0; |
| 111 m_dwXrefStartObjNum = 0; | 119 m_dwXrefStartObjNum = 0; |
| 112 m_bOwnFileRead = TRUE; | 120 m_bOwnFileRead = TRUE; |
| 113 m_FileVersion = 0; | 121 m_FileVersion = 0; |
| 114 m_bForceUseSecurityHandler = FALSE; | 122 m_bForceUseSecurityHandler = FALSE; |
| 115 } | 123 } |
| 116 CPDF_Parser::~CPDF_Parser() { | 124 CPDF_Parser::~CPDF_Parser() { |
| 117 CloseParser(FALSE); | 125 CloseParser(FALSE); |
| 118 } | 126 } |
| 119 FX_DWORD CPDF_Parser::GetLastObjNum() { | 127 |
| 120 FX_DWORD dwSize = m_CrossRef.GetSize(); | 128 FX_DWORD CPDF_Parser::GetLastObjNum() const { |
| 121 return dwSize ? dwSize - 1 : 0; | 129 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; |
| 122 } | 130 } |
| 131 |
| 132 bool CPDF_Parser::IsValidObjectNumber(FX_DWORD objnum) const { |
| 133 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; |
| 134 } |
| 135 |
| 123 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { | 136 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { |
| 124 m_pEncryptDict = pDict; | 137 m_pEncryptDict = pDict; |
| 125 } | 138 } |
| 126 void CPDF_Parser::CloseParser(FX_BOOL bReParse) { | 139 void CPDF_Parser::CloseParser(FX_BOOL bReParse) { |
| 127 m_bVersionUpdated = FALSE; | 140 m_bVersionUpdated = FALSE; |
| 128 if (!bReParse) { | 141 if (!bReParse) { |
| 129 delete m_pDocument; | 142 delete m_pDocument; |
| 130 m_pDocument = NULL; | 143 m_pDocument = NULL; |
| 131 } | 144 } |
| 132 if (m_pTrailer) { | 145 if (m_pTrailer) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 143 while (pos) { | 156 while (pos) { |
| 144 void* objnum; | 157 void* objnum; |
| 145 CPDF_StreamAcc* pStream; | 158 CPDF_StreamAcc* pStream; |
| 146 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | 159 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); |
| 147 delete pStream; | 160 delete pStream; |
| 148 } | 161 } |
| 149 m_ObjectStreamMap.RemoveAll(); | 162 m_ObjectStreamMap.RemoveAll(); |
| 150 m_ObjCache.clear(); | 163 m_ObjCache.clear(); |
| 151 | 164 |
| 152 m_SortedOffset.RemoveAll(); | 165 m_SortedOffset.RemoveAll(); |
| 153 m_CrossRef.RemoveAll(); | 166 m_ObjectInfo.clear(); |
| 154 m_V5Type.RemoveAll(); | 167 m_V5Type.RemoveAll(); |
| 155 m_ObjVersion.RemoveAll(); | 168 m_ObjVersion.RemoveAll(); |
| 156 int32_t iLen = m_Trailers.GetSize(); | 169 int32_t iLen = m_Trailers.GetSize(); |
| 157 for (int32_t i = 0; i < iLen; ++i) { | 170 for (int32_t i = 0; i < iLen; ++i) { |
| 158 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) | 171 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) |
| 159 trailer->Release(); | 172 trailer->Release(); |
| 160 } | 173 } |
| 161 m_Trailers.RemoveAll(); | 174 m_Trailers.RemoveAll(); |
| 162 if (m_pLinearized) { | 175 if (m_pLinearized) { |
| 163 m_pLinearized->Release(); | 176 m_pLinearized->Release(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 337 } |
| 325 return PDFPARSE_ERROR_SUCCESS; | 338 return PDFPARSE_ERROR_SUCCESS; |
| 326 } | 339 } |
| 327 void CPDF_Parser::ReleaseEncryptHandler() { | 340 void CPDF_Parser::ReleaseEncryptHandler() { |
| 328 m_Syntax.m_pCryptoHandler.reset(); | 341 m_Syntax.m_pCryptoHandler.reset(); |
| 329 if (!m_bForceUseSecurityHandler) { | 342 if (!m_bForceUseSecurityHandler) { |
| 330 m_pSecurityHandler.reset(); | 343 m_pSecurityHandler.reset(); |
| 331 } | 344 } |
| 332 } | 345 } |
| 333 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { | 346 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { |
| 334 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 347 if (!IsValidObjectNumber(objnum)) |
| 335 return 0; | 348 return 0; |
| 336 } | 349 |
| 337 if (m_V5Type[objnum] == 1) { | 350 if (m_V5Type[objnum] == 1) |
| 338 return m_CrossRef[objnum]; | 351 return m_ObjectInfo[objnum].pos; |
| 339 } | 352 |
| 340 if (m_V5Type[objnum] == 2) { | 353 if (m_V5Type[objnum] == 2) { |
| 341 return m_CrossRef[(int32_t)m_CrossRef[objnum]]; | 354 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 355 return m_ObjectInfo[pos].pos; |
| 342 } | 356 } |
| 343 return 0; | 357 return 0; |
| 344 } | 358 } |
| 345 | 359 |
| 346 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { | 360 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { |
| 347 if (!LoadCrossRefV4(xrefpos, 0, TRUE)) { | 361 if (!LoadCrossRefV4(xrefpos, 0, TRUE)) { |
| 348 return FALSE; | 362 return FALSE; |
| 349 } | 363 } |
| 350 m_pTrailer = LoadTrailerV4(); | 364 m_pTrailer = LoadTrailerV4(); |
| 351 if (!m_pTrailer) { | 365 if (!m_pTrailer) { |
| 352 return FALSE; | 366 return FALSE; |
| 353 } | 367 } |
| 354 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 368 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
| 355 if (xrefsize <= 0 || xrefsize > (1 << 20)) { | 369 if (xrefsize <= 0 || xrefsize > kMaxXRefSize) { |
| 356 return FALSE; | 370 return FALSE; |
| 357 } | 371 } |
| 358 m_CrossRef.SetSize(xrefsize); | 372 m_ObjectInfo[0].pos = 0; |
| 359 m_V5Type.SetSize(xrefsize); | 373 m_V5Type.SetSize(xrefsize); |
| 360 CFX_FileSizeArray CrossRefList, XRefStreamList; | 374 CFX_FileSizeArray CrossRefList, XRefStreamList; |
| 361 CrossRefList.Add(xrefpos); | 375 CrossRefList.Add(xrefpos); |
| 362 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); | 376 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); |
| 363 if (!CheckDirectType(m_pTrailer, "Prev", PDFOBJ_NUMBER)) { | 377 if (!CheckDirectType(m_pTrailer, "Prev", PDFOBJ_NUMBER)) { |
| 364 return FALSE; | 378 return FALSE; |
| 365 } | 379 } |
| 366 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, "Prev"); | 380 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, "Prev"); |
| 367 if (newxrefpos == xrefpos) { | 381 if (newxrefpos == xrefpos) { |
| 368 return FALSE; | 382 return FALSE; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { | 465 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { |
| 452 return FALSE; | 466 return FALSE; |
| 453 } | 467 } |
| 454 if (!m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), dwReadSize)) { | 468 if (!m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), dwReadSize)) { |
| 455 return FALSE; | 469 return FALSE; |
| 456 } | 470 } |
| 457 for (int32_t i = 0; i < block_size; i++) { | 471 for (int32_t i = 0; i < block_size; i++) { |
| 458 FX_DWORD objnum = start_objnum + block * 1024 + i; | 472 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 459 char* pEntry = pBuf + i * recordsize; | 473 char* pEntry = pBuf + i * recordsize; |
| 460 if (pEntry[17] == 'f') { | 474 if (pEntry[17] == 'f') { |
| 461 m_CrossRef.SetAtGrow(objnum, 0); | 475 m_ObjectInfo[objnum].pos = 0; |
| 462 m_V5Type.SetAtGrow(objnum, 0); | 476 m_V5Type.SetAtGrow(objnum, 0); |
| 463 } else { | 477 } else { |
| 464 int32_t offset = FXSYS_atoi(pEntry); | 478 int32_t offset = FXSYS_atoi(pEntry); |
| 465 if (offset == 0) { | 479 if (offset == 0) { |
| 466 for (int32_t c = 0; c < 10; c++) { | 480 for (int32_t c = 0; c < 10; c++) { |
| 467 if (!std::isdigit(pEntry[c])) | 481 if (!std::isdigit(pEntry[c])) |
| 468 return FALSE; | 482 return FALSE; |
| 469 } | 483 } |
| 470 } | 484 } |
| 471 m_CrossRef.SetAtGrow(objnum, offset); | 485 m_ObjectInfo[objnum].pos = offset; |
| 472 int32_t version = FXSYS_atoi(pEntry + 11); | 486 int32_t version = FXSYS_atoi(pEntry + 11); |
| 473 if (version >= 1) { | 487 if (version >= 1) { |
| 474 m_bVersionUpdated = TRUE; | 488 m_bVersionUpdated = TRUE; |
| 475 } | 489 } |
| 476 m_ObjVersion.SetAtGrow(objnum, version); | 490 m_ObjVersion.SetAtGrow(objnum, version); |
| 477 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 491 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen) { |
| 478 void* pResult = FXSYS_bsearch( | 492 void* pResult = FXSYS_bsearch( |
| 479 &m_CrossRef[objnum], m_SortedOffset.GetData(), | 493 &m_ObjectInfo[objnum].pos, m_SortedOffset.GetData(), |
| 480 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); | 494 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); |
| 481 if (!pResult) { | 495 if (!pResult) { |
| 482 m_SortedOffset.Add(m_CrossRef[objnum]); | 496 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); |
| 483 } | 497 } |
| 484 } | 498 } |
| 485 m_V5Type.SetAtGrow(objnum, 1); | 499 m_V5Type.SetAtGrow(objnum, 1); |
| 486 } | 500 } |
| 487 } | 501 } |
| 488 } | 502 } |
| 489 m_Syntax.RestorePos(SavedPos + count * recordsize); | 503 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| 490 return TRUE; | 504 return TRUE; |
| 491 } | 505 } |
| 492 | 506 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 513 FX_BOOL bIsNumber; | 527 FX_BOOL bIsNumber; |
| 514 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 528 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
| 515 if (word.IsEmpty()) | 529 if (word.IsEmpty()) |
| 516 return false; | 530 return false; |
| 517 | 531 |
| 518 if (!bIsNumber) { | 532 if (!bIsNumber) { |
| 519 m_Syntax.RestorePos(SavedPos); | 533 m_Syntax.RestorePos(SavedPos); |
| 520 break; | 534 break; |
| 521 } | 535 } |
| 522 FX_DWORD start_objnum = FXSYS_atoi(word); | 536 FX_DWORD start_objnum = FXSYS_atoi(word); |
| 523 if (start_objnum >= (1 << 20)) | 537 if (start_objnum >= kMaxObjectNumber) |
| 524 return false; | 538 return false; |
| 525 | 539 |
| 526 FX_DWORD count = m_Syntax.GetDirectNum(); | 540 FX_DWORD count = m_Syntax.GetDirectNum(); |
| 527 m_Syntax.ToNextWord(); | 541 m_Syntax.ToNextWord(); |
| 528 SavedPos = m_Syntax.SavePos(); | 542 SavedPos = m_Syntax.SavePos(); |
| 529 const int32_t recordsize = 20; | 543 const int32_t recordsize = 20; |
| 530 m_dwXrefStartObjNum = start_objnum; | 544 m_dwXrefStartObjNum = start_objnum; |
| 531 if (!bSkip) { | 545 if (!bSkip) { |
| 532 std::vector<char> buf(1024 * recordsize + 1); | 546 std::vector<char> buf(1024 * recordsize + 1); |
| 533 char* pBuf = pdfium::vector_as_array(&buf); | 547 char* pBuf = pdfium::vector_as_array(&buf); |
| 534 pBuf[1024 * recordsize] = '\0'; | 548 pBuf[1024 * recordsize] = '\0'; |
| 535 int32_t nBlocks = count / 1024 + 1; | 549 int32_t nBlocks = count / 1024 + 1; |
| 536 for (int32_t block = 0; block < nBlocks; block++) { | 550 for (int32_t block = 0; block < nBlocks; block++) { |
| 537 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 551 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
| 538 m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), | 552 m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), |
| 539 block_size * recordsize); | 553 block_size * recordsize); |
| 540 for (int32_t i = 0; i < block_size; i++) { | 554 for (int32_t i = 0; i < block_size; i++) { |
| 541 FX_DWORD objnum = start_objnum + block * 1024 + i; | 555 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 542 char* pEntry = pBuf + i * recordsize; | 556 char* pEntry = pBuf + i * recordsize; |
| 543 if (pEntry[17] == 'f') { | 557 if (pEntry[17] == 'f') { |
| 544 m_CrossRef.SetAtGrow(objnum, 0); | 558 m_ObjectInfo[objnum].pos = 0; |
| 545 m_V5Type.SetAtGrow(objnum, 0); | 559 m_V5Type.SetAtGrow(objnum, 0); |
| 546 } else { | 560 } else { |
| 547 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 561 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
| 548 if (offset == 0) { | 562 if (offset == 0) { |
| 549 for (int32_t c = 0; c < 10; c++) { | 563 for (int32_t c = 0; c < 10; c++) { |
| 550 if (!std::isdigit(pEntry[c])) | 564 if (!std::isdigit(pEntry[c])) |
| 551 return false; | 565 return false; |
| 552 } | 566 } |
| 553 } | 567 } |
| 554 m_CrossRef.SetAtGrow(objnum, offset); | 568 m_ObjectInfo[objnum].pos = offset; |
| 555 int32_t version = FXSYS_atoi(pEntry + 11); | 569 int32_t version = FXSYS_atoi(pEntry + 11); |
| 556 if (version >= 1) { | 570 if (version >= 1) { |
| 557 m_bVersionUpdated = TRUE; | 571 m_bVersionUpdated = TRUE; |
| 558 } | 572 } |
| 559 m_ObjVersion.SetAtGrow(objnum, version); | 573 m_ObjVersion.SetAtGrow(objnum, version); |
| 560 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && | 574 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen && |
| 561 !FindPosInOffsets(m_CrossRef[objnum])) { | 575 !FindPosInOffsets(m_ObjectInfo[objnum].pos)) { |
| 562 m_SortedOffset.Add(m_CrossRef[objnum]); | 576 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); |
| 563 } | 577 } |
| 564 m_V5Type.SetAtGrow(objnum, 1); | 578 m_V5Type.SetAtGrow(objnum, 1); |
| 565 } | 579 } |
| 566 } | 580 } |
| 567 } | 581 } |
| 568 } | 582 } |
| 569 m_Syntax.RestorePos(SavedPos + count * recordsize); | 583 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| 570 } | 584 } |
| 571 return !streampos || LoadCrossRefV5(&streampos, FALSE); | 585 return !streampos || LoadCrossRefV5(&streampos, FALSE); |
| 572 } | 586 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 585 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { | 599 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { |
| 586 return FALSE; | 600 return FALSE; |
| 587 } | 601 } |
| 588 } | 602 } |
| 589 m_ObjectStreamMap.InitHashTable(101, FALSE); | 603 m_ObjectStreamMap.InitHashTable(101, FALSE); |
| 590 m_bXRefStream = TRUE; | 604 m_bXRefStream = TRUE; |
| 591 return TRUE; | 605 return TRUE; |
| 592 } | 606 } |
| 593 | 607 |
| 594 FX_BOOL CPDF_Parser::RebuildCrossRef() { | 608 FX_BOOL CPDF_Parser::RebuildCrossRef() { |
| 595 m_CrossRef.RemoveAll(); | 609 m_ObjectInfo.clear(); |
| 596 m_V5Type.RemoveAll(); | 610 m_V5Type.RemoveAll(); |
| 597 m_SortedOffset.RemoveAll(); | 611 m_SortedOffset.RemoveAll(); |
| 598 m_ObjVersion.RemoveAll(); | 612 m_ObjVersion.RemoveAll(); |
| 599 if (m_pTrailer) { | 613 if (m_pTrailer) { |
| 600 m_pTrailer->Release(); | 614 m_pTrailer->Release(); |
| 601 m_pTrailer = NULL; | 615 m_pTrailer = NULL; |
| 602 } | 616 } |
| 603 int32_t status = 0; | 617 int32_t status = 0; |
| 604 int32_t inside_index = 0; | 618 int32_t inside_index = 0; |
| 605 FX_DWORD objnum = 0, gennum = 0; | 619 FX_DWORD objnum = 0, gennum = 0; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } else { | 801 } else { |
| 788 offset += 3; | 802 offset += 3; |
| 789 } | 803 } |
| 790 FX_FILESIZE nLen = obj_end - obj_pos - offset; | 804 FX_FILESIZE nLen = obj_end - obj_pos - offset; |
| 791 if ((FX_DWORD)nLen > size - i) { | 805 if ((FX_DWORD)nLen > size - i) { |
| 792 pos = obj_end + m_Syntax.m_HeaderOffset; | 806 pos = obj_end + m_Syntax.m_HeaderOffset; |
| 793 bOverFlow = TRUE; | 807 bOverFlow = TRUE; |
| 794 } else { | 808 } else { |
| 795 i += (FX_DWORD)nLen; | 809 i += (FX_DWORD)nLen; |
| 796 } | 810 } |
| 797 if (m_CrossRef.GetSize() > (int32_t)objnum && | 811 if (!m_ObjectInfo.empty() && IsValidObjectNumber(objnum) && |
| 798 m_CrossRef[objnum]) { | 812 m_ObjectInfo[objnum].pos) { |
| 799 if (pObject) { | 813 if (pObject) { |
| 800 FX_DWORD oldgen = m_ObjVersion.GetAt(objnum); | 814 FX_DWORD oldgen = m_ObjVersion.GetAt(objnum); |
| 801 m_CrossRef[objnum] = obj_pos; | 815 m_ObjectInfo[objnum].pos = obj_pos; |
| 802 m_ObjVersion.SetAt(objnum, (int16_t)gennum); | 816 m_ObjVersion.SetAt(objnum, (int16_t)gennum); |
| 803 if (oldgen != gennum) { | 817 if (oldgen != gennum) { |
| 804 m_bVersionUpdated = TRUE; | 818 m_bVersionUpdated = TRUE; |
| 805 } | 819 } |
| 806 } | 820 } |
| 807 } else { | 821 } else { |
| 808 m_CrossRef.SetAtGrow(objnum, obj_pos); | 822 m_ObjectInfo[objnum].pos = obj_pos; |
| 809 m_V5Type.SetAtGrow(objnum, 1); | 823 m_V5Type.SetAtGrow(objnum, 1); |
| 810 m_ObjVersion.SetAtGrow(objnum, (int16_t)gennum); | 824 m_ObjVersion.SetAtGrow(objnum, (int16_t)gennum); |
| 811 } | 825 } |
| 812 if (pObject) { | 826 if (pObject) { |
| 813 pObject->Release(); | 827 pObject->Release(); |
| 814 } | 828 } |
| 815 } | 829 } |
| 816 --i; | 830 --i; |
| 817 status = 0; | 831 status = 0; |
| 818 break; | 832 break; |
| 819 } | 833 } |
| 820 break; | 834 break; |
| 821 case 7: | 835 case 7: |
| 822 if (inside_index == 7) { | 836 if (inside_index == 7) { |
| 823 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { | 837 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { |
| 824 last_trailer = pos + i - 7; | 838 last_trailer = pos + i - 7; |
| 825 m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); | 839 m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); |
| 826 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); | 840 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); |
| 827 if (pObj) { | 841 if (pObj) { |
| 828 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 842 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
| 829 pObj->Release(); | 843 pObj->Release(); |
| 830 } else { | 844 } else { |
| 831 CPDF_Stream* pStream = pObj->AsStream(); | 845 CPDF_Stream* pStream = pObj->AsStream(); |
| 832 if (CPDF_Dictionary* pTrailer = | 846 if (CPDF_Dictionary* pTrailer = |
| 833 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 847 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
| 834 if (m_pTrailer) { | 848 if (m_pTrailer) { |
| 835 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 849 CPDF_Object* pRoot = pTrailer->GetElement("Root"); |
| 836 CPDF_Reference* pRef = ToReference(pRoot); | 850 CPDF_Reference* pRef = ToReference(pRoot); |
| 837 if (!pRoot || | 851 if (!pRoot || |
| 838 (pRef && | 852 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
| 839 (FX_DWORD)m_CrossRef.GetSize() > | 853 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
| 840 pRef->GetRefObjNum() && | |
| 841 m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) { | |
| 842 FX_POSITION pos = pTrailer->GetStartPos(); | 854 FX_POSITION pos = pTrailer->GetStartPos(); |
| 843 while (pos) { | 855 while (pos) { |
| 844 CFX_ByteString key; | 856 CFX_ByteString key; |
| 845 CPDF_Object* pElement = | 857 CPDF_Object* pElement = |
| 846 pTrailer->GetNextElement(pos, key); | 858 pTrailer->GetNextElement(pos, key); |
| 847 FX_DWORD dwObjNum = | 859 FX_DWORD dwObjNum = |
| 848 pElement ? pElement->GetObjNum() : 0; | 860 pElement ? pElement->GetObjNum() : 0; |
| 849 if (dwObjNum) { | 861 if (dwObjNum) { |
| 850 m_pTrailer->SetAtReference(key, m_pDocument, | 862 m_pTrailer->SetAtReference(key, m_pDocument, |
| 851 dwObjNum); | 863 dwObjNum); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 last_trailer = m_Syntax.m_FileLen; | 969 last_trailer = m_Syntax.m_FileLen; |
| 958 } | 970 } |
| 959 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; | 971 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; |
| 960 void* pResult = | 972 void* pResult = |
| 961 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 973 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 962 sizeof(FX_FILESIZE), CompareFileSize); | 974 sizeof(FX_FILESIZE), CompareFileSize); |
| 963 if (!pResult) { | 975 if (!pResult) { |
| 964 m_SortedOffset.Add(offset); | 976 m_SortedOffset.Add(offset); |
| 965 } | 977 } |
| 966 FX_Free(buffer); | 978 FX_Free(buffer); |
| 967 return m_pTrailer && m_CrossRef.GetSize() > 0; | 979 return m_pTrailer && !m_ObjectInfo.empty(); |
| 968 } | 980 } |
| 969 | 981 |
| 970 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { | 982 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { |
| 971 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr); | 983 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr); |
| 972 if (!pObject) | 984 if (!pObject) |
| 973 return FALSE; | 985 return FALSE; |
| 974 if (m_pDocument) { | 986 if (m_pDocument) { |
| 975 FX_BOOL bInserted = FALSE; | 987 FX_BOOL bInserted = FALSE; |
| 976 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 988 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
| 977 if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) { | 989 if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 989 return FALSE; | 1001 return FALSE; |
| 990 | 1002 |
| 991 *pos = pStream->GetDict()->GetInteger("Prev"); | 1003 *pos = pStream->GetDict()->GetInteger("Prev"); |
| 992 int32_t size = pStream->GetDict()->GetInteger("Size"); | 1004 int32_t size = pStream->GetDict()->GetInteger("Size"); |
| 993 if (size < 0) { | 1005 if (size < 0) { |
| 994 pStream->Release(); | 1006 pStream->Release(); |
| 995 return FALSE; | 1007 return FALSE; |
| 996 } | 1008 } |
| 997 if (bMainXRef) { | 1009 if (bMainXRef) { |
| 998 m_pTrailer = ToDictionary(pStream->GetDict()->Clone()); | 1010 m_pTrailer = ToDictionary(pStream->GetDict()->Clone()); |
| 999 m_CrossRef.SetSize(size); | 1011 m_ObjectInfo[0].pos = 0; |
| 1000 if (m_V5Type.SetSize(size)) { | 1012 if (m_V5Type.SetSize(size)) { |
| 1001 FXSYS_memset(m_V5Type.GetData(), 0, size); | 1013 FXSYS_memset(m_V5Type.GetData(), 0, size); |
| 1002 } | 1014 } |
| 1003 } else { | 1015 } else { |
| 1004 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); | 1016 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); |
| 1005 } | 1017 } |
| 1006 std::vector<std::pair<int32_t, int32_t> > arrIndex; | 1018 std::vector<std::pair<int32_t, int32_t> > arrIndex; |
| 1007 CPDF_Array* pArray = pStream->GetDict()->GetArray("Index"); | 1019 CPDF_Array* pArray = pStream->GetDict()->GetArray("Index"); |
| 1008 if (pArray) { | 1020 if (pArray) { |
| 1009 FX_DWORD nPairSize = pArray->GetCount() / 2; | 1021 FX_DWORD nPairSize = pArray->GetCount() / 2; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 } | 1081 } |
| 1070 for (FX_DWORD j = 0; j < count; j++) { | 1082 for (FX_DWORD j = 0; j < count; j++) { |
| 1071 int32_t type = 1; | 1083 int32_t type = 1; |
| 1072 const uint8_t* entrystart = segstart + j * totalWidth; | 1084 const uint8_t* entrystart = segstart + j * totalWidth; |
| 1073 if (WidthArray[0]) { | 1085 if (WidthArray[0]) { |
| 1074 type = GetVarInt(entrystart, WidthArray[0]); | 1086 type = GetVarInt(entrystart, WidthArray[0]); |
| 1075 } | 1087 } |
| 1076 if (m_V5Type[startnum + j] == 255) { | 1088 if (m_V5Type[startnum + j] == 255) { |
| 1077 FX_FILESIZE offset = | 1089 FX_FILESIZE offset = |
| 1078 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1090 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
| 1079 m_CrossRef[startnum + j] = offset; | 1091 m_ObjectInfo[startnum + j].pos = offset; |
| 1080 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1092 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
| 1081 m_SortedOffset.GetSize(), | 1093 m_SortedOffset.GetSize(), |
| 1082 sizeof(FX_FILESIZE), CompareFileSize); | 1094 sizeof(FX_FILESIZE), CompareFileSize); |
| 1083 if (!pResult) { | 1095 if (!pResult) { |
| 1084 m_SortedOffset.Add(offset); | 1096 m_SortedOffset.Add(offset); |
| 1085 } | 1097 } |
| 1086 continue; | 1098 continue; |
| 1087 } | 1099 } |
| 1088 if (m_V5Type[startnum + j]) { | 1100 if (m_V5Type[startnum + j]) { |
| 1089 continue; | 1101 continue; |
| 1090 } | 1102 } |
| 1091 m_V5Type[startnum + j] = type; | 1103 m_V5Type[startnum + j] = type; |
| 1092 if (type == 0) { | 1104 if (type == 0) { |
| 1093 m_CrossRef[startnum + j] = 0; | 1105 m_ObjectInfo[startnum + j].pos = 0; |
| 1094 } else { | 1106 } else { |
| 1095 FX_FILESIZE offset = | 1107 FX_FILESIZE offset = |
| 1096 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1108 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
| 1097 m_CrossRef[startnum + j] = offset; | 1109 m_ObjectInfo[startnum + j].pos = offset; |
| 1098 if (type == 1) { | 1110 if (type == 1) { |
| 1099 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1111 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
| 1100 m_SortedOffset.GetSize(), | 1112 m_SortedOffset.GetSize(), |
| 1101 sizeof(FX_FILESIZE), CompareFileSize); | 1113 sizeof(FX_FILESIZE), CompareFileSize); |
| 1102 if (!pResult) { | 1114 if (!pResult) { |
| 1103 m_SortedOffset.Add(offset); | 1115 m_SortedOffset.Add(offset); |
| 1104 } | 1116 } |
| 1105 } else { | 1117 } else { |
| 1106 if (offset < 0 || offset >= m_V5Type.GetSize()) { | 1118 if (offset < 0 || offset >= m_V5Type.GetSize()) { |
| 1107 pStream->Release(); | 1119 pStream->Release(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1132 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); | 1144 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); |
| 1133 return pRef ? pRef->GetRefObjNum() : 0; | 1145 return pRef ? pRef->GetRefObjNum() : 0; |
| 1134 } | 1146 } |
| 1135 FX_DWORD CPDF_Parser::GetInfoObjNum() { | 1147 FX_DWORD CPDF_Parser::GetInfoObjNum() { |
| 1136 CPDF_Reference* pRef = | 1148 CPDF_Reference* pRef = |
| 1137 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); | 1149 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); |
| 1138 return pRef ? pRef->GetRefObjNum() : 0; | 1150 return pRef ? pRef->GetRefObjNum() : 0; |
| 1139 } | 1151 } |
| 1140 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { | 1152 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { |
| 1141 bForm = FALSE; | 1153 bForm = FALSE; |
| 1142 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1154 if (!IsValidObjectNumber(objnum)) |
| 1143 return TRUE; | 1155 return TRUE; |
| 1144 } | 1156 if (m_V5Type[objnum] == 0) |
| 1145 if (m_V5Type[objnum] == 0) { | |
| 1146 return TRUE; | 1157 return TRUE; |
| 1147 } | 1158 if (m_V5Type[objnum] == 2) |
| 1148 if (m_V5Type[objnum] == 2) { | |
| 1149 return TRUE; | 1159 return TRUE; |
| 1150 } | 1160 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1151 FX_FILESIZE pos = m_CrossRef[objnum]; | |
| 1152 void* pResult = | 1161 void* pResult = |
| 1153 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1162 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 1154 sizeof(FX_FILESIZE), CompareFileSize); | 1163 sizeof(FX_FILESIZE), CompareFileSize); |
| 1155 if (!pResult) { | 1164 if (!pResult) { |
| 1156 return TRUE; | 1165 return TRUE; |
| 1157 } | 1166 } |
| 1158 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1167 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == |
| 1159 m_SortedOffset.GetSize() - 1) { | 1168 m_SortedOffset.GetSize() - 1) { |
| 1160 return FALSE; | 1169 return FALSE; |
| 1161 } | 1170 } |
| 1162 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; | 1171 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; |
| 1163 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1172 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1164 m_Syntax.RestorePos(pos); | 1173 m_Syntax.RestorePos(pos); |
| 1165 const char kFormStream[] = "/Form\0stream"; | 1174 const char kFormStream[] = "/Form\0stream"; |
| 1166 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); | 1175 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); |
| 1167 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; | 1176 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; |
| 1168 m_Syntax.RestorePos(SavedPos); | 1177 m_Syntax.RestorePos(SavedPos); |
| 1169 return TRUE; | 1178 return TRUE; |
| 1170 } | 1179 } |
| 1171 | 1180 |
| 1172 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, | 1181 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, |
| 1173 FX_DWORD objnum, | 1182 FX_DWORD objnum, |
| 1174 PARSE_CONTEXT* pContext) { | 1183 PARSE_CONTEXT* pContext) { |
| 1175 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) | 1184 if (!IsValidObjectNumber(objnum)) |
| 1176 return nullptr; | 1185 return nullptr; |
| 1177 | 1186 |
| 1178 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1187 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
| 1179 FX_FILESIZE pos = m_CrossRef[objnum]; | 1188 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1180 if (pos <= 0) | 1189 if (pos <= 0) |
| 1181 return nullptr; | 1190 return nullptr; |
| 1182 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); | 1191 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); |
| 1183 } | 1192 } |
| 1184 if (m_V5Type[objnum] != 2) | 1193 if (m_V5Type[objnum] != 2) |
| 1185 return nullptr; | 1194 return nullptr; |
| 1186 | 1195 |
| 1187 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); | 1196 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
| 1188 if (!pObjStream) | 1197 if (!pObjStream) |
| 1189 return nullptr; | 1198 return nullptr; |
| 1190 | 1199 |
| 1191 ScopedFileStream file(FX_CreateMemoryStream( | 1200 ScopedFileStream file(FX_CreateMemoryStream( |
| 1192 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1201 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); |
| 1193 CPDF_SyntaxParser syntax; | 1202 CPDF_SyntaxParser syntax; |
| 1194 syntax.InitParser(file.get(), 0); | 1203 syntax.InitParser(file.get(), 0); |
| 1195 const int32_t offset = GetStreamFirst(pObjStream); | 1204 const int32_t offset = GetStreamFirst(pObjStream); |
| 1196 | 1205 |
| 1197 // Read object numbers from |pObjStream| into a cache. | 1206 // Read object numbers from |pObjStream| into a cache. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1220 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); | 1229 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); |
| 1221 if (!pStream) | 1230 if (!pStream) |
| 1222 return nullptr; | 1231 return nullptr; |
| 1223 | 1232 |
| 1224 pStreamAcc = new CPDF_StreamAcc; | 1233 pStreamAcc = new CPDF_StreamAcc; |
| 1225 pStreamAcc->LoadAllData(pStream); | 1234 pStreamAcc->LoadAllData(pStream); |
| 1226 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); | 1235 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); |
| 1227 return pStreamAcc; | 1236 return pStreamAcc; |
| 1228 } | 1237 } |
| 1229 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { | 1238 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { |
| 1230 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1239 if (!IsValidObjectNumber(objnum)) |
| 1231 return 0; | 1240 return 0; |
| 1232 } | 1241 |
| 1233 if (m_V5Type[objnum] == 2) { | 1242 if (m_V5Type[objnum] == 2) { |
| 1234 objnum = (FX_DWORD)m_CrossRef[objnum]; | 1243 objnum = m_ObjectInfo[objnum].pos; |
| 1235 } | 1244 } |
| 1236 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1245 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
| 1237 FX_FILESIZE offset = m_CrossRef[objnum]; | 1246 FX_FILESIZE offset = m_ObjectInfo[objnum].pos; |
| 1238 if (offset == 0) { | 1247 if (offset == 0) { |
| 1239 return 0; | 1248 return 0; |
| 1240 } | 1249 } |
| 1241 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1250 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
| 1242 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 1251 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
| 1243 CompareFileSize); | 1252 CompareFileSize); |
| 1244 if (!pResult) { | 1253 if (!pResult) { |
| 1245 return 0; | 1254 return 0; |
| 1246 } | 1255 } |
| 1247 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1256 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == |
| 1248 m_SortedOffset.GetSize() - 1) { | 1257 m_SortedOffset.GetSize() - 1) { |
| 1249 return 0; | 1258 return 0; |
| 1250 } | 1259 } |
| 1251 return ((FX_FILESIZE*)pResult)[1] - offset; | 1260 return ((FX_FILESIZE*)pResult)[1] - offset; |
| 1252 } | 1261 } |
| 1253 return 0; | 1262 return 0; |
| 1254 } | 1263 } |
| 1255 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, | 1264 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, |
| 1256 uint8_t*& pBuffer, | 1265 uint8_t*& pBuffer, |
| 1257 FX_DWORD& size) { | 1266 FX_DWORD& size) { |
| 1258 pBuffer = NULL; | 1267 pBuffer = NULL; |
| 1259 size = 0; | 1268 size = 0; |
| 1260 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1269 if (!IsValidObjectNumber(objnum)) |
| 1261 return; | 1270 return; |
| 1262 } | 1271 |
| 1263 if (m_V5Type[objnum] == 2) { | 1272 if (m_V5Type[objnum] == 2) { |
| 1264 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); | 1273 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
| 1265 if (!pObjStream) | 1274 if (!pObjStream) |
| 1266 return; | 1275 return; |
| 1267 | 1276 |
| 1268 int32_t offset = GetStreamFirst(pObjStream); | 1277 int32_t offset = GetStreamFirst(pObjStream); |
| 1269 const uint8_t* pData = pObjStream->GetData(); | 1278 const uint8_t* pData = pObjStream->GetData(); |
| 1270 FX_DWORD totalsize = pObjStream->GetSize(); | 1279 FX_DWORD totalsize = pObjStream->GetSize(); |
| 1271 ScopedFileStream file( | 1280 ScopedFileStream file( |
| 1272 FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, FALSE)); | 1281 FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, FALSE)); |
| 1273 CPDF_SyntaxParser syntax; | 1282 CPDF_SyntaxParser syntax; |
| 1274 syntax.InitParser(file.get(), 0); | 1283 syntax.InitParser(file.get(), 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1288 pBuffer = FX_Alloc(uint8_t, size); | 1297 pBuffer = FX_Alloc(uint8_t, size); |
| 1289 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); | 1298 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); |
| 1290 return; | 1299 return; |
| 1291 } | 1300 } |
| 1292 return; | 1301 return; |
| 1293 } | 1302 } |
| 1294 | 1303 |
| 1295 if (m_V5Type[objnum] != 1) | 1304 if (m_V5Type[objnum] != 1) |
| 1296 return; | 1305 return; |
| 1297 | 1306 |
| 1298 FX_FILESIZE pos = m_CrossRef[objnum]; | 1307 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1299 if (pos == 0) { | 1308 if (pos == 0) { |
| 1300 return; | 1309 return; |
| 1301 } | 1310 } |
| 1302 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1311 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1303 m_Syntax.RestorePos(pos); | 1312 m_Syntax.RestorePos(pos); |
| 1304 FX_BOOL bIsNumber; | 1313 FX_BOOL bIsNumber; |
| 1305 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1314 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
| 1306 if (!bIsNumber) { | 1315 if (!bIsNumber) { |
| 1307 m_Syntax.RestorePos(SavedPos); | 1316 m_Syntax.RestorePos(SavedPos); |
| 1308 return; | 1317 return; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 bXRefRebuilt = TRUE; | 1571 bXRefRebuilt = TRUE; |
| 1563 m_LastXRefOffset = 0; | 1572 m_LastXRefOffset = 0; |
| 1564 } | 1573 } |
| 1565 if (bLoadV4) { | 1574 if (bLoadV4) { |
| 1566 m_pTrailer = LoadTrailerV4(); | 1575 m_pTrailer = LoadTrailerV4(); |
| 1567 if (!m_pTrailer) { | 1576 if (!m_pTrailer) { |
| 1568 return FALSE; | 1577 return FALSE; |
| 1569 } | 1578 } |
| 1570 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 1579 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
| 1571 if (xrefsize > 0) { | 1580 if (xrefsize > 0) { |
| 1572 m_CrossRef.SetSize(xrefsize); | 1581 m_ObjectInfo[0].pos = 0; |
| 1573 m_V5Type.SetSize(xrefsize); | 1582 m_V5Type.SetSize(xrefsize); |
| 1574 } | 1583 } |
| 1575 } | 1584 } |
| 1576 FX_DWORD dwRet = SetEncryptHandler(); | 1585 FX_DWORD dwRet = SetEncryptHandler(); |
| 1577 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1586 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
| 1578 return dwRet; | 1587 return dwRet; |
| 1579 } | 1588 } |
| 1580 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); | 1589 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); |
| 1581 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { | 1590 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { |
| 1582 if (bXRefRebuilt) { | 1591 if (bXRefRebuilt) { |
| (...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2957 int iSize = m_arrayAcroforms.GetSize(); | 2966 int iSize = m_arrayAcroforms.GetSize(); |
| 2958 for (int i = 0; i < iSize; ++i) { | 2967 for (int i = 0; i < iSize; ++i) { |
| 2959 m_arrayAcroforms.GetAt(i)->Release(); | 2968 m_arrayAcroforms.GetAt(i)->Release(); |
| 2960 } | 2969 } |
| 2961 } | 2970 } |
| 2962 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 2971 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
| 2963 m_pDocument = pDoc; | 2972 m_pDocument = pDoc; |
| 2964 } | 2973 } |
| 2965 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { | 2974 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { |
| 2966 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); | 2975 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); |
| 2967 if (!pParser) { | 2976 if (!pParser || !pParser->IsValidObjectNumber(objnum)) |
| 2968 return 0; | 2977 return 0; |
| 2969 } | 2978 |
| 2970 if (objnum >= (FX_DWORD)pParser->m_CrossRef.GetSize()) { | |
| 2971 return 0; | |
| 2972 } | |
| 2973 if (pParser->m_V5Type[objnum] == 2) { | 2979 if (pParser->m_V5Type[objnum] == 2) { |
| 2974 objnum = (FX_DWORD)pParser->m_CrossRef[objnum]; | 2980 objnum = pParser->m_ObjectInfo[objnum].pos; |
| 2975 } | 2981 } else if (pParser->m_V5Type[objnum] == 1 || |
| 2976 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) { | 2982 pParser->m_V5Type[objnum] == 255) { |
| 2977 offset = pParser->m_CrossRef[objnum]; | 2983 offset = pParser->m_ObjectInfo[objnum].pos; |
| 2978 if (offset == 0) { | 2984 if (offset == 0) { |
| 2979 return 0; | 2985 return 0; |
| 2980 } | 2986 } |
| 2981 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), | 2987 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), |
| 2982 pParser->m_SortedOffset.GetSize(), | 2988 pParser->m_SortedOffset.GetSize(), |
| 2983 sizeof(FX_FILESIZE), CompareFileSize); | 2989 sizeof(FX_FILESIZE), CompareFileSize); |
| 2984 if (!pResult) { | 2990 if (!pResult) { |
| 2985 return 0; | 2991 return 0; |
| 2986 } | 2992 } |
| 2987 if ((FX_FILESIZE*)pResult - | 2993 if ((FX_FILESIZE*)pResult - |
| (...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4984 if (!m_pLinearizedDict) | 4990 if (!m_pLinearizedDict) |
| 4985 return -1; | 4991 return -1; |
| 4986 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4992 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
| 4987 if (!pRange) | 4993 if (!pRange) |
| 4988 return -1; | 4994 return -1; |
| 4989 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4995 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 4990 if (!pStreamLen) | 4996 if (!pStreamLen) |
| 4991 return -1; | 4997 return -1; |
| 4992 return pStreamLen->GetInteger(); | 4998 return pStreamLen->GetInteger(); |
| 4993 } | 4999 } |
| OLD | NEW |