| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 switch (type) { | 144 switch (type) { |
| 145 case CPDF_Object::ARRAY: { | 145 case CPDF_Object::ARRAY: { |
| 146 CPDF_Array* pArray = pObj->AsArray(); | 146 CPDF_Array* pArray = pObj->AsArray(); |
| 147 for (size_t k = 0; k < pArray->GetCount(); ++k) | 147 for (size_t k = 0; k < pArray->GetCount(); ++k) |
| 148 new_obj_array.Add(pArray->GetObjectAt(k)); | 148 new_obj_array.Add(pArray->GetObjectAt(k)); |
| 149 } break; | 149 } break; |
| 150 case CPDF_Object::STREAM: | 150 case CPDF_Object::STREAM: |
| 151 pObj = pObj->GetDict(); | 151 pObj = pObj->GetDict(); |
| 152 case CPDF_Object::DICTIONARY: { | 152 case CPDF_Object::DICTIONARY: { |
| 153 CPDF_Dictionary* pDict = pObj->GetDict(); | 153 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 154 if (pDict && pDict->GetStringBy("Type") == "Page" && !bParsePage) | 154 if (pDict && pDict->GetStringFor("Type") == "Page" && !bParsePage) |
| 155 continue; | 155 continue; |
| 156 | 156 |
| 157 for (const auto& it : *pDict) { | 157 for (const auto& it : *pDict) { |
| 158 const CFX_ByteString& key = it.first; | 158 const CFX_ByteString& key = it.first; |
| 159 CPDF_Object* value = it.second; | 159 CPDF_Object* value = it.second; |
| 160 if (key != "Parent") | 160 if (key != "Parent") |
| 161 new_obj_array.Add(value); | 161 new_obj_array.Add(value); |
| 162 } | 162 } |
| 163 } break; | 163 } break; |
| 164 case CPDF_Object::REFERENCE: { | 164 case CPDF_Object::REFERENCE: { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 434 } |
| 435 return FALSE; | 435 return FALSE; |
| 436 } | 436 } |
| 437 | 437 |
| 438 CPDF_Dictionary* pDict = m_pRoot->GetDict(); | 438 CPDF_Dictionary* pDict = m_pRoot->GetDict(); |
| 439 if (!pDict) { | 439 if (!pDict) { |
| 440 m_docStatus = PDF_DATAAVAIL_ERROR; | 440 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 441 return FALSE; | 441 return FALSE; |
| 442 } | 442 } |
| 443 | 443 |
| 444 CPDF_Reference* pRef = ToReference(pDict->GetObjectBy("Pages")); | 444 CPDF_Reference* pRef = ToReference(pDict->GetObjectFor("Pages")); |
| 445 if (!pRef) { | 445 if (!pRef) { |
| 446 m_docStatus = PDF_DATAAVAIL_ERROR; | 446 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 447 return FALSE; | 447 return FALSE; |
| 448 } | 448 } |
| 449 | 449 |
| 450 m_PagesObjNum = pRef->GetRefObjNum(); | 450 m_PagesObjNum = pRef->GetRefObjNum(); |
| 451 CPDF_Reference* pAcroFormRef = | 451 CPDF_Reference* pAcroFormRef = |
| 452 ToReference(m_pRoot->GetDict()->GetObjectBy("AcroForm")); | 452 ToReference(m_pRoot->GetDict()->GetObjectFor("AcroForm")); |
| 453 if (pAcroFormRef) { | 453 if (pAcroFormRef) { |
| 454 m_bHaveAcroForm = TRUE; | 454 m_bHaveAcroForm = TRUE; |
| 455 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); | 455 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 if (m_dwInfoObjNum) { | 458 if (m_dwInfoObjNum) { |
| 459 m_docStatus = PDF_DATAAVAIL_INFO; | 459 m_docStatus = PDF_DATAAVAIL_INFO; |
| 460 } else { | 460 } else { |
| 461 m_docStatus = | 461 m_docStatus = |
| 462 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; | 462 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; |
| 463 } | 463 } |
| 464 return TRUE; | 464 return TRUE; |
| 465 } | 465 } |
| 466 | 466 |
| 467 FX_BOOL CPDF_DataAvail::PreparePageItem() { | 467 FX_BOOL CPDF_DataAvail::PreparePageItem() { |
| 468 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 468 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 469 CPDF_Reference* pRef = | 469 CPDF_Reference* pRef = |
| 470 ToReference(pRoot ? pRoot->GetObjectBy("Pages") : nullptr); | 470 ToReference(pRoot ? pRoot->GetObjectFor("Pages") : nullptr); |
| 471 if (!pRef) { | 471 if (!pRef) { |
| 472 m_docStatus = PDF_DATAAVAIL_ERROR; | 472 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 473 return FALSE; | 473 return FALSE; |
| 474 } | 474 } |
| 475 | 475 |
| 476 m_PagesObjNum = pRef->GetRefObjNum(); | 476 m_PagesObjNum = pRef->GetRefObjNum(); |
| 477 m_pCurrentParser = m_pDocument->GetParser(); | 477 m_pCurrentParser = m_pDocument->GetParser(); |
| 478 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 478 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
| 479 return TRUE; | 479 return TRUE; |
| 480 } | 480 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 506 if (CPDF_Reference* pRef = ToReference(pArrayObj)) | 506 if (CPDF_Reference* pRef = ToReference(pArrayObj)) |
| 507 UnavailObjList.Add(pRef->GetRefObjNum()); | 507 UnavailObjList.Add(pRef->GetRefObjNum()); |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 | 510 |
| 511 if (!pObj->IsDictionary()) { | 511 if (!pObj->IsDictionary()) { |
| 512 pObj->Release(); | 512 pObj->Release(); |
| 513 continue; | 513 continue; |
| 514 } | 514 } |
| 515 | 515 |
| 516 CFX_ByteString type = pObj->GetDict()->GetStringBy("Type"); | 516 CFX_ByteString type = pObj->GetDict()->GetStringFor("Type"); |
| 517 if (type == "Pages") { | 517 if (type == "Pages") { |
| 518 m_PagesArray.Add(pObj); | 518 m_PagesArray.Add(pObj); |
| 519 continue; | 519 continue; |
| 520 } | 520 } |
| 521 pObj->Release(); | 521 pObj->Release(); |
| 522 } | 522 } |
| 523 | 523 |
| 524 m_PageObjList.RemoveAll(); | 524 m_PageObjList.RemoveAll(); |
| 525 if (UnavailObjList.GetSize()) { | 525 if (UnavailObjList.GetSize()) { |
| 526 m_PageObjList.Append(UnavailObjList); | 526 m_PageObjList.Append(UnavailObjList); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 553 return TRUE; | 553 return TRUE; |
| 554 } | 554 } |
| 555 | 555 |
| 556 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { | 556 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { |
| 557 if (!pParser) { | 557 if (!pParser) { |
| 558 m_docStatus = PDF_DATAAVAIL_ERROR; | 558 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 559 return FALSE; | 559 return FALSE; |
| 560 } | 560 } |
| 561 | 561 |
| 562 CPDF_Dictionary* pDict = pPages->GetDict(); | 562 CPDF_Dictionary* pDict = pPages->GetDict(); |
| 563 CPDF_Object* pKids = pDict ? pDict->GetObjectBy("Kids") : nullptr; | 563 CPDF_Object* pKids = pDict ? pDict->GetObjectFor("Kids") : nullptr; |
| 564 if (!pKids) | 564 if (!pKids) |
| 565 return TRUE; | 565 return TRUE; |
| 566 | 566 |
| 567 switch (pKids->GetType()) { | 567 switch (pKids->GetType()) { |
| 568 case CPDF_Object::REFERENCE: | 568 case CPDF_Object::REFERENCE: |
| 569 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); | 569 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); |
| 570 break; | 570 break; |
| 571 case CPDF_Object::ARRAY: { | 571 case CPDF_Object::ARRAY: { |
| 572 CPDF_Array* pKidsArray = pKids->AsArray(); | 572 CPDF_Array* pKidsArray = pKids->AsArray(); |
| 573 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { | 573 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 } | 626 } |
| 627 return TRUE; | 627 return TRUE; |
| 628 } | 628 } |
| 629 | 629 |
| 630 pHints->AddSegment(0, kReqSize); | 630 pHints->AddSegment(0, kReqSize); |
| 631 return FALSE; | 631 return FALSE; |
| 632 } | 632 } |
| 633 | 633 |
| 634 FX_BOOL CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { | 634 FX_BOOL CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { |
| 635 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 635 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 636 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectBy("E") : nullptr; | 636 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr; |
| 637 if (!pEndOffSet) { | 637 if (!pEndOffSet) { |
| 638 m_docStatus = PDF_DATAAVAIL_ERROR; | 638 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 639 return FALSE; | 639 return FALSE; |
| 640 } | 640 } |
| 641 | 641 |
| 642 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectBy("T") : nullptr; | 642 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr; |
| 643 if (!pXRefOffset) { | 643 if (!pXRefOffset) { |
| 644 m_docStatus = PDF_DATAAVAIL_ERROR; | 644 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 645 return FALSE; | 645 return FALSE; |
| 646 } | 646 } |
| 647 | 647 |
| 648 CPDF_Object* pFileLen = pDict ? pDict->GetObjectBy("L") : nullptr; | 648 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr; |
| 649 if (!pFileLen) { | 649 if (!pFileLen) { |
| 650 m_docStatus = PDF_DATAAVAIL_ERROR; | 650 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 651 return FALSE; | 651 return FALSE; |
| 652 } | 652 } |
| 653 | 653 |
| 654 FX_BOOL bNeedDownLoad = FALSE; | 654 FX_BOOL bNeedDownLoad = FALSE; |
| 655 if (pEndOffSet->IsNumber()) { | 655 if (pEndOffSet->IsNumber()) { |
| 656 uint32_t dwEnd = pEndOffSet->GetInteger(); | 656 uint32_t dwEnd = pEndOffSet->GetInteger(); |
| 657 dwEnd += 512; | 657 dwEnd += 512; |
| 658 if ((FX_FILESIZE)dwEnd > m_dwFileLen) | 658 if ((FX_FILESIZE)dwEnd > m_dwFileLen) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 721 } |
| 722 | 722 |
| 723 FX_BOOL CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { | 723 FX_BOOL CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { |
| 724 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 724 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 725 if (!pDict) { | 725 if (!pDict) { |
| 726 m_docStatus = PDF_DATAAVAIL_ERROR; | 726 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 727 return FALSE; | 727 return FALSE; |
| 728 } | 728 } |
| 729 | 729 |
| 730 // The actual value is not required here, but validate its existence and type. | 730 // The actual value is not required here, but validate its existence and type. |
| 731 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectBy("O")); | 731 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O")); |
| 732 if (!pFirstPage || !pFirstPage->IsInteger()) { | 732 if (!pFirstPage || !pFirstPage->IsInteger()) { |
| 733 m_docStatus = PDF_DATAAVAIL_ERROR; | 733 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 734 return FALSE; | 734 return FALSE; |
| 735 } | 735 } |
| 736 | 736 |
| 737 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectBy("N")); | 737 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N")); |
| 738 if (!pPageCount || !pPageCount->IsInteger()) { | 738 if (!pPageCount || !pPageCount->IsInteger()) { |
| 739 m_docStatus = PDF_DATAAVAIL_ERROR; | 739 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 740 return FALSE; | 740 return FALSE; |
| 741 } | 741 } |
| 742 | 742 |
| 743 int nPageCount = pPageCount->GetInteger(); | 743 int nPageCount = pPageCount->GetInteger(); |
| 744 if (nPageCount <= 1) { | 744 if (nPageCount <= 1) { |
| 745 m_docStatus = PDF_DATAAVAIL_DONE; | 745 m_docStatus = PDF_DATAAVAIL_DONE; |
| 746 return TRUE; | 746 return TRUE; |
| 747 } | 747 } |
| 748 | 748 |
| 749 CPDF_Array* pHintStreamRange = pDict->GetArrayBy("H"); | 749 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); |
| 750 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0; | 750 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0; |
| 751 if (nHintStreamSize != 2 && nHintStreamSize != 4) { | 751 if (nHintStreamSize != 2 && nHintStreamSize != 4) { |
| 752 m_docStatus = PDF_DATAAVAIL_ERROR; | 752 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 753 return FALSE; | 753 return FALSE; |
| 754 } | 754 } |
| 755 | 755 |
| 756 for (const CPDF_Object* pArrayObject : *pHintStreamRange) { | 756 for (const CPDF_Object* pArrayObject : *pHintStreamRange) { |
| 757 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect()); | 757 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect()); |
| 758 if (!pNumber || !pNumber->IsInteger()) { | 758 if (!pNumber || !pNumber->IsInteger()) { |
| 759 m_docStatus = PDF_DATAAVAIL_ERROR; | 759 m_docStatus = PDF_DATAAVAIL_ERROR; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 if (!bNumber) | 862 if (!bNumber) |
| 863 return FALSE; | 863 return FALSE; |
| 864 | 864 |
| 865 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); | 865 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); |
| 866 m_pLinearized = | 866 m_pLinearized = |
| 867 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 867 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); |
| 868 if (!m_pLinearized) | 868 if (!m_pLinearized) |
| 869 return FALSE; | 869 return FALSE; |
| 870 | 870 |
| 871 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 871 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 872 if (!pDict || !pDict->GetObjectBy("Linearized")) | 872 if (!pDict || !pDict->GetObjectFor("Linearized")) |
| 873 return FALSE; | 873 return FALSE; |
| 874 | 874 |
| 875 CPDF_Object* pLen = pDict->GetObjectBy("L"); | 875 CPDF_Object* pLen = pDict->GetObjectFor("L"); |
| 876 if (!pLen) | 876 if (!pLen) |
| 877 return FALSE; | 877 return FALSE; |
| 878 | 878 |
| 879 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) | 879 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) |
| 880 return FALSE; | 880 return FALSE; |
| 881 | 881 |
| 882 m_bLinearized = TRUE; | 882 m_bLinearized = TRUE; |
| 883 | 883 |
| 884 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectBy("P"))) | 884 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) |
| 885 m_dwFirstPageNo = pNo->GetInteger(); | 885 m_dwFirstPageNo = pNo->GetInteger(); |
| 886 | 886 |
| 887 return TRUE; | 887 return TRUE; |
| 888 } | 888 } |
| 889 | 889 |
| 890 FX_BOOL CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { | 890 FX_BOOL CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { |
| 891 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 891 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
| 892 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); | 892 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); |
| 893 | 893 |
| 894 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 894 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 return -1; | 951 return -1; |
| 952 | 952 |
| 953 uint32_t objNum = FXSYS_atoui(objnum.c_str()); | 953 uint32_t objNum = FXSYS_atoui(objnum.c_str()); |
| 954 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); | 954 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); |
| 955 if (!pObj) { | 955 if (!pObj) { |
| 956 m_Pos += m_parser.m_pSyntax->SavePos(); | 956 m_Pos += m_parser.m_pSyntax->SavePos(); |
| 957 return 0; | 957 return 0; |
| 958 } | 958 } |
| 959 | 959 |
| 960 CPDF_Dictionary* pDict = pObj->GetDict(); | 960 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 961 CPDF_Name* pName = ToName(pDict ? pDict->GetObjectBy("Type") : nullptr); | 961 CPDF_Name* pName = ToName(pDict ? pDict->GetObjectFor("Type") : nullptr); |
| 962 if (pName) { | 962 if (pName) { |
| 963 if (pName->GetString() == "XRef") { | 963 if (pName->GetString() == "XRef") { |
| 964 m_Pos += m_parser.m_pSyntax->SavePos(); | 964 m_Pos += m_parser.m_pSyntax->SavePos(); |
| 965 xref_offset = pObj->GetDict()->GetIntegerBy("Prev"); | 965 xref_offset = pObj->GetDict()->GetIntegerFor("Prev"); |
| 966 pObj->Release(); | 966 pObj->Release(); |
| 967 return 1; | 967 return 1; |
| 968 } | 968 } |
| 969 } | 969 } |
| 970 pObj->Release(); | 970 pObj->Release(); |
| 971 return -1; | 971 return -1; |
| 972 } | 972 } |
| 973 pHints->AddSegment(m_Pos, req_size); | 973 pHints->AddSegment(m_Pos, req_size); |
| 974 return 0; | 974 return 0; |
| 975 } | 975 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 if (!pTrailer) { | 1198 if (!pTrailer) { |
| 1199 m_Pos += m_syntaxParser.SavePos(); | 1199 m_Pos += m_syntaxParser.SavePos(); |
| 1200 pHints->AddSegment(m_Pos, iTrailerSize); | 1200 pHints->AddSegment(m_Pos, iTrailerSize); |
| 1201 return FALSE; | 1201 return FALSE; |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 if (!pTrailer->IsDictionary()) | 1204 if (!pTrailer->IsDictionary()) |
| 1205 return FALSE; | 1205 return FALSE; |
| 1206 | 1206 |
| 1207 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); | 1207 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); |
| 1208 CPDF_Object* pEncrypt = pTrailerDict->GetObjectBy("Encrypt"); | 1208 CPDF_Object* pEncrypt = pTrailerDict->GetObjectFor("Encrypt"); |
| 1209 if (ToReference(pEncrypt)) { | 1209 if (ToReference(pEncrypt)) { |
| 1210 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1210 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 1211 return TRUE; | 1211 return TRUE; |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 uint32_t xrefpos = GetDirectInteger(pTrailerDict, "Prev"); | 1214 uint32_t xrefpos = GetDirectInteger(pTrailerDict, "Prev"); |
| 1215 if (xrefpos) { | 1215 if (xrefpos) { |
| 1216 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, "XRefStm"); | 1216 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, "XRefStm"); |
| 1217 if (m_dwPrevXRefOffset) { | 1217 if (m_dwPrevXRefOffset) { |
| 1218 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1218 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 } | 1321 } |
| 1322 | 1322 |
| 1323 if (!pPage->IsDictionary()) { | 1323 if (!pPage->IsDictionary()) { |
| 1324 pPage->Release(); | 1324 pPage->Release(); |
| 1325 m_docStatus = PDF_DATAAVAIL_ERROR; | 1325 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1326 return FALSE; | 1326 return FALSE; |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 pPageNode->m_dwPageNo = dwPageNo; | 1329 pPageNode->m_dwPageNo = dwPageNo; |
| 1330 CPDF_Dictionary* pDict = pPage->GetDict(); | 1330 CPDF_Dictionary* pDict = pPage->GetDict(); |
| 1331 CFX_ByteString type = pDict->GetStringBy("Type"); | 1331 CFX_ByteString type = pDict->GetStringFor("Type"); |
| 1332 if (type == "Pages") { | 1332 if (type == "Pages") { |
| 1333 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1333 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 1334 CPDF_Object* pKids = pDict->GetObjectBy("Kids"); | 1334 CPDF_Object* pKids = pDict->GetObjectFor("Kids"); |
| 1335 if (!pKids) { | 1335 if (!pKids) { |
| 1336 m_docStatus = PDF_DATAAVAIL_PAGE; | 1336 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 1337 return TRUE; | 1337 return TRUE; |
| 1338 } | 1338 } |
| 1339 | 1339 |
| 1340 switch (pKids->GetType()) { | 1340 switch (pKids->GetType()) { |
| 1341 case CPDF_Object::REFERENCE: { | 1341 case CPDF_Object::REFERENCE: { |
| 1342 CPDF_Reference* pKid = pKids->AsReference(); | 1342 CPDF_Reference* pKid = pKids->AsReference(); |
| 1343 PageNode* pNode = new PageNode(); | 1343 PageNode* pNode = new PageNode(); |
| 1344 pPageNode->m_childNode.Add(pNode); | 1344 pPageNode->m_childNode.Add(pNode); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 pPages->Release(); | 1457 pPages->Release(); |
| 1458 m_docStatus = PDF_DATAAVAIL_ERROR; | 1458 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1459 return FALSE; | 1459 return FALSE; |
| 1460 } | 1460 } |
| 1461 | 1461 |
| 1462 if (!pPagesDict->KeyExist("Kids")) { | 1462 if (!pPagesDict->KeyExist("Kids")) { |
| 1463 pPages->Release(); | 1463 pPages->Release(); |
| 1464 return TRUE; | 1464 return TRUE; |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 int count = pPagesDict->GetIntegerBy("Count"); | 1467 int count = pPagesDict->GetIntegerFor("Count"); |
| 1468 if (count > 0) { | 1468 if (count > 0) { |
| 1469 pPages->Release(); | 1469 pPages->Release(); |
| 1470 return TRUE; | 1470 return TRUE; |
| 1471 } | 1471 } |
| 1472 | 1472 |
| 1473 pPages->Release(); | 1473 pPages->Release(); |
| 1474 return FALSE; | 1474 return FALSE; |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 FX_BOOL CPDF_DataAvail::LoadDocPages(DownloadHints* pHints) { | 1477 FX_BOOL CPDF_DataAvail::LoadDocPages(DownloadHints* pHints) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 DownloadHints* pHints) { | 1537 DownloadHints* pHints) { |
| 1538 if (!m_objs_array.GetSize()) { | 1538 if (!m_objs_array.GetSize()) { |
| 1539 m_objs_array.RemoveAll(); | 1539 m_objs_array.RemoveAll(); |
| 1540 m_ObjectSet.clear(); | 1540 m_ObjectSet.clear(); |
| 1541 | 1541 |
| 1542 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); | 1542 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); |
| 1543 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); | 1543 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); |
| 1544 if (!pPageDict) | 1544 if (!pPageDict) |
| 1545 return TRUE; | 1545 return TRUE; |
| 1546 | 1546 |
| 1547 CPDF_Object* pAnnots = pPageDict->GetObjectBy("Annots"); | 1547 CPDF_Object* pAnnots = pPageDict->GetObjectFor("Annots"); |
| 1548 if (!pAnnots) | 1548 if (!pAnnots) |
| 1549 return TRUE; | 1549 return TRUE; |
| 1550 | 1550 |
| 1551 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 1551 CFX_ArrayTemplate<CPDF_Object*> obj_array; |
| 1552 obj_array.Add(pAnnots); | 1552 obj_array.Add(pAnnots); |
| 1553 | 1553 |
| 1554 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 1554 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); |
| 1555 if (bRet) | 1555 if (bRet) |
| 1556 m_objs_array.RemoveAll(); | 1556 m_objs_array.RemoveAll(); |
| 1557 | 1557 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1580 if (nRet == DataAvailable) | 1580 if (nRet == DataAvailable) |
| 1581 m_bPageLoadedOK = FALSE; | 1581 m_bPageLoadedOK = FALSE; |
| 1582 return nRet; | 1582 return nRet; |
| 1583 } | 1583 } |
| 1584 | 1584 |
| 1585 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) { | 1585 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) { |
| 1586 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); | 1586 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); |
| 1587 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) | 1587 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) |
| 1588 return FALSE; | 1588 return FALSE; |
| 1589 | 1589 |
| 1590 CPDF_Object* pParent = pDict->GetObjectBy("Parent"); | 1590 CPDF_Object* pParent = pDict->GetObjectFor("Parent"); |
| 1591 if (!pParent) | 1591 if (!pParent) |
| 1592 return FALSE; | 1592 return FALSE; |
| 1593 | 1593 |
| 1594 CPDF_Dictionary* pParentDict = pParent->GetDict(); | 1594 CPDF_Dictionary* pParentDict = pParent->GetDict(); |
| 1595 if (!pParentDict) | 1595 if (!pParentDict) |
| 1596 return FALSE; | 1596 return FALSE; |
| 1597 | 1597 |
| 1598 CPDF_Object* pRet = pParentDict->GetObjectBy("Resources"); | 1598 CPDF_Object* pRet = pParentDict->GetObjectFor("Resources"); |
| 1599 if (pRet) { | 1599 if (pRet) { |
| 1600 m_pPageResource = pRet; | 1600 m_pPageResource = pRet; |
| 1601 return TRUE; | 1601 return TRUE; |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 return HaveResourceAncestor(pParentDict); | 1604 return HaveResourceAncestor(pParentDict); |
| 1605 } | 1605 } |
| 1606 | 1606 |
| 1607 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( | 1607 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( |
| 1608 uint32_t dwPage, | 1608 uint32_t dwPage, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 m_bPageLoadedOK = TRUE; | 1703 m_bPageLoadedOK = TRUE; |
| 1704 } | 1704 } |
| 1705 | 1705 |
| 1706 if (!m_bAnnotsLoad) { | 1706 if (!m_bAnnotsLoad) { |
| 1707 if (!CheckPageAnnots(dwPage, pHints)) | 1707 if (!CheckPageAnnots(dwPage, pHints)) |
| 1708 return DataNotAvailable; | 1708 return DataNotAvailable; |
| 1709 m_bAnnotsLoad = TRUE; | 1709 m_bAnnotsLoad = TRUE; |
| 1710 } | 1710 } |
| 1711 | 1711 |
| 1712 if (m_pPageDict && !m_bNeedDownLoadResource) { | 1712 if (m_pPageDict && !m_bNeedDownLoadResource) { |
| 1713 m_pPageResource = m_pPageDict->GetObjectBy("Resources"); | 1713 m_pPageResource = m_pPageDict->GetObjectFor("Resources"); |
| 1714 m_bNeedDownLoadResource = | 1714 m_bNeedDownLoadResource = |
| 1715 m_pPageResource || HaveResourceAncestor(m_pPageDict); | 1715 m_pPageResource || HaveResourceAncestor(m_pPageDict); |
| 1716 } | 1716 } |
| 1717 | 1717 |
| 1718 if (m_bNeedDownLoadResource) { | 1718 if (m_bNeedDownLoadResource) { |
| 1719 if (!CheckResources(pHints)) | 1719 if (!CheckResources(pHints)) |
| 1720 return DataNotAvailable; | 1720 return DataNotAvailable; |
| 1721 m_bNeedDownLoadResource = FALSE; | 1721 m_bNeedDownLoadResource = FALSE; |
| 1722 } | 1722 } |
| 1723 | 1723 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1754 uint32_t* pSize) { | 1754 uint32_t* pSize) { |
| 1755 if (pPos) | 1755 if (pPos) |
| 1756 *pPos = m_dwLastXRefOffset; | 1756 *pPos = m_dwLastXRefOffset; |
| 1757 if (pSize) | 1757 if (pSize) |
| 1758 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); | 1758 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); |
| 1759 } | 1759 } |
| 1760 | 1760 |
| 1761 int CPDF_DataAvail::GetPageCount() const { | 1761 int CPDF_DataAvail::GetPageCount() const { |
| 1762 if (m_pLinearized) { | 1762 if (m_pLinearized) { |
| 1763 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1763 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1764 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectBy("N") : nullptr; | 1764 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("N") : nullptr; |
| 1765 return pObj ? pObj->GetInteger() : 0; | 1765 return pObj ? pObj->GetInteger() : 0; |
| 1766 } | 1766 } |
| 1767 return m_pDocument ? m_pDocument->GetPageCount() : 0; | 1767 return m_pDocument ? m_pDocument->GetPageCount() : 0; |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { | 1770 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { |
| 1771 if (!m_pDocument || index < 0 || index >= GetPageCount()) | 1771 if (!m_pDocument || index < 0 || index >= GetPageCount()) |
| 1772 return nullptr; | 1772 return nullptr; |
| 1773 | 1773 |
| 1774 if (m_pLinearized) { | 1774 if (m_pLinearized) { |
| 1775 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1775 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1776 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectBy("P") : nullptr; | 1776 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr; |
| 1777 | 1777 |
| 1778 int pageNum = pObj ? pObj->GetInteger() : 0; | 1778 int pageNum = pObj ? pObj->GetInteger() : 0; |
| 1779 if (m_pHintTables && index != pageNum) { | 1779 if (m_pHintTables && index != pageNum) { |
| 1780 FX_FILESIZE szPageStartPos = 0; | 1780 FX_FILESIZE szPageStartPos = 0; |
| 1781 FX_FILESIZE szPageLength = 0; | 1781 FX_FILESIZE szPageLength = 0; |
| 1782 uint32_t dwObjNum = 0; | 1782 uint32_t dwObjNum = 0; |
| 1783 bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, | 1783 bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, |
| 1784 &szPageLength, &dwObjNum); | 1784 &szPageLength, &dwObjNum); |
| 1785 if (!bPagePosGot) | 1785 if (!bPagePosGot) |
| 1786 return nullptr; | 1786 return nullptr; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1803 CPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( | 1803 CPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( |
| 1804 DownloadHints* pHints) { | 1804 DownloadHints* pHints) { |
| 1805 if (!m_pDocument) | 1805 if (!m_pDocument) |
| 1806 return FormAvailable; | 1806 return FormAvailable; |
| 1807 | 1807 |
| 1808 if (!m_bLinearizedFormParamLoad) { | 1808 if (!m_bLinearizedFormParamLoad) { |
| 1809 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 1809 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 1810 if (!pRoot) | 1810 if (!pRoot) |
| 1811 return FormAvailable; | 1811 return FormAvailable; |
| 1812 | 1812 |
| 1813 CPDF_Object* pAcroForm = pRoot->GetObjectBy("AcroForm"); | 1813 CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm"); |
| 1814 if (!pAcroForm) | 1814 if (!pAcroForm) |
| 1815 return FormNotExist; | 1815 return FormNotExist; |
| 1816 | 1816 |
| 1817 DocAvailStatus nDocStatus = CheckLinearizedData(pHints); | 1817 DocAvailStatus nDocStatus = CheckLinearizedData(pHints); |
| 1818 if (nDocStatus == DataError) | 1818 if (nDocStatus == DataError) |
| 1819 return FormError; | 1819 return FormError; |
| 1820 if (nDocStatus == DataNotAvailable) | 1820 if (nDocStatus == DataNotAvailable) |
| 1821 return FormNotAvailable; | 1821 return FormNotAvailable; |
| 1822 | 1822 |
| 1823 if (!m_objs_array.GetSize()) | 1823 if (!m_objs_array.GetSize()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1835 return FormAvailable; | 1835 return FormAvailable; |
| 1836 } | 1836 } |
| 1837 | 1837 |
| 1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
| 1839 | 1839 |
| 1840 CPDF_DataAvail::PageNode::~PageNode() { | 1840 CPDF_DataAvail::PageNode::~PageNode() { |
| 1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
| 1842 delete m_childNode[i]; | 1842 delete m_childNode[i]; |
| 1843 m_childNode.RemoveAll(); | 1843 m_childNode.RemoveAll(); |
| 1844 } | 1844 } |
| OLD | NEW |