| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 CPDF_Parser::CPDF_Parser() { | 105 CPDF_Parser::CPDF_Parser() { |
| 106 m_pDocument = NULL; | 106 m_pDocument = NULL; |
| 107 m_pTrailer = NULL; | 107 m_pTrailer = NULL; |
| 108 m_pEncryptDict = NULL; | 108 m_pEncryptDict = NULL; |
| 109 m_pLinearized = NULL; | 109 m_pLinearized = NULL; |
| 110 m_dwFirstPageNo = 0; | 110 m_dwFirstPageNo = 0; |
| 111 m_dwXrefStartObjNum = 0; | 111 m_dwXrefStartObjNum = 0; |
| 112 m_bOwnFileRead = TRUE; | 112 m_bOwnFileRead = TRUE; |
| 113 m_FileVersion = 0; | 113 m_FileVersion = 0; |
| 114 m_bForceUseSecurityHandler = FALSE; | 114 m_bForceUseSecurityHandler = FALSE; |
| 115 m_dwLastObjnum = 0; |
| 115 } | 116 } |
| 116 CPDF_Parser::~CPDF_Parser() { | 117 CPDF_Parser::~CPDF_Parser() { |
| 117 CloseParser(FALSE); | 118 CloseParser(FALSE); |
| 118 } | 119 } |
| 119 FX_DWORD CPDF_Parser::GetLastObjNum() { | 120 void CPDF_Parser::SetLastObjNum(FX_DWORD num) { |
| 120 FX_DWORD dwSize = m_CrossRef.GetSize(); | 121 m_dwLastObjnum = std::max(m_dwLastObjnum, num); |
| 121 return dwSize ? dwSize - 1 : 0; | 122 } |
| 123 FX_DWORD CPDF_Parser::GetLastObjNum() const { |
| 124 return m_ObjectInfo.empty() ? 0 : m_dwLastObjnum; |
| 125 } |
| 126 FX_DWORD CPDF_Parser::GetSize() const { |
| 127 return m_ObjectInfo.empty() ? 0 : m_dwLastObjnum + 1; |
| 122 } | 128 } |
| 123 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { | 129 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { |
| 124 m_pEncryptDict = pDict; | 130 m_pEncryptDict = pDict; |
| 125 } | 131 } |
| 126 void CPDF_Parser::CloseParser(FX_BOOL bReParse) { | 132 void CPDF_Parser::CloseParser(FX_BOOL bReParse) { |
| 127 m_bVersionUpdated = FALSE; | 133 m_bVersionUpdated = FALSE; |
| 128 if (!bReParse) { | 134 if (!bReParse) { |
| 129 delete m_pDocument; | 135 delete m_pDocument; |
| 130 m_pDocument = NULL; | 136 m_pDocument = NULL; |
| 131 } | 137 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 143 while (pos) { | 149 while (pos) { |
| 144 void* objnum; | 150 void* objnum; |
| 145 CPDF_StreamAcc* pStream; | 151 CPDF_StreamAcc* pStream; |
| 146 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | 152 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); |
| 147 delete pStream; | 153 delete pStream; |
| 148 } | 154 } |
| 149 m_ObjectStreamMap.RemoveAll(); | 155 m_ObjectStreamMap.RemoveAll(); |
| 150 m_ObjCache.clear(); | 156 m_ObjCache.clear(); |
| 151 | 157 |
| 152 m_SortedOffset.RemoveAll(); | 158 m_SortedOffset.RemoveAll(); |
| 153 m_CrossRef.RemoveAll(); | 159 m_ObjectInfo.clear(); |
| 160 m_dwLastObjnum = 0; |
| 154 m_V5Type.RemoveAll(); | 161 m_V5Type.RemoveAll(); |
| 155 m_ObjVersion.RemoveAll(); | 162 m_ObjVersion.RemoveAll(); |
| 156 int32_t iLen = m_Trailers.GetSize(); | 163 int32_t iLen = m_Trailers.GetSize(); |
| 157 for (int32_t i = 0; i < iLen; ++i) { | 164 for (int32_t i = 0; i < iLen; ++i) { |
| 158 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) | 165 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) |
| 159 trailer->Release(); | 166 trailer->Release(); |
| 160 } | 167 } |
| 161 m_Trailers.RemoveAll(); | 168 m_Trailers.RemoveAll(); |
| 162 if (m_pLinearized) { | 169 if (m_pLinearized) { |
| 163 m_pLinearized->Release(); | 170 m_pLinearized->Release(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 331 } |
| 325 return PDFPARSE_ERROR_SUCCESS; | 332 return PDFPARSE_ERROR_SUCCESS; |
| 326 } | 333 } |
| 327 void CPDF_Parser::ReleaseEncryptHandler() { | 334 void CPDF_Parser::ReleaseEncryptHandler() { |
| 328 m_Syntax.m_pCryptoHandler.reset(); | 335 m_Syntax.m_pCryptoHandler.reset(); |
| 329 if (!m_bForceUseSecurityHandler) { | 336 if (!m_bForceUseSecurityHandler) { |
| 330 m_pSecurityHandler.reset(); | 337 m_pSecurityHandler.reset(); |
| 331 } | 338 } |
| 332 } | 339 } |
| 333 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { | 340 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { |
| 334 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 341 if (objnum >= GetSize()) { |
| 335 return 0; | 342 return 0; |
| 336 } | 343 } |
| 337 if (m_V5Type[objnum] == 1) { | 344 if (m_V5Type[objnum] == 1) { |
| 338 return m_CrossRef[objnum]; | 345 return m_ObjectInfo[objnum].pos; |
| 339 } | 346 } |
| 340 if (m_V5Type[objnum] == 2) { | 347 if (m_V5Type[objnum] == 2) { |
| 341 return m_CrossRef[(int32_t)m_CrossRef[objnum]]; | 348 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 349 return m_ObjectInfo[pos].pos; |
| 342 } | 350 } |
| 343 return 0; | 351 return 0; |
| 344 } | 352 } |
| 345 | 353 |
| 346 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { | 354 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { |
| 347 if (!LoadCrossRefV4(xrefpos, 0, TRUE)) { | 355 if (!LoadCrossRefV4(xrefpos, 0, TRUE)) { |
| 348 return FALSE; | 356 return FALSE; |
| 349 } | 357 } |
| 350 m_pTrailer = LoadTrailerV4(); | 358 m_pTrailer = LoadTrailerV4(); |
| 351 if (!m_pTrailer) { | 359 if (!m_pTrailer) { |
| 352 return FALSE; | 360 return FALSE; |
| 353 } | 361 } |
| 354 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 362 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
| 355 if (xrefsize <= 0 || xrefsize > (1 << 20)) { | 363 if (xrefsize <= 0 || xrefsize > (1 << 20)) { |
| 356 return FALSE; | 364 return FALSE; |
| 357 } | 365 } |
| 358 m_CrossRef.SetSize(xrefsize); | 366 m_ObjectInfo[0].pos = 0; |
| 367 SetLastObjNum(static_cast<FX_DWORD>(xrefsize)); |
| 359 m_V5Type.SetSize(xrefsize); | 368 m_V5Type.SetSize(xrefsize); |
| 360 CFX_FileSizeArray CrossRefList, XRefStreamList; | 369 CFX_FileSizeArray CrossRefList, XRefStreamList; |
| 361 CrossRefList.Add(xrefpos); | 370 CrossRefList.Add(xrefpos); |
| 362 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); | 371 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); |
| 363 if (!CheckDirectType(m_pTrailer, "Prev", PDFOBJ_NUMBER)) { | 372 if (!CheckDirectType(m_pTrailer, "Prev", PDFOBJ_NUMBER)) { |
| 364 return FALSE; | 373 return FALSE; |
| 365 } | 374 } |
| 366 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, "Prev"); | 375 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, "Prev"); |
| 367 if (newxrefpos == xrefpos) { | 376 if (newxrefpos == xrefpos) { |
| 368 return FALSE; | 377 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) { | 460 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { |
| 452 return FALSE; | 461 return FALSE; |
| 453 } | 462 } |
| 454 if (!m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), dwReadSize)) { | 463 if (!m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), dwReadSize)) { |
| 455 return FALSE; | 464 return FALSE; |
| 456 } | 465 } |
| 457 for (int32_t i = 0; i < block_size; i++) { | 466 for (int32_t i = 0; i < block_size; i++) { |
| 458 FX_DWORD objnum = start_objnum + block * 1024 + i; | 467 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 459 char* pEntry = pBuf + i * recordsize; | 468 char* pEntry = pBuf + i * recordsize; |
| 460 if (pEntry[17] == 'f') { | 469 if (pEntry[17] == 'f') { |
| 461 m_CrossRef.SetAtGrow(objnum, 0); | 470 m_ObjectInfo[objnum].pos = 0; |
| 471 SetLastObjNum(objnum); |
| 462 m_V5Type.SetAtGrow(objnum, 0); | 472 m_V5Type.SetAtGrow(objnum, 0); |
| 463 } else { | 473 } else { |
| 464 int32_t offset = FXSYS_atoi(pEntry); | 474 int32_t offset = FXSYS_atoi(pEntry); |
| 465 if (offset == 0) { | 475 if (offset == 0) { |
| 466 for (int32_t c = 0; c < 10; c++) { | 476 for (int32_t c = 0; c < 10; c++) { |
| 467 if (!std::isdigit(pEntry[c])) | 477 if (!std::isdigit(pEntry[c])) |
| 468 return FALSE; | 478 return FALSE; |
| 469 } | 479 } |
| 470 } | 480 } |
| 471 m_CrossRef.SetAtGrow(objnum, offset); | 481 m_ObjectInfo[objnum].pos = offset; |
| 482 SetLastObjNum(objnum); |
| 472 int32_t version = FXSYS_atoi(pEntry + 11); | 483 int32_t version = FXSYS_atoi(pEntry + 11); |
| 473 if (version >= 1) { | 484 if (version >= 1) { |
| 474 m_bVersionUpdated = TRUE; | 485 m_bVersionUpdated = TRUE; |
| 475 } | 486 } |
| 476 m_ObjVersion.SetAtGrow(objnum, version); | 487 m_ObjVersion.SetAtGrow(objnum, version); |
| 477 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 488 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen) { |
| 478 void* pResult = FXSYS_bsearch( | 489 void* pResult = FXSYS_bsearch( |
| 479 &m_CrossRef[objnum], m_SortedOffset.GetData(), | 490 &m_ObjectInfo[objnum].pos, m_SortedOffset.GetData(), |
| 480 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); | 491 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); |
| 481 if (!pResult) { | 492 if (!pResult) { |
| 482 m_SortedOffset.Add(m_CrossRef[objnum]); | 493 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); |
| 483 } | 494 } |
| 484 } | 495 } |
| 485 m_V5Type.SetAtGrow(objnum, 1); | 496 m_V5Type.SetAtGrow(objnum, 1); |
| 486 } | 497 } |
| 487 } | 498 } |
| 488 } | 499 } |
| 489 m_Syntax.RestorePos(SavedPos + count * recordsize); | 500 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| 490 return TRUE; | 501 return TRUE; |
| 491 } | 502 } |
| 492 | 503 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 pBuf[1024 * recordsize] = '\0'; | 545 pBuf[1024 * recordsize] = '\0'; |
| 535 int32_t nBlocks = count / 1024 + 1; | 546 int32_t nBlocks = count / 1024 + 1; |
| 536 for (int32_t block = 0; block < nBlocks; block++) { | 547 for (int32_t block = 0; block < nBlocks; block++) { |
| 537 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 548 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
| 538 m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), | 549 m_Syntax.ReadBlock(reinterpret_cast<uint8_t*>(pBuf), |
| 539 block_size * recordsize); | 550 block_size * recordsize); |
| 540 for (int32_t i = 0; i < block_size; i++) { | 551 for (int32_t i = 0; i < block_size; i++) { |
| 541 FX_DWORD objnum = start_objnum + block * 1024 + i; | 552 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 542 char* pEntry = pBuf + i * recordsize; | 553 char* pEntry = pBuf + i * recordsize; |
| 543 if (pEntry[17] == 'f') { | 554 if (pEntry[17] == 'f') { |
| 544 m_CrossRef.SetAtGrow(objnum, 0); | 555 m_ObjectInfo[objnum].pos = 0; |
| 556 SetLastObjNum(objnum); |
| 545 m_V5Type.SetAtGrow(objnum, 0); | 557 m_V5Type.SetAtGrow(objnum, 0); |
| 546 } else { | 558 } else { |
| 547 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 559 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
| 548 if (offset == 0) { | 560 if (offset == 0) { |
| 549 for (int32_t c = 0; c < 10; c++) { | 561 for (int32_t c = 0; c < 10; c++) { |
| 550 if (!std::isdigit(pEntry[c])) | 562 if (!std::isdigit(pEntry[c])) |
| 551 return false; | 563 return false; |
| 552 } | 564 } |
| 553 } | 565 } |
| 554 m_CrossRef.SetAtGrow(objnum, offset); | 566 m_ObjectInfo[objnum].pos = offset; |
| 567 SetLastObjNum(objnum); |
| 555 int32_t version = FXSYS_atoi(pEntry + 11); | 568 int32_t version = FXSYS_atoi(pEntry + 11); |
| 556 if (version >= 1) { | 569 if (version >= 1) { |
| 557 m_bVersionUpdated = TRUE; | 570 m_bVersionUpdated = TRUE; |
| 558 } | 571 } |
| 559 m_ObjVersion.SetAtGrow(objnum, version); | 572 m_ObjVersion.SetAtGrow(objnum, version); |
| 560 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && | 573 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen && |
| 561 !FindPosInOffsets(m_CrossRef[objnum])) { | 574 !FindPosInOffsets(m_ObjectInfo[objnum].pos)) { |
| 562 m_SortedOffset.Add(m_CrossRef[objnum]); | 575 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); |
| 563 } | 576 } |
| 564 m_V5Type.SetAtGrow(objnum, 1); | 577 m_V5Type.SetAtGrow(objnum, 1); |
| 565 } | 578 } |
| 566 } | 579 } |
| 567 } | 580 } |
| 568 } | 581 } |
| 569 m_Syntax.RestorePos(SavedPos + count * recordsize); | 582 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| 570 } | 583 } |
| 571 return !streampos || LoadCrossRefV5(&streampos, FALSE); | 584 return !streampos || LoadCrossRefV5(&streampos, FALSE); |
| 572 } | 585 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 585 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { | 598 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { |
| 586 return FALSE; | 599 return FALSE; |
| 587 } | 600 } |
| 588 } | 601 } |
| 589 m_ObjectStreamMap.InitHashTable(101, FALSE); | 602 m_ObjectStreamMap.InitHashTable(101, FALSE); |
| 590 m_bXRefStream = TRUE; | 603 m_bXRefStream = TRUE; |
| 591 return TRUE; | 604 return TRUE; |
| 592 } | 605 } |
| 593 | 606 |
| 594 FX_BOOL CPDF_Parser::RebuildCrossRef() { | 607 FX_BOOL CPDF_Parser::RebuildCrossRef() { |
| 595 m_CrossRef.RemoveAll(); | 608 m_ObjectInfo.clear(); |
| 609 m_dwLastObjnum = 0; |
| 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 (GetSize() > objnum && m_ObjectInfo[objnum].pos) { |
| 798 m_CrossRef[objnum]) { | |
| 799 if (pObject) { | 812 if (pObject) { |
| 800 FX_DWORD oldgen = m_ObjVersion.GetAt(objnum); | 813 FX_DWORD oldgen = m_ObjVersion.GetAt(objnum); |
| 801 m_CrossRef[objnum] = obj_pos; | 814 m_ObjectInfo[objnum].pos = obj_pos; |
| 802 m_ObjVersion.SetAt(objnum, (int16_t)gennum); | 815 m_ObjVersion.SetAt(objnum, (int16_t)gennum); |
| 803 if (oldgen != gennum) { | 816 if (oldgen != gennum) { |
| 804 m_bVersionUpdated = TRUE; | 817 m_bVersionUpdated = TRUE; |
| 805 } | 818 } |
| 806 } | 819 } |
| 807 } else { | 820 } else { |
| 808 m_CrossRef.SetAtGrow(objnum, obj_pos); | 821 m_ObjectInfo[objnum].pos = obj_pos; |
| 822 SetLastObjNum(objnum); |
| 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 && GetSize() > 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 && GetSize() > 0; |
| 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; |
| 1012 SetLastObjNum(static_cast<FX_DWORD>(size)); |
| 1000 if (m_V5Type.SetSize(size)) { | 1013 if (m_V5Type.SetSize(size)) { |
| 1001 FXSYS_memset(m_V5Type.GetData(), 0, size); | 1014 FXSYS_memset(m_V5Type.GetData(), 0, size); |
| 1002 } | 1015 } |
| 1003 } else { | 1016 } else { |
| 1004 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); | 1017 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); |
| 1005 } | 1018 } |
| 1006 std::vector<std::pair<int32_t, int32_t> > arrIndex; | 1019 std::vector<std::pair<int32_t, int32_t> > arrIndex; |
| 1007 CPDF_Array* pArray = pStream->GetDict()->GetArray("Index"); | 1020 CPDF_Array* pArray = pStream->GetDict()->GetArray("Index"); |
| 1008 if (pArray) { | 1021 if (pArray) { |
| 1009 FX_DWORD nPairSize = pArray->GetCount() / 2; | 1022 FX_DWORD nPairSize = pArray->GetCount() / 2; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 } | 1082 } |
| 1070 for (FX_DWORD j = 0; j < count; j++) { | 1083 for (FX_DWORD j = 0; j < count; j++) { |
| 1071 int32_t type = 1; | 1084 int32_t type = 1; |
| 1072 const uint8_t* entrystart = segstart + j * totalWidth; | 1085 const uint8_t* entrystart = segstart + j * totalWidth; |
| 1073 if (WidthArray[0]) { | 1086 if (WidthArray[0]) { |
| 1074 type = GetVarInt(entrystart, WidthArray[0]); | 1087 type = GetVarInt(entrystart, WidthArray[0]); |
| 1075 } | 1088 } |
| 1076 if (m_V5Type[startnum + j] == 255) { | 1089 if (m_V5Type[startnum + j] == 255) { |
| 1077 FX_FILESIZE offset = | 1090 FX_FILESIZE offset = |
| 1078 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1091 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
| 1079 m_CrossRef[startnum + j] = offset; | 1092 m_ObjectInfo[startnum + j].pos = offset; |
| 1080 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1093 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
| 1081 m_SortedOffset.GetSize(), | 1094 m_SortedOffset.GetSize(), |
| 1082 sizeof(FX_FILESIZE), CompareFileSize); | 1095 sizeof(FX_FILESIZE), CompareFileSize); |
| 1083 if (!pResult) { | 1096 if (!pResult) { |
| 1084 m_SortedOffset.Add(offset); | 1097 m_SortedOffset.Add(offset); |
| 1085 } | 1098 } |
| 1086 continue; | 1099 continue; |
| 1087 } | 1100 } |
| 1088 if (m_V5Type[startnum + j]) { | 1101 if (m_V5Type[startnum + j]) { |
| 1089 continue; | 1102 continue; |
| 1090 } | 1103 } |
| 1091 m_V5Type[startnum + j] = type; | 1104 m_V5Type[startnum + j] = type; |
| 1092 if (type == 0) { | 1105 if (type == 0) { |
| 1093 m_CrossRef[startnum + j] = 0; | 1106 m_ObjectInfo[startnum + j].pos = 0; |
| 1094 } else { | 1107 } else { |
| 1095 FX_FILESIZE offset = | 1108 FX_FILESIZE offset = |
| 1096 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1109 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
| 1097 m_CrossRef[startnum + j] = offset; | 1110 m_ObjectInfo[startnum + j].pos = offset; |
| 1098 if (type == 1) { | 1111 if (type == 1) { |
| 1099 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1112 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
| 1100 m_SortedOffset.GetSize(), | 1113 m_SortedOffset.GetSize(), |
| 1101 sizeof(FX_FILESIZE), CompareFileSize); | 1114 sizeof(FX_FILESIZE), CompareFileSize); |
| 1102 if (!pResult) { | 1115 if (!pResult) { |
| 1103 m_SortedOffset.Add(offset); | 1116 m_SortedOffset.Add(offset); |
| 1104 } | 1117 } |
| 1105 } else { | 1118 } else { |
| 1106 if (offset < 0 || offset >= m_V5Type.GetSize()) { | 1119 if (offset < 0 || offset >= m_V5Type.GetSize()) { |
| 1107 pStream->Release(); | 1120 pStream->Release(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1132 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); | 1145 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); |
| 1133 return pRef ? pRef->GetRefObjNum() : 0; | 1146 return pRef ? pRef->GetRefObjNum() : 0; |
| 1134 } | 1147 } |
| 1135 FX_DWORD CPDF_Parser::GetInfoObjNum() { | 1148 FX_DWORD CPDF_Parser::GetInfoObjNum() { |
| 1136 CPDF_Reference* pRef = | 1149 CPDF_Reference* pRef = |
| 1137 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); | 1150 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); |
| 1138 return pRef ? pRef->GetRefObjNum() : 0; | 1151 return pRef ? pRef->GetRefObjNum() : 0; |
| 1139 } | 1152 } |
| 1140 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { | 1153 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { |
| 1141 bForm = FALSE; | 1154 bForm = FALSE; |
| 1142 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1155 if (objnum >= GetSize()) { |
| 1143 return TRUE; | 1156 return TRUE; |
| 1144 } | 1157 } |
| 1145 if (m_V5Type[objnum] == 0) { | 1158 if (m_V5Type[objnum] == 0) { |
| 1146 return TRUE; | 1159 return TRUE; |
| 1147 } | 1160 } |
| 1148 if (m_V5Type[objnum] == 2) { | 1161 if (m_V5Type[objnum] == 2) { |
| 1149 return TRUE; | 1162 return TRUE; |
| 1150 } | 1163 } |
| 1151 FX_FILESIZE pos = m_CrossRef[objnum]; | 1164 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1152 void* pResult = | 1165 void* pResult = |
| 1153 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1166 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 1154 sizeof(FX_FILESIZE), CompareFileSize); | 1167 sizeof(FX_FILESIZE), CompareFileSize); |
| 1155 if (!pResult) { | 1168 if (!pResult) { |
| 1156 return TRUE; | 1169 return TRUE; |
| 1157 } | 1170 } |
| 1158 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1171 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == |
| 1159 m_SortedOffset.GetSize() - 1) { | 1172 m_SortedOffset.GetSize() - 1) { |
| 1160 return FALSE; | 1173 return FALSE; |
| 1161 } | 1174 } |
| 1162 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; | 1175 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; |
| 1163 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1176 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1164 m_Syntax.RestorePos(pos); | 1177 m_Syntax.RestorePos(pos); |
| 1165 const char kFormStream[] = "/Form\0stream"; | 1178 const char kFormStream[] = "/Form\0stream"; |
| 1166 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); | 1179 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); |
| 1167 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; | 1180 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; |
| 1168 m_Syntax.RestorePos(SavedPos); | 1181 m_Syntax.RestorePos(SavedPos); |
| 1169 return TRUE; | 1182 return TRUE; |
| 1170 } | 1183 } |
| 1171 | 1184 |
| 1172 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, | 1185 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, |
| 1173 FX_DWORD objnum, | 1186 FX_DWORD objnum, |
| 1174 PARSE_CONTEXT* pContext) { | 1187 PARSE_CONTEXT* pContext) { |
| 1175 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) | 1188 if (objnum >= GetSize()) |
| 1176 return nullptr; | 1189 return nullptr; |
| 1177 | 1190 |
| 1178 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1191 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
| 1179 FX_FILESIZE pos = m_CrossRef[objnum]; | 1192 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1180 if (pos <= 0) | 1193 if (pos <= 0) |
| 1181 return nullptr; | 1194 return nullptr; |
| 1182 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); | 1195 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); |
| 1183 } | 1196 } |
| 1184 if (m_V5Type[objnum] != 2) | 1197 if (m_V5Type[objnum] != 2) |
| 1185 return nullptr; | 1198 return nullptr; |
| 1186 | 1199 |
| 1187 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); | 1200 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
| 1188 if (!pObjStream) | 1201 if (!pObjStream) |
| 1189 return nullptr; | 1202 return nullptr; |
| 1190 | 1203 |
| 1191 ScopedFileStream file(FX_CreateMemoryStream( | 1204 ScopedFileStream file(FX_CreateMemoryStream( |
| 1192 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1205 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); |
| 1193 CPDF_SyntaxParser syntax; | 1206 CPDF_SyntaxParser syntax; |
| 1194 syntax.InitParser(file.get(), 0); | 1207 syntax.InitParser(file.get(), 0); |
| 1195 const int32_t offset = GetStreamFirst(pObjStream); | 1208 const int32_t offset = GetStreamFirst(pObjStream); |
| 1196 | 1209 |
| 1197 // Read object numbers from |pObjStream| into a cache. | 1210 // Read object numbers from |pObjStream| into a cache. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1220 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); | 1233 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); |
| 1221 if (!pStream) | 1234 if (!pStream) |
| 1222 return nullptr; | 1235 return nullptr; |
| 1223 | 1236 |
| 1224 pStreamAcc = new CPDF_StreamAcc; | 1237 pStreamAcc = new CPDF_StreamAcc; |
| 1225 pStreamAcc->LoadAllData(pStream); | 1238 pStreamAcc->LoadAllData(pStream); |
| 1226 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); | 1239 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); |
| 1227 return pStreamAcc; | 1240 return pStreamAcc; |
| 1228 } | 1241 } |
| 1229 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { | 1242 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { |
| 1230 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1243 if (objnum >= GetSize()) { |
| 1231 return 0; | 1244 return 0; |
| 1232 } | 1245 } |
| 1233 if (m_V5Type[objnum] == 2) { | 1246 if (m_V5Type[objnum] == 2) { |
| 1234 objnum = (FX_DWORD)m_CrossRef[objnum]; | 1247 objnum = m_ObjectInfo[objnum].pos; |
| 1235 } | 1248 } |
| 1236 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1249 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
| 1237 FX_FILESIZE offset = m_CrossRef[objnum]; | 1250 FX_FILESIZE offset = m_ObjectInfo[objnum].pos; |
| 1238 if (offset == 0) { | 1251 if (offset == 0) { |
| 1239 return 0; | 1252 return 0; |
| 1240 } | 1253 } |
| 1241 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1254 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), |
| 1242 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 1255 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
| 1243 CompareFileSize); | 1256 CompareFileSize); |
| 1244 if (!pResult) { | 1257 if (!pResult) { |
| 1245 return 0; | 1258 return 0; |
| 1246 } | 1259 } |
| 1247 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1260 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == |
| 1248 m_SortedOffset.GetSize() - 1) { | 1261 m_SortedOffset.GetSize() - 1) { |
| 1249 return 0; | 1262 return 0; |
| 1250 } | 1263 } |
| 1251 return ((FX_FILESIZE*)pResult)[1] - offset; | 1264 return ((FX_FILESIZE*)pResult)[1] - offset; |
| 1252 } | 1265 } |
| 1253 return 0; | 1266 return 0; |
| 1254 } | 1267 } |
| 1255 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, | 1268 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, |
| 1256 uint8_t*& pBuffer, | 1269 uint8_t*& pBuffer, |
| 1257 FX_DWORD& size) { | 1270 FX_DWORD& size) { |
| 1258 pBuffer = NULL; | 1271 pBuffer = NULL; |
| 1259 size = 0; | 1272 size = 0; |
| 1260 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1273 if (objnum >= GetSize()) { |
| 1261 return; | 1274 return; |
| 1262 } | 1275 } |
| 1263 if (m_V5Type[objnum] == 2) { | 1276 if (m_V5Type[objnum] == 2) { |
| 1264 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); | 1277 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
| 1265 if (!pObjStream) | 1278 if (!pObjStream) |
| 1266 return; | 1279 return; |
| 1267 | 1280 |
| 1268 int32_t offset = GetStreamFirst(pObjStream); | 1281 int32_t offset = GetStreamFirst(pObjStream); |
| 1269 const uint8_t* pData = pObjStream->GetData(); | 1282 const uint8_t* pData = pObjStream->GetData(); |
| 1270 FX_DWORD totalsize = pObjStream->GetSize(); | 1283 FX_DWORD totalsize = pObjStream->GetSize(); |
| 1271 ScopedFileStream file( | 1284 ScopedFileStream file( |
| 1272 FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, FALSE)); | 1285 FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, FALSE)); |
| 1273 CPDF_SyntaxParser syntax; | 1286 CPDF_SyntaxParser syntax; |
| 1274 syntax.InitParser(file.get(), 0); | 1287 syntax.InitParser(file.get(), 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1288 pBuffer = FX_Alloc(uint8_t, size); | 1301 pBuffer = FX_Alloc(uint8_t, size); |
| 1289 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); | 1302 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); |
| 1290 return; | 1303 return; |
| 1291 } | 1304 } |
| 1292 return; | 1305 return; |
| 1293 } | 1306 } |
| 1294 | 1307 |
| 1295 if (m_V5Type[objnum] != 1) | 1308 if (m_V5Type[objnum] != 1) |
| 1296 return; | 1309 return; |
| 1297 | 1310 |
| 1298 FX_FILESIZE pos = m_CrossRef[objnum]; | 1311 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1299 if (pos == 0) { | 1312 if (pos == 0) { |
| 1300 return; | 1313 return; |
| 1301 } | 1314 } |
| 1302 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1315 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1303 m_Syntax.RestorePos(pos); | 1316 m_Syntax.RestorePos(pos); |
| 1304 FX_BOOL bIsNumber; | 1317 FX_BOOL bIsNumber; |
| 1305 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1318 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
| 1306 if (!bIsNumber) { | 1319 if (!bIsNumber) { |
| 1307 m_Syntax.RestorePos(SavedPos); | 1320 m_Syntax.RestorePos(SavedPos); |
| 1308 return; | 1321 return; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 bXRefRebuilt = TRUE; | 1575 bXRefRebuilt = TRUE; |
| 1563 m_LastXRefOffset = 0; | 1576 m_LastXRefOffset = 0; |
| 1564 } | 1577 } |
| 1565 if (bLoadV4) { | 1578 if (bLoadV4) { |
| 1566 m_pTrailer = LoadTrailerV4(); | 1579 m_pTrailer = LoadTrailerV4(); |
| 1567 if (!m_pTrailer) { | 1580 if (!m_pTrailer) { |
| 1568 return FALSE; | 1581 return FALSE; |
| 1569 } | 1582 } |
| 1570 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 1583 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
| 1571 if (xrefsize > 0) { | 1584 if (xrefsize > 0) { |
| 1572 m_CrossRef.SetSize(xrefsize); | 1585 m_ObjectInfo[0].pos = 0; |
| 1586 SetLastObjNum(static_cast<FX_DWORD>(xrefsize)); |
| 1573 m_V5Type.SetSize(xrefsize); | 1587 m_V5Type.SetSize(xrefsize); |
| 1574 } | 1588 } |
| 1575 } | 1589 } |
| 1576 FX_DWORD dwRet = SetEncryptHandler(); | 1590 FX_DWORD dwRet = SetEncryptHandler(); |
| 1577 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1591 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
| 1578 return dwRet; | 1592 return dwRet; |
| 1579 } | 1593 } |
| 1580 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); | 1594 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); |
| 1581 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { | 1595 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { |
| 1582 if (bXRefRebuilt) { | 1596 if (bXRefRebuilt) { |
| (...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2960 } | 2974 } |
| 2961 } | 2975 } |
| 2962 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 2976 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
| 2963 m_pDocument = pDoc; | 2977 m_pDocument = pDoc; |
| 2964 } | 2978 } |
| 2965 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { | 2979 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { |
| 2966 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); | 2980 CPDF_Parser* pParser = (CPDF_Parser*)(m_pDocument->GetParser()); |
| 2967 if (!pParser) { | 2981 if (!pParser) { |
| 2968 return 0; | 2982 return 0; |
| 2969 } | 2983 } |
| 2970 if (objnum >= (FX_DWORD)pParser->m_CrossRef.GetSize()) { | 2984 if (objnum >= pParser->GetSize()) { |
| 2971 return 0; | 2985 return 0; |
| 2972 } | 2986 } |
| 2973 if (pParser->m_V5Type[objnum] == 2) { | 2987 if (pParser->m_V5Type[objnum] == 2) { |
| 2974 objnum = (FX_DWORD)pParser->m_CrossRef[objnum]; | 2988 objnum = pParser->m_ObjectInfo[objnum].pos; |
| 2975 } | 2989 } |
| 2976 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) { | 2990 if (pParser->m_V5Type[objnum] == 1 || pParser->m_V5Type[objnum] == 255) { |
| 2977 offset = pParser->m_CrossRef[objnum]; | 2991 offset = pParser->m_ObjectInfo[objnum].pos; |
| 2978 if (offset == 0) { | 2992 if (offset == 0) { |
| 2979 return 0; | 2993 return 0; |
| 2980 } | 2994 } |
| 2981 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), | 2995 void* pResult = FXSYS_bsearch(&offset, pParser->m_SortedOffset.GetData(), |
| 2982 pParser->m_SortedOffset.GetSize(), | 2996 pParser->m_SortedOffset.GetSize(), |
| 2983 sizeof(FX_FILESIZE), CompareFileSize); | 2997 sizeof(FX_FILESIZE), CompareFileSize); |
| 2984 if (!pResult) { | 2998 if (!pResult) { |
| 2985 return 0; | 2999 return 0; |
| 2986 } | 3000 } |
| 2987 if ((FX_FILESIZE*)pResult - | 3001 if ((FX_FILESIZE*)pResult - |
| (...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4981 if (!m_pLinearizedDict) | 4995 if (!m_pLinearizedDict) |
| 4982 return -1; | 4996 return -1; |
| 4983 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4997 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
| 4984 if (!pRange) | 4998 if (!pRange) |
| 4985 return -1; | 4999 return -1; |
| 4986 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 5000 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 4987 if (!pStreamLen) | 5001 if (!pStreamLen) |
| 4988 return -1; | 5002 return -1; |
| 4989 return pStreamLen->GetInteger(); | 5003 return pStreamLen->GetInteger(); |
| 4990 } | 5004 } |
| OLD | NEW |