| OLD | NEW |
| 1 // Copyright 2014 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/include/fpdfapi/fpdf_parser.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 #include <memory> | |
| 11 #include <set> | |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "core/include/fpdfapi/cpdf_document.h" | 7 #include "core/include/fpdfapi/cpdf_document.h" |
| 16 #include "core/include/fpdfapi/cpdf_parser.h" | 8 #include "core/include/fpdfapi/fpdf_objects.h" |
| 17 #include "core/include/fpdfapi/fpdf_module.h" | |
| 18 #include "core/include/fpdfapi/fpdf_page.h" | |
| 19 #include "core/include/fxcrt/fx_ext.h" | 9 #include "core/include/fxcrt/fx_ext.h" |
| 20 #include "core/include/fxcrt/fx_safe_types.h" | 10 #include "core/include/fxcrt/fx_safe_types.h" |
| 21 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 11 #include "core/src/fpdfapi/fpdf_parser/cpdf_data_avail.h" |
| 22 #include "core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" | |
| 23 #include "core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.h" | 12 #include "core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.h" |
| 24 #include "core/src/fpdfapi/fpdf_parser/parser_int.h" | |
| 25 #include "third_party/base/stl_util.h" | 13 #include "third_party/base/stl_util.h" |
| 26 | 14 |
| 27 namespace { | 15 IPDF_DataAvail::IPDF_DataAvail(IPDF_DataAvail::FileAvail* pFileAvail, |
| 28 | |
| 29 bool CanReadFromBitStream(const CFX_BitStream* hStream, | |
| 30 const FX_SAFE_DWORD& num_bits) { | |
| 31 return num_bits.IsValid() && | |
| 32 hStream->BitsRemaining() >= num_bits.ValueOrDie(); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 bool IsSignatureDict(const CPDF_Dictionary* pDict) { | |
| 38 CPDF_Object* pType = pDict->GetElementValue("Type"); | |
| 39 if (!pType) | |
| 40 pType = pDict->GetElementValue("FT"); | |
| 41 return pType && pType->GetString() == "Sig"; | |
| 42 } | |
| 43 | |
| 44 | |
| 45 class CPDF_DataAvail final : public IPDF_DataAvail { | |
| 46 public: | |
| 47 CPDF_DataAvail(IFX_FileAvail* pFileAvail, | |
| 48 IFX_FileRead* pFileRead, | |
| 49 FX_BOOL bSupportHintTable); | |
| 50 ~CPDF_DataAvail() override; | |
| 51 | |
| 52 // IPDF_DataAvail: | |
| 53 DocAvailStatus IsDocAvail(IFX_DownloadHints* pHints) override; | |
| 54 void SetDocument(CPDF_Document* pDoc) override; | |
| 55 DocAvailStatus IsPageAvail(int iPage, IFX_DownloadHints* pHints) override; | |
| 56 DocFormStatus IsFormAvail(IFX_DownloadHints* pHints) override; | |
| 57 DocLinearizationStatus IsLinearizedPDF() override; | |
| 58 FX_BOOL IsLinearized() override { return m_bLinearized; } | |
| 59 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, FX_DWORD* pSize) override; | |
| 60 | |
| 61 int GetPageCount() const; | |
| 62 CPDF_Dictionary* GetPage(int index); | |
| 63 | |
| 64 friend class CPDF_HintTables; | |
| 65 | |
| 66 protected: | |
| 67 static const int kMaxDataAvailRecursionDepth = 64; | |
| 68 static int s_CurrentDataAvailRecursionDepth; | |
| 69 static const int kMaxPageRecursionDepth = 1024; | |
| 70 | |
| 71 FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset); | |
| 72 FX_BOOL IsObjectsAvail(CFX_ArrayTemplate<CPDF_Object*>& obj_array, | |
| 73 FX_BOOL bParsePage, | |
| 74 IFX_DownloadHints* pHints, | |
| 75 CFX_ArrayTemplate<CPDF_Object*>& ret_array); | |
| 76 FX_BOOL CheckDocStatus(IFX_DownloadHints* pHints); | |
| 77 FX_BOOL CheckHeader(IFX_DownloadHints* pHints); | |
| 78 FX_BOOL CheckFirstPage(IFX_DownloadHints* pHints); | |
| 79 FX_BOOL CheckHintTables(IFX_DownloadHints* pHints); | |
| 80 FX_BOOL CheckEnd(IFX_DownloadHints* pHints); | |
| 81 FX_BOOL CheckCrossRef(IFX_DownloadHints* pHints); | |
| 82 FX_BOOL CheckCrossRefItem(IFX_DownloadHints* pHints); | |
| 83 FX_BOOL CheckTrailer(IFX_DownloadHints* pHints); | |
| 84 FX_BOOL CheckRoot(IFX_DownloadHints* pHints); | |
| 85 FX_BOOL CheckInfo(IFX_DownloadHints* pHints); | |
| 86 FX_BOOL CheckPages(IFX_DownloadHints* pHints); | |
| 87 FX_BOOL CheckPage(IFX_DownloadHints* pHints); | |
| 88 FX_BOOL CheckResources(IFX_DownloadHints* pHints); | |
| 89 FX_BOOL CheckAnnots(IFX_DownloadHints* pHints); | |
| 90 FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints); | |
| 91 FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints* pHints); | |
| 92 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pHints); | |
| 93 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHints); | |
| 94 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints* pHints); | |
| 95 | |
| 96 int32_t CheckCrossRefStream(IFX_DownloadHints* pHints, | |
| 97 FX_FILESIZE& xref_offset); | |
| 98 FX_BOOL IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen); | |
| 99 void SetStartOffset(FX_FILESIZE dwOffset); | |
| 100 FX_BOOL GetNextToken(CFX_ByteString& token); | |
| 101 FX_BOOL GetNextChar(uint8_t& ch); | |
| 102 CPDF_Object* ParseIndirectObjectAt( | |
| 103 FX_FILESIZE pos, | |
| 104 FX_DWORD objnum, | |
| 105 CPDF_IndirectObjectHolder* pObjList = nullptr); | |
| 106 CPDF_Object* GetObject(FX_DWORD objnum, | |
| 107 IFX_DownloadHints* pHints, | |
| 108 FX_BOOL* pExistInFile); | |
| 109 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); | |
| 110 FX_BOOL PreparePageItem(); | |
| 111 FX_BOOL LoadPages(IFX_DownloadHints* pHints); | |
| 112 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); | |
| 113 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); | |
| 114 DocAvailStatus CheckLinearizedData(IFX_DownloadHints* pHints); | |
| 115 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadHints* pHints); | |
| 116 | |
| 117 DocAvailStatus CheckLinearizedFirstPage(int iPage, IFX_DownloadHints* pHints); | |
| 118 FX_BOOL HaveResourceAncestor(CPDF_Dictionary* pDict); | |
| 119 FX_BOOL CheckPage(int32_t iPage, IFX_DownloadHints* pHints); | |
| 120 FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); | |
| 121 FX_BOOL LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints); | |
| 122 FX_BOOL CheckPageNode(CPDF_PageNode& pageNodes, | |
| 123 int32_t iPage, | |
| 124 int32_t& iCount, | |
| 125 IFX_DownloadHints* pHints, | |
| 126 int level); | |
| 127 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, | |
| 128 CPDF_PageNode* pPageNode, | |
| 129 IFX_DownloadHints* pHints); | |
| 130 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, | |
| 131 CPDF_PageNode* pPageNode, | |
| 132 IFX_DownloadHints* pHints); | |
| 133 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints); | |
| 134 bool IsFirstCheck(int iPage); | |
| 135 void ResetFirstCheck(int iPage); | |
| 136 FX_BOOL IsDataAvail(FX_FILESIZE offset, | |
| 137 FX_DWORD size, | |
| 138 IFX_DownloadHints* pHints); | |
| 139 | |
| 140 CPDF_Parser m_parser; | |
| 141 CPDF_SyntaxParser m_syntaxParser; | |
| 142 CPDF_Object* m_pRoot; | |
| 143 FX_DWORD m_dwRootObjNum; | |
| 144 FX_DWORD m_dwInfoObjNum; | |
| 145 CPDF_Object* m_pLinearized; | |
| 146 CPDF_Object* m_pTrailer; | |
| 147 FX_BOOL m_bDocAvail; | |
| 148 FX_FILESIZE m_dwHeaderOffset; | |
| 149 FX_FILESIZE m_dwLastXRefOffset; | |
| 150 FX_FILESIZE m_dwXRefOffset; | |
| 151 FX_FILESIZE m_dwTrailerOffset; | |
| 152 FX_FILESIZE m_dwCurrentOffset; | |
| 153 PDF_DATAAVAIL_STATUS m_docStatus; | |
| 154 FX_FILESIZE m_dwFileLen; | |
| 155 CPDF_Document* m_pDocument; | |
| 156 std::set<FX_DWORD> m_ObjectSet; | |
| 157 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; | |
| 158 FX_FILESIZE m_Pos; | |
| 159 FX_FILESIZE m_bufferOffset; | |
| 160 FX_DWORD m_bufferSize; | |
| 161 CFX_ByteString m_WordBuf; | |
| 162 uint8_t m_bufferData[512]; | |
| 163 CFX_DWordArray m_XRefStreamList; | |
| 164 CFX_DWordArray m_PageObjList; | |
| 165 FX_DWORD m_PagesObjNum; | |
| 166 FX_BOOL m_bLinearized; | |
| 167 FX_DWORD m_dwFirstPageNo; | |
| 168 FX_BOOL m_bLinearedDataOK; | |
| 169 FX_BOOL m_bMainXRefLoadTried; | |
| 170 FX_BOOL m_bMainXRefLoadedOK; | |
| 171 FX_BOOL m_bPagesTreeLoad; | |
| 172 FX_BOOL m_bPagesLoad; | |
| 173 CPDF_Parser* m_pCurrentParser; | |
| 174 FX_FILESIZE m_dwCurrentXRefSteam; | |
| 175 FX_BOOL m_bAnnotsLoad; | |
| 176 FX_BOOL m_bHaveAcroForm; | |
| 177 FX_DWORD m_dwAcroFormObjNum; | |
| 178 FX_BOOL m_bAcroFormLoad; | |
| 179 CPDF_Object* m_pAcroForm; | |
| 180 CFX_ArrayTemplate<CPDF_Object*> m_arrayAcroforms; | |
| 181 CPDF_Dictionary* m_pPageDict; | |
| 182 CPDF_Object* m_pPageResource; | |
| 183 FX_BOOL m_bNeedDownLoadResource; | |
| 184 FX_BOOL m_bPageLoadedOK; | |
| 185 FX_BOOL m_bLinearizedFormParamLoad; | |
| 186 CFX_ArrayTemplate<CPDF_Object*> m_PagesArray; | |
| 187 FX_DWORD m_dwEncryptObjNum; | |
| 188 FX_FILESIZE m_dwPrevXRefOffset; | |
| 189 FX_BOOL m_bTotalLoadPageTree; | |
| 190 FX_BOOL m_bCurPageDictLoadOK; | |
| 191 CPDF_PageNode m_pageNodes; | |
| 192 std::set<FX_DWORD> m_pageMapCheckState; | |
| 193 std::set<FX_DWORD> m_pagesLoadState; | |
| 194 std::unique_ptr<CPDF_HintTables> m_pHintTables; | |
| 195 FX_BOOL m_bSupportHintTable; | |
| 196 }; | |
| 197 | |
| 198 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, | |
| 199 IFX_FileRead* pFileRead) | 16 IFX_FileRead* pFileRead) |
| 200 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) {} | 17 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) {} |
| 201 | 18 |
| 202 // static | 19 // static |
| 203 IPDF_DataAvail* IPDF_DataAvail::Create(IFX_FileAvail* pFileAvail, | 20 IPDF_DataAvail* IPDF_DataAvail::Create(IPDF_DataAvail::FileAvail* pFileAvail, |
| 204 IFX_FileRead* pFileRead) { | 21 IFX_FileRead* pFileRead) { |
| 205 return new CPDF_DataAvail(pFileAvail, pFileRead, TRUE); | 22 return new CPDF_DataAvail(pFileAvail, pFileRead, TRUE); |
| 206 } | 23 } |
| 207 | 24 |
| 208 // static | 25 // static |
| 209 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; | 26 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; |
| 210 | 27 |
| 211 CPDF_DataAvail::CPDF_DataAvail(IFX_FileAvail* pFileAvail, | 28 CPDF_DataAvail::CPDF_DataAvail(IPDF_DataAvail::FileAvail* pFileAvail, |
| 212 IFX_FileRead* pFileRead, | 29 IFX_FileRead* pFileRead, |
| 213 FX_BOOL bSupportHintTable) | 30 FX_BOOL bSupportHintTable) |
| 214 : IPDF_DataAvail(pFileAvail, pFileRead) { | 31 : IPDF_DataAvail(pFileAvail, pFileRead) { |
| 215 m_Pos = 0; | 32 m_Pos = 0; |
| 216 m_dwFileLen = 0; | 33 m_dwFileLen = 0; |
| 217 if (m_pFileRead) { | 34 if (m_pFileRead) { |
| 218 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 35 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); |
| 219 } | 36 } |
| 220 m_dwCurrentOffset = 0; | 37 m_dwCurrentOffset = 0; |
| 221 m_dwXRefOffset = 0; | 38 m_dwXRefOffset = 0; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (it == pParser->m_SortedOffset.end() || | 114 if (it == pParser->m_SortedOffset.end() || |
| 298 ++it == pParser->m_SortedOffset.end()) { | 115 ++it == pParser->m_SortedOffset.end()) { |
| 299 return 0; | 116 return 0; |
| 300 } | 117 } |
| 301 return *it - offset; | 118 return *it - offset; |
| 302 } | 119 } |
| 303 | 120 |
| 304 FX_BOOL CPDF_DataAvail::IsObjectsAvail( | 121 FX_BOOL CPDF_DataAvail::IsObjectsAvail( |
| 305 CFX_ArrayTemplate<CPDF_Object*>& obj_array, | 122 CFX_ArrayTemplate<CPDF_Object*>& obj_array, |
| 306 FX_BOOL bParsePage, | 123 FX_BOOL bParsePage, |
| 307 IFX_DownloadHints* pHints, | 124 IPDF_DataAvail::DownloadHints* pHints, |
| 308 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { | 125 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { |
| 309 if (!obj_array.GetSize()) | 126 if (!obj_array.GetSize()) |
| 310 return TRUE; | 127 return TRUE; |
| 311 | 128 |
| 312 FX_DWORD count = 0; | 129 FX_DWORD count = 0; |
| 313 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; | 130 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; |
| 314 int32_t i = 0; | 131 int32_t i = 0; |
| 315 for (i = 0; i < obj_array.GetSize(); i++) { | 132 for (i = 0; i < obj_array.GetSize(); i++) { |
| 316 CPDF_Object* pObj = obj_array[i]; | 133 CPDF_Object* pObj = obj_array[i]; |
| 317 if (!pObj) | 134 if (!pObj) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 192 } |
| 376 return FALSE; | 193 return FALSE; |
| 377 } | 194 } |
| 378 | 195 |
| 379 obj_array.RemoveAll(); | 196 obj_array.RemoveAll(); |
| 380 obj_array.Append(new_obj_array); | 197 obj_array.Append(new_obj_array); |
| 381 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 198 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); |
| 382 } | 199 } |
| 383 | 200 |
| 384 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( | 201 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( |
| 385 IFX_DownloadHints* pHints) { | 202 IPDF_DataAvail::DownloadHints* pHints) { |
| 386 if (!m_dwFileLen && m_pFileRead) { | 203 if (!m_dwFileLen && m_pFileRead) { |
| 387 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 204 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); |
| 388 if (!m_dwFileLen) | 205 if (!m_dwFileLen) |
| 389 return DataError; | 206 return DataError; |
| 390 } | 207 } |
| 391 | 208 |
| 392 while (!m_bDocAvail) { | 209 while (!m_bDocAvail) { |
| 393 if (!CheckDocStatus(pHints)) | 210 if (!CheckDocStatus(pHints)) |
| 394 return DataNotAvailable; | 211 return DataNotAvailable; |
| 395 } | 212 } |
| 396 | 213 |
| 397 return DataAvailable; | 214 return DataAvailable; |
| 398 } | 215 } |
| 399 | 216 |
| 400 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { | 217 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject( |
| 218 IPDF_DataAvail::DownloadHints* pHints) { |
| 401 if (!m_objs_array.GetSize()) { | 219 if (!m_objs_array.GetSize()) { |
| 402 m_objs_array.RemoveAll(); | 220 m_objs_array.RemoveAll(); |
| 403 m_ObjectSet.clear(); | 221 m_ObjectSet.clear(); |
| 404 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 222 CFX_ArrayTemplate<CPDF_Object*> obj_array; |
| 405 obj_array.Append(m_arrayAcroforms); | 223 obj_array.Append(m_arrayAcroforms); |
| 406 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 224 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); |
| 407 if (bRet) | 225 if (bRet) |
| 408 m_objs_array.RemoveAll(); | 226 m_objs_array.RemoveAll(); |
| 409 return bRet; | 227 return bRet; |
| 410 } | 228 } |
| 411 | 229 |
| 412 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 230 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; |
| 413 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 231 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); |
| 414 if (bRet) { | 232 if (bRet) { |
| 415 int32_t iSize = m_arrayAcroforms.GetSize(); | 233 int32_t iSize = m_arrayAcroforms.GetSize(); |
| 416 for (int32_t i = 0; i < iSize; ++i) { | 234 for (int32_t i = 0; i < iSize; ++i) { |
| 417 m_arrayAcroforms.GetAt(i)->Release(); | 235 m_arrayAcroforms.GetAt(i)->Release(); |
| 418 } | 236 } |
| 419 m_arrayAcroforms.RemoveAll(); | 237 m_arrayAcroforms.RemoveAll(); |
| 420 } else { | 238 } else { |
| 421 m_objs_array.RemoveAll(); | 239 m_objs_array.RemoveAll(); |
| 422 m_objs_array.Append(new_objs_array); | 240 m_objs_array.Append(new_objs_array); |
| 423 } | 241 } |
| 424 return bRet; | 242 return bRet; |
| 425 } | 243 } |
| 426 | 244 |
| 427 FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) { | 245 FX_BOOL CPDF_DataAvail::CheckAcroForm(IPDF_DataAvail::DownloadHints* pHints) { |
| 428 FX_BOOL bExist = FALSE; | 246 FX_BOOL bExist = FALSE; |
| 429 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 247 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); |
| 430 if (!bExist) { | 248 if (!bExist) { |
| 431 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 249 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
| 432 return TRUE; | 250 return TRUE; |
| 433 } | 251 } |
| 434 | 252 |
| 435 if (!m_pAcroForm) { | 253 if (!m_pAcroForm) { |
| 436 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 254 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
| 437 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 255 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 438 return TRUE; | 256 return TRUE; |
| 439 } | 257 } |
| 440 return FALSE; | 258 return FALSE; |
| 441 } | 259 } |
| 442 | 260 |
| 443 m_arrayAcroforms.Add(m_pAcroForm); | 261 m_arrayAcroforms.Add(m_pAcroForm); |
| 444 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 262 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
| 445 return TRUE; | 263 return TRUE; |
| 446 } | 264 } |
| 447 | 265 |
| 448 FX_BOOL CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints* pHints) { | 266 FX_BOOL CPDF_DataAvail::CheckDocStatus(IPDF_DataAvail::DownloadHints* pHints) { |
| 449 switch (m_docStatus) { | 267 switch (m_docStatus) { |
| 450 case PDF_DATAAVAIL_HEADER: | 268 case PDF_DATAAVAIL_HEADER: |
| 451 return CheckHeader(pHints); | 269 return CheckHeader(pHints); |
| 452 case PDF_DATAAVAIL_FIRSTPAGE: | 270 case PDF_DATAAVAIL_FIRSTPAGE: |
| 453 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: | 271 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: |
| 454 return CheckFirstPage(pHints); | 272 return CheckFirstPage(pHints); |
| 455 case PDF_DATAAVAIL_HINTTABLE: | 273 case PDF_DATAAVAIL_HINTTABLE: |
| 456 return CheckHintTables(pHints); | 274 return CheckHintTables(pHints); |
| 457 case PDF_DATAAVAIL_END: | 275 case PDF_DATAAVAIL_END: |
| 458 return CheckEnd(pHints); | 276 return CheckEnd(pHints); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 488 case PDF_DATAAVAIL_ERROR: | 306 case PDF_DATAAVAIL_ERROR: |
| 489 return LoadAllFile(pHints); | 307 return LoadAllFile(pHints); |
| 490 case PDF_DATAAVAIL_PAGE_LATERLOAD: | 308 case PDF_DATAAVAIL_PAGE_LATERLOAD: |
| 491 m_docStatus = PDF_DATAAVAIL_PAGE; | 309 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 492 default: | 310 default: |
| 493 m_bDocAvail = TRUE; | 311 m_bDocAvail = TRUE; |
| 494 return TRUE; | 312 return TRUE; |
| 495 } | 313 } |
| 496 } | 314 } |
| 497 | 315 |
| 498 FX_BOOL CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) { | 316 FX_BOOL CPDF_DataAvail::CheckPageStatus(IPDF_DataAvail::DownloadHints* pHints) { |
| 499 switch (m_docStatus) { | 317 switch (m_docStatus) { |
| 500 case PDF_DATAAVAIL_PAGETREE: | 318 case PDF_DATAAVAIL_PAGETREE: |
| 501 return CheckPages(pHints); | 319 return CheckPages(pHints); |
| 502 case PDF_DATAAVAIL_PAGE: | 320 case PDF_DATAAVAIL_PAGE: |
| 503 return CheckPage(pHints); | 321 return CheckPage(pHints); |
| 504 case PDF_DATAAVAIL_ERROR: | 322 case PDF_DATAAVAIL_ERROR: |
| 505 return LoadAllFile(pHints); | 323 return LoadAllFile(pHints); |
| 506 default: | 324 default: |
| 507 m_bPagesTreeLoad = TRUE; | 325 m_bPagesTreeLoad = TRUE; |
| 508 m_bPagesLoad = TRUE; | 326 m_bPagesLoad = TRUE; |
| 509 return TRUE; | 327 return TRUE; |
| 510 } | 328 } |
| 511 } | 329 } |
| 512 | 330 |
| 513 FX_BOOL CPDF_DataAvail::LoadAllFile(IFX_DownloadHints* pHints) { | 331 FX_BOOL CPDF_DataAvail::LoadAllFile(IPDF_DataAvail::DownloadHints* pHints) { |
| 514 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { | 332 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { |
| 515 m_docStatus = PDF_DATAAVAIL_DONE; | 333 m_docStatus = PDF_DATAAVAIL_DONE; |
| 516 return TRUE; | 334 return TRUE; |
| 517 } | 335 } |
| 518 | 336 |
| 519 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); | 337 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); |
| 520 return FALSE; | 338 return FALSE; |
| 521 } | 339 } |
| 522 | 340 |
| 523 FX_BOOL CPDF_DataAvail::LoadAllXref(IFX_DownloadHints* pHints) { | 341 FX_BOOL CPDF_DataAvail::LoadAllXref(IPDF_DataAvail::DownloadHints* pHints) { |
| 524 m_parser.m_pSyntax->InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); | 342 m_parser.m_pSyntax->InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); |
| 525 m_parser.m_bOwnFileRead = false; | 343 m_parser.m_bOwnFileRead = false; |
| 526 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && | 344 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && |
| 527 !m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) { | 345 !m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) { |
| 528 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 346 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 529 return FALSE; | 347 return FALSE; |
| 530 } | 348 } |
| 531 | 349 |
| 532 m_dwRootObjNum = m_parser.GetRootObjNum(); | 350 m_dwRootObjNum = m_parser.GetRootObjNum(); |
| 533 m_dwInfoObjNum = m_parser.GetInfoObjNum(); | 351 m_dwInfoObjNum = m_parser.GetInfoObjNum(); |
| 534 m_pCurrentParser = &m_parser; | 352 m_pCurrentParser = &m_parser; |
| 535 m_docStatus = PDF_DATAAVAIL_ROOT; | 353 m_docStatus = PDF_DATAAVAIL_ROOT; |
| 536 return TRUE; | 354 return TRUE; |
| 537 } | 355 } |
| 538 | 356 |
| 539 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, | 357 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, |
| 540 IFX_DownloadHints* pHints, | 358 IPDF_DataAvail::DownloadHints* pHints, |
| 541 FX_BOOL* pExistInFile) { | 359 FX_BOOL* pExistInFile) { |
| 542 CPDF_Object* pRet = nullptr; | 360 CPDF_Object* pRet = nullptr; |
| 543 FX_DWORD size = 0; | 361 FX_DWORD size = 0; |
| 544 FX_FILESIZE offset = 0; | 362 FX_FILESIZE offset = 0; |
| 545 CPDF_Parser* pParser = nullptr; | 363 CPDF_Parser* pParser = nullptr; |
| 546 | 364 |
| 547 if (pExistInFile) | 365 if (pExistInFile) |
| 548 *pExistInFile = TRUE; | 366 *pExistInFile = TRUE; |
| 549 | 367 |
| 550 if (m_pDocument) { | 368 if (m_pDocument) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 561 | 379 |
| 562 if (pParser) | 380 if (pParser) |
| 563 pRet = pParser->ParseIndirectObject(nullptr, objnum); | 381 pRet = pParser->ParseIndirectObject(nullptr, objnum); |
| 564 | 382 |
| 565 if (!pRet && pExistInFile) | 383 if (!pRet && pExistInFile) |
| 566 *pExistInFile = FALSE; | 384 *pExistInFile = FALSE; |
| 567 | 385 |
| 568 return pRet; | 386 return pRet; |
| 569 } | 387 } |
| 570 | 388 |
| 571 FX_BOOL CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) { | 389 FX_BOOL CPDF_DataAvail::CheckInfo(IPDF_DataAvail::DownloadHints* pHints) { |
| 572 FX_BOOL bExist = FALSE; | 390 FX_BOOL bExist = FALSE; |
| 573 CPDF_Object* pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); | 391 CPDF_Object* pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); |
| 574 if (!bExist) { | 392 if (!bExist) { |
| 575 m_docStatus = | 393 m_docStatus = |
| 576 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); | 394 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); |
| 577 return TRUE; | 395 return TRUE; |
| 578 } | 396 } |
| 579 | 397 |
| 580 if (!pInfo) { | 398 if (!pInfo) { |
| 581 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 399 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
| 582 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 400 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 583 return TRUE; | 401 return TRUE; |
| 584 } | 402 } |
| 585 | 403 |
| 586 if (m_Pos == m_dwFileLen) | 404 if (m_Pos == m_dwFileLen) |
| 587 m_docStatus = PDF_DATAAVAIL_ERROR; | 405 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 588 return FALSE; | 406 return FALSE; |
| 589 } | 407 } |
| 590 | 408 |
| 591 if (pInfo) | 409 if (pInfo) |
| 592 pInfo->Release(); | 410 pInfo->Release(); |
| 593 | 411 |
| 594 m_docStatus = | 412 m_docStatus = |
| 595 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); | 413 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); |
| 596 | 414 |
| 597 return TRUE; | 415 return TRUE; |
| 598 } | 416 } |
| 599 | 417 |
| 600 FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) { | 418 FX_BOOL CPDF_DataAvail::CheckRoot(IPDF_DataAvail::DownloadHints* pHints) { |
| 601 FX_BOOL bExist = FALSE; | 419 FX_BOOL bExist = FALSE; |
| 602 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); | 420 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); |
| 603 if (!bExist) { | 421 if (!bExist) { |
| 604 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 422 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 605 return TRUE; | 423 return TRUE; |
| 606 } | 424 } |
| 607 | 425 |
| 608 if (!m_pRoot) { | 426 if (!m_pRoot) { |
| 609 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 427 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
| 610 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 428 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 } | 476 } |
| 659 | 477 |
| 660 bool CPDF_DataAvail::IsFirstCheck(int iPage) { | 478 bool CPDF_DataAvail::IsFirstCheck(int iPage) { |
| 661 return m_pageMapCheckState.insert(iPage).second; | 479 return m_pageMapCheckState.insert(iPage).second; |
| 662 } | 480 } |
| 663 | 481 |
| 664 void CPDF_DataAvail::ResetFirstCheck(int iPage) { | 482 void CPDF_DataAvail::ResetFirstCheck(int iPage) { |
| 665 m_pageMapCheckState.erase(iPage); | 483 m_pageMapCheckState.erase(iPage); |
| 666 } | 484 } |
| 667 | 485 |
| 668 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { | 486 FX_BOOL CPDF_DataAvail::CheckPage(IPDF_DataAvail::DownloadHints* pHints) { |
| 669 FX_DWORD iPageObjs = m_PageObjList.GetSize(); | 487 FX_DWORD iPageObjs = m_PageObjList.GetSize(); |
| 670 CFX_DWordArray UnavailObjList; | 488 CFX_DWordArray UnavailObjList; |
| 671 for (FX_DWORD i = 0; i < iPageObjs; ++i) { | 489 for (FX_DWORD i = 0; i < iPageObjs; ++i) { |
| 672 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); | 490 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); |
| 673 FX_BOOL bExist = FALSE; | 491 FX_BOOL bExist = FALSE; |
| 674 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); | 492 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); |
| 675 if (!pObj) { | 493 if (!pObj) { |
| 676 if (bExist) | 494 if (bExist) |
| 677 UnavailObjList.Add(dwPageObjNum); | 495 UnavailObjList.Add(dwPageObjNum); |
| 678 continue; | 496 continue; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 m_PageObjList.Add(pRef->GetRefObjNum()); | 574 m_PageObjList.Add(pRef->GetRefObjNum()); |
| 757 } | 575 } |
| 758 } break; | 576 } break; |
| 759 default: | 577 default: |
| 760 m_docStatus = PDF_DATAAVAIL_ERROR; | 578 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 761 return FALSE; | 579 return FALSE; |
| 762 } | 580 } |
| 763 return TRUE; | 581 return TRUE; |
| 764 } | 582 } |
| 765 | 583 |
| 766 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) { | 584 FX_BOOL CPDF_DataAvail::CheckPages(IPDF_DataAvail::DownloadHints* pHints) { |
| 767 FX_BOOL bExist = FALSE; | 585 FX_BOOL bExist = FALSE; |
| 768 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 586 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
| 769 if (!bExist) { | 587 if (!bExist) { |
| 770 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 588 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 771 return TRUE; | 589 return TRUE; |
| 772 } | 590 } |
| 773 | 591 |
| 774 if (!pPages) { | 592 if (!pPages) { |
| 775 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 593 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
| 776 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 594 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 777 return TRUE; | 595 return TRUE; |
| 778 } | 596 } |
| 779 return FALSE; | 597 return FALSE; |
| 780 } | 598 } |
| 781 | 599 |
| 782 if (!GetPageKids(m_pCurrentParser, pPages)) { | 600 if (!GetPageKids(m_pCurrentParser, pPages)) { |
| 783 pPages->Release(); | 601 pPages->Release(); |
| 784 m_docStatus = PDF_DATAAVAIL_ERROR; | 602 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 785 return FALSE; | 603 return FALSE; |
| 786 } | 604 } |
| 787 | 605 |
| 788 pPages->Release(); | 606 pPages->Release(); |
| 789 m_docStatus = PDF_DATAAVAIL_PAGE; | 607 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 790 return TRUE; | 608 return TRUE; |
| 791 } | 609 } |
| 792 | 610 |
| 793 FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) { | 611 FX_BOOL CPDF_DataAvail::CheckHeader(IPDF_DataAvail::DownloadHints* pHints) { |
| 794 FX_DWORD req_size = 1024; | 612 FX_DWORD req_size = 1024; |
| 795 if ((FX_FILESIZE)req_size > m_dwFileLen) | 613 if ((FX_FILESIZE)req_size > m_dwFileLen) |
| 796 req_size = (FX_DWORD)m_dwFileLen; | 614 req_size = (FX_DWORD)m_dwFileLen; |
| 797 | 615 |
| 798 if (m_pFileAvail->IsDataAvail(0, req_size)) { | 616 if (m_pFileAvail->IsDataAvail(0, req_size)) { |
| 799 uint8_t buffer[1024]; | 617 uint8_t buffer[1024]; |
| 800 m_pFileRead->ReadBlock(buffer, 0, req_size); | 618 m_pFileRead->ReadBlock(buffer, 0, req_size); |
| 801 | 619 |
| 802 if (IsLinearizedFile(buffer, req_size)) { | 620 if (IsLinearizedFile(buffer, req_size)) { |
| 803 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; | 621 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; |
| 804 } else { | 622 } else { |
| 805 if (m_docStatus == PDF_DATAAVAIL_ERROR) | 623 if (m_docStatus == PDF_DATAAVAIL_ERROR) |
| 806 return FALSE; | 624 return FALSE; |
| 807 m_docStatus = PDF_DATAAVAIL_END; | 625 m_docStatus = PDF_DATAAVAIL_END; |
| 808 } | 626 } |
| 809 return TRUE; | 627 return TRUE; |
| 810 } | 628 } |
| 811 | 629 |
| 812 pHints->AddSegment(0, req_size); | 630 pHints->AddSegment(0, req_size); |
| 813 return FALSE; | 631 return FALSE; |
| 814 } | 632 } |
| 815 | 633 |
| 816 FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints* pHints) { | 634 FX_BOOL CPDF_DataAvail::CheckFirstPage(IPDF_DataAvail::DownloadHints* pHints) { |
| 817 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 635 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 818 CPDF_Object* pEndOffSet = pDict ? pDict->GetElement("E") : NULL; | 636 CPDF_Object* pEndOffSet = pDict ? pDict->GetElement("E") : NULL; |
| 819 if (!pEndOffSet) { | 637 if (!pEndOffSet) { |
| 820 m_docStatus = PDF_DATAAVAIL_ERROR; | 638 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 821 return FALSE; | 639 return FALSE; |
| 822 } | 640 } |
| 823 | 641 |
| 824 CPDF_Object* pXRefOffset = pDict ? pDict->GetElement("T") : NULL; | 642 CPDF_Object* pXRefOffset = pDict ? pDict->GetElement("T") : NULL; |
| 825 if (!pXRefOffset) { | 643 if (!pXRefOffset) { |
| 826 m_docStatus = PDF_DATAAVAIL_ERROR; | 644 m_docStatus = PDF_DATAAVAIL_ERROR; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 return FALSE; | 694 return FALSE; |
| 877 } | 695 } |
| 878 | 696 |
| 879 m_docStatus = | 697 m_docStatus = |
| 880 m_bSupportHintTable ? PDF_DATAAVAIL_HINTTABLE : PDF_DATAAVAIL_DONE; | 698 m_bSupportHintTable ? PDF_DATAAVAIL_HINTTABLE : PDF_DATAAVAIL_DONE; |
| 881 return TRUE; | 699 return TRUE; |
| 882 } | 700 } |
| 883 | 701 |
| 884 FX_BOOL CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, | 702 FX_BOOL CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, |
| 885 FX_DWORD size, | 703 FX_DWORD size, |
| 886 IFX_DownloadHints* pHints) { | 704 IPDF_DataAvail::DownloadHints* pHints) { |
| 887 if (offset > m_dwFileLen) | 705 if (offset > m_dwFileLen) |
| 888 return TRUE; | 706 return TRUE; |
| 889 | 707 |
| 890 FX_SAFE_DWORD safeSize = pdfium::base::checked_cast<FX_DWORD>(offset); | 708 FX_SAFE_DWORD safeSize = pdfium::base::checked_cast<FX_DWORD>(offset); |
| 891 safeSize += size; | 709 safeSize += size; |
| 892 safeSize += 512; | 710 safeSize += 512; |
| 893 if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) | 711 if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) |
| 894 size = m_dwFileLen - offset; | 712 size = m_dwFileLen - offset; |
| 895 else | 713 else |
| 896 size += 512; | 714 size += 512; |
| 897 | 715 |
| 898 if (!m_pFileAvail->IsDataAvail(offset, size)) { | 716 if (!m_pFileAvail->IsDataAvail(offset, size)) { |
| 899 pHints->AddSegment(offset, size); | 717 pHints->AddSegment(offset, size); |
| 900 return FALSE; | 718 return FALSE; |
| 901 } | 719 } |
| 902 return TRUE; | 720 return TRUE; |
| 903 } | 721 } |
| 904 | 722 |
| 905 FX_BOOL CPDF_DataAvail::CheckHintTables(IFX_DownloadHints* pHints) { | 723 FX_BOOL CPDF_DataAvail::CheckHintTables(IPDF_DataAvail::DownloadHints* pHints) { |
| 906 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 724 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 907 if (!pDict) { | 725 if (!pDict) { |
| 908 m_docStatus = PDF_DATAAVAIL_ERROR; | 726 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 909 return FALSE; | 727 return FALSE; |
| 910 } | 728 } |
| 911 | 729 |
| 912 if (!pDict->KeyExist("H") || !pDict->KeyExist("O") || !pDict->KeyExist("N")) { | 730 if (!pDict->KeyExist("H") || !pDict->KeyExist("O") || !pDict->KeyExist("N")) { |
| 913 m_docStatus = PDF_DATAAVAIL_ERROR; | 731 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 914 return FALSE; | 732 return FALSE; |
| 915 } | 733 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 m_bLinearized = TRUE; | 861 m_bLinearized = TRUE; |
| 1044 | 862 |
| 1045 if (CPDF_Number* pNo = ToNumber(pDict->GetElement("P"))) | 863 if (CPDF_Number* pNo = ToNumber(pDict->GetElement("P"))) |
| 1046 m_dwFirstPageNo = pNo->GetInteger(); | 864 m_dwFirstPageNo = pNo->GetInteger(); |
| 1047 | 865 |
| 1048 return TRUE; | 866 return TRUE; |
| 1049 } | 867 } |
| 1050 return FALSE; | 868 return FALSE; |
| 1051 } | 869 } |
| 1052 | 870 |
| 1053 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { | 871 FX_BOOL CPDF_DataAvail::CheckEnd(IPDF_DataAvail::DownloadHints* pHints) { |
| 1054 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 872 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
| 1055 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 873 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); |
| 1056 | 874 |
| 1057 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 875 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
| 1058 uint8_t buffer[1024]; | 876 uint8_t buffer[1024]; |
| 1059 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 877 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
| 1060 | 878 |
| 1061 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); | 879 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); |
| 1062 m_syntaxParser.InitParser(file.get(), 0); | 880 m_syntaxParser.InitParser(file.get(), 0); |
| 1063 m_syntaxParser.RestorePos(dwSize - 1); | 881 m_syntaxParser.RestorePos(dwSize - 1); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1085 } | 903 } |
| 1086 | 904 |
| 1087 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 905 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 1088 return TRUE; | 906 return TRUE; |
| 1089 } | 907 } |
| 1090 | 908 |
| 1091 pHints->AddSegment(req_pos, dwSize); | 909 pHints->AddSegment(req_pos, dwSize); |
| 1092 return FALSE; | 910 return FALSE; |
| 1093 } | 911 } |
| 1094 | 912 |
| 1095 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, | 913 int32_t CPDF_DataAvail::CheckCrossRefStream( |
| 1096 FX_FILESIZE& xref_offset) { | 914 IPDF_DataAvail::DownloadHints* pHints, |
| 915 FX_FILESIZE& xref_offset) { |
| 1097 xref_offset = 0; | 916 xref_offset = 0; |
| 1098 FX_DWORD req_size = | 917 FX_DWORD req_size = |
| 1099 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 918 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
| 1100 | 919 |
| 1101 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 920 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
| 1102 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 921 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
| 1103 CFX_BinaryBuf buf(iSize); | 922 CFX_BinaryBuf buf(iSize); |
| 1104 uint8_t* pBuf = buf.GetBuffer(); | 923 uint8_t* pBuf = buf.GetBuffer(); |
| 1105 | 924 |
| 1106 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 925 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 return FALSE; | 1060 return FALSE; |
| 1242 | 1061 |
| 1243 m_bufferOffset = read_pos; | 1062 m_bufferOffset = read_pos; |
| 1244 m_bufferSize = read_size; | 1063 m_bufferSize = read_size; |
| 1245 } | 1064 } |
| 1246 ch = m_bufferData[pos - m_bufferOffset]; | 1065 ch = m_bufferData[pos - m_bufferOffset]; |
| 1247 m_Pos++; | 1066 m_Pos++; |
| 1248 return TRUE; | 1067 return TRUE; |
| 1249 } | 1068 } |
| 1250 | 1069 |
| 1251 FX_BOOL CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints* pHints) { | 1070 FX_BOOL CPDF_DataAvail::CheckCrossRefItem( |
| 1071 IPDF_DataAvail::DownloadHints* pHints) { |
| 1252 int32_t iSize = 0; | 1072 int32_t iSize = 0; |
| 1253 CFX_ByteString token; | 1073 CFX_ByteString token; |
| 1254 while (1) { | 1074 while (1) { |
| 1255 if (!GetNextToken(token)) { | 1075 if (!GetNextToken(token)) { |
| 1256 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1076 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
| 1257 pHints->AddSegment(m_Pos, iSize); | 1077 pHints->AddSegment(m_Pos, iSize); |
| 1258 return FALSE; | 1078 return FALSE; |
| 1259 } | 1079 } |
| 1260 | 1080 |
| 1261 if (token == "trailer") { | 1081 if (token == "trailer") { |
| 1262 m_dwTrailerOffset = m_Pos; | 1082 m_dwTrailerOffset = m_Pos; |
| 1263 m_docStatus = PDF_DATAAVAIL_TRAILER; | 1083 m_docStatus = PDF_DATAAVAIL_TRAILER; |
| 1264 return TRUE; | 1084 return TRUE; |
| 1265 } | 1085 } |
| 1266 } | 1086 } |
| 1267 } | 1087 } |
| 1268 | 1088 |
| 1269 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints* pHints) { | 1089 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream( |
| 1090 IPDF_DataAvail::DownloadHints* pHints) { |
| 1270 FX_FILESIZE xref_offset = 0; | 1091 FX_FILESIZE xref_offset = 0; |
| 1271 | 1092 |
| 1272 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); | 1093 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); |
| 1273 if (nRet == 1) { | 1094 if (nRet == 1) { |
| 1274 if (!xref_offset) { | 1095 if (!xref_offset) { |
| 1275 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; | 1096 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; |
| 1276 } else { | 1097 } else { |
| 1277 m_dwCurrentXRefSteam = xref_offset; | 1098 m_dwCurrentXRefSteam = xref_offset; |
| 1278 m_Pos = xref_offset; | 1099 m_Pos = xref_offset; |
| 1279 } | 1100 } |
| 1280 return TRUE; | 1101 return TRUE; |
| 1281 } | 1102 } |
| 1282 | 1103 |
| 1283 if (nRet == -1) | 1104 if (nRet == -1) |
| 1284 m_docStatus = PDF_DATAAVAIL_ERROR; | 1105 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1285 return FALSE; | 1106 return FALSE; |
| 1286 } | 1107 } |
| 1287 | 1108 |
| 1288 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) { | 1109 FX_BOOL CPDF_DataAvail::CheckCrossRef(IPDF_DataAvail::DownloadHints* pHints) { |
| 1289 int32_t iSize = 0; | 1110 int32_t iSize = 0; |
| 1290 CFX_ByteString token; | 1111 CFX_ByteString token; |
| 1291 if (!GetNextToken(token)) { | 1112 if (!GetNextToken(token)) { |
| 1292 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1113 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
| 1293 pHints->AddSegment(m_Pos, iSize); | 1114 pHints->AddSegment(m_Pos, iSize); |
| 1294 return FALSE; | 1115 return FALSE; |
| 1295 } | 1116 } |
| 1296 | 1117 |
| 1297 if (token == "xref") { | 1118 if (token == "xref") { |
| 1298 while (1) { | 1119 while (1) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1310 return TRUE; | 1131 return TRUE; |
| 1311 } | 1132 } |
| 1312 } | 1133 } |
| 1313 } else { | 1134 } else { |
| 1314 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1135 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 1315 return TRUE; | 1136 return TRUE; |
| 1316 } | 1137 } |
| 1317 return FALSE; | 1138 return FALSE; |
| 1318 } | 1139 } |
| 1319 | 1140 |
| 1320 FX_BOOL CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) { | 1141 FX_BOOL CPDF_DataAvail::CheckTrailerAppend( |
| 1142 IPDF_DataAvail::DownloadHints* pHints) { |
| 1321 if (m_Pos < m_dwFileLen) { | 1143 if (m_Pos < m_dwFileLen) { |
| 1322 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); | 1144 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); |
| 1323 int32_t iSize = (int32_t)( | 1145 int32_t iSize = (int32_t)( |
| 1324 dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen - dwAppendPos : 512); | 1146 dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen - dwAppendPos : 512); |
| 1325 | 1147 |
| 1326 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { | 1148 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { |
| 1327 pHints->AddSegment(dwAppendPos, iSize); | 1149 pHints->AddSegment(dwAppendPos, iSize); |
| 1328 return FALSE; | 1150 return FALSE; |
| 1329 } | 1151 } |
| 1330 } | 1152 } |
| 1331 | 1153 |
| 1332 if (m_dwPrevXRefOffset) { | 1154 if (m_dwPrevXRefOffset) { |
| 1333 SetStartOffset(m_dwPrevXRefOffset); | 1155 SetStartOffset(m_dwPrevXRefOffset); |
| 1334 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 1156 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
| 1335 } else { | 1157 } else { |
| 1336 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; | 1158 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; |
| 1337 } | 1159 } |
| 1338 return TRUE; | 1160 return TRUE; |
| 1339 } | 1161 } |
| 1340 | 1162 |
| 1341 FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) { | 1163 FX_BOOL CPDF_DataAvail::CheckTrailer(IPDF_DataAvail::DownloadHints* pHints) { |
| 1342 int32_t iTrailerSize = | 1164 int32_t iTrailerSize = |
| 1343 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1165 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
| 1344 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { | 1166 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { |
| 1345 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); | 1167 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); |
| 1346 CFX_BinaryBuf buf(iSize); | 1168 CFX_BinaryBuf buf(iSize); |
| 1347 uint8_t* pBuf = buf.GetBuffer(); | 1169 uint8_t* pBuf = buf.GetBuffer(); |
| 1348 if (!pBuf) { | 1170 if (!pBuf) { |
| 1349 m_docStatus = PDF_DATAAVAIL_ERROR; | 1171 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1350 return FALSE; | 1172 return FALSE; |
| 1351 } | 1173 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 return TRUE; | 1213 return TRUE; |
| 1392 } | 1214 } |
| 1393 m_dwPrevXRefOffset = 0; | 1215 m_dwPrevXRefOffset = 0; |
| 1394 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 1216 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
| 1395 return TRUE; | 1217 return TRUE; |
| 1396 } | 1218 } |
| 1397 pHints->AddSegment(m_Pos, iTrailerSize); | 1219 pHints->AddSegment(m_Pos, iTrailerSize); |
| 1398 return FALSE; | 1220 return FALSE; |
| 1399 } | 1221 } |
| 1400 | 1222 |
| 1401 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) { | 1223 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, |
| 1224 IPDF_DataAvail::DownloadHints* pHints) { |
| 1402 while (TRUE) { | 1225 while (TRUE) { |
| 1403 switch (m_docStatus) { | 1226 switch (m_docStatus) { |
| 1404 case PDF_DATAAVAIL_PAGETREE: | 1227 case PDF_DATAAVAIL_PAGETREE: |
| 1405 if (!LoadDocPages(pHints)) | 1228 if (!LoadDocPages(pHints)) |
| 1406 return FALSE; | 1229 return FALSE; |
| 1407 break; | 1230 break; |
| 1408 case PDF_DATAAVAIL_PAGE: | 1231 case PDF_DATAAVAIL_PAGE: |
| 1409 if (!LoadDocPage(iPage, pHints)) | 1232 if (!LoadDocPage(iPage, pHints)) |
| 1410 return FALSE; | 1233 return FALSE; |
| 1411 break; | 1234 break; |
| 1412 case PDF_DATAAVAIL_ERROR: | 1235 case PDF_DATAAVAIL_ERROR: |
| 1413 return LoadAllFile(pHints); | 1236 return LoadAllFile(pHints); |
| 1414 default: | 1237 default: |
| 1415 m_bPagesTreeLoad = TRUE; | 1238 m_bPagesTreeLoad = TRUE; |
| 1416 m_bPagesLoad = TRUE; | 1239 m_bPagesLoad = TRUE; |
| 1417 m_bCurPageDictLoadOK = TRUE; | 1240 m_bCurPageDictLoadOK = TRUE; |
| 1418 m_docStatus = PDF_DATAAVAIL_PAGE; | 1241 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 1419 return TRUE; | 1242 return TRUE; |
| 1420 } | 1243 } |
| 1421 } | 1244 } |
| 1422 } | 1245 } |
| 1423 | 1246 |
| 1424 FX_BOOL CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo, | 1247 FX_BOOL CPDF_DataAvail::CheckArrayPageNode( |
| 1425 CPDF_PageNode* pPageNode, | 1248 FX_DWORD dwPageNo, |
| 1426 IFX_DownloadHints* pHints) { | 1249 CPDF_DataAvail::PageNode* pPageNode, |
| 1250 IPDF_DataAvail::DownloadHints* pHints) { |
| 1427 FX_BOOL bExist = FALSE; | 1251 FX_BOOL bExist = FALSE; |
| 1428 CPDF_Object* pPages = GetObject(dwPageNo, pHints, &bExist); | 1252 CPDF_Object* pPages = GetObject(dwPageNo, pHints, &bExist); |
| 1429 if (!bExist) { | 1253 if (!bExist) { |
| 1430 m_docStatus = PDF_DATAAVAIL_ERROR; | 1254 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1431 return FALSE; | 1255 return FALSE; |
| 1432 } | 1256 } |
| 1433 | 1257 |
| 1434 if (!pPages) { | 1258 if (!pPages) { |
| 1435 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 1259 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
| 1436 m_docStatus = PDF_DATAAVAIL_ERROR; | 1260 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1437 return FALSE; | 1261 return FALSE; |
| 1438 } | 1262 } |
| 1439 return FALSE; | 1263 return FALSE; |
| 1440 } | 1264 } |
| 1441 | 1265 |
| 1442 CPDF_Array* pArray = pPages->AsArray(); | 1266 CPDF_Array* pArray = pPages->AsArray(); |
| 1443 if (!pArray) { | 1267 if (!pArray) { |
| 1444 pPages->Release(); | 1268 pPages->Release(); |
| 1445 m_docStatus = PDF_DATAAVAIL_ERROR; | 1269 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1446 return FALSE; | 1270 return FALSE; |
| 1447 } | 1271 } |
| 1448 | 1272 |
| 1449 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1273 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 1450 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { | 1274 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { |
| 1451 CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); | 1275 CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); |
| 1452 if (!pKid) | 1276 if (!pKid) |
| 1453 continue; | 1277 continue; |
| 1454 | 1278 |
| 1455 CPDF_PageNode* pNode = new CPDF_PageNode(); | 1279 PageNode* pNode = new PageNode(); |
| 1456 pPageNode->m_childNode.Add(pNode); | 1280 pPageNode->m_childNode.Add(pNode); |
| 1457 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1281 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 1458 } | 1282 } |
| 1459 pPages->Release(); | 1283 pPages->Release(); |
| 1460 return TRUE; | 1284 return TRUE; |
| 1461 } | 1285 } |
| 1462 | 1286 |
| 1463 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, | 1287 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode( |
| 1464 CPDF_PageNode* pPageNode, | 1288 FX_DWORD dwPageNo, |
| 1465 IFX_DownloadHints* pHints) { | 1289 CPDF_DataAvail::PageNode* pPageNode, |
| 1290 IPDF_DataAvail::DownloadHints* pHints) { |
| 1466 FX_BOOL bExist = FALSE; | 1291 FX_BOOL bExist = FALSE; |
| 1467 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); | 1292 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); |
| 1468 if (!bExist) { | 1293 if (!bExist) { |
| 1469 m_docStatus = PDF_DATAAVAIL_ERROR; | 1294 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1470 return FALSE; | 1295 return FALSE; |
| 1471 } | 1296 } |
| 1472 | 1297 |
| 1473 if (!pPage) { | 1298 if (!pPage) { |
| 1474 if (m_docStatus == PDF_DATAAVAIL_ERROR) | 1299 if (m_docStatus == PDF_DATAAVAIL_ERROR) |
| 1475 m_docStatus = PDF_DATAAVAIL_ERROR; | 1300 m_docStatus = PDF_DATAAVAIL_ERROR; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1496 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1321 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 1497 CPDF_Object* pKids = pDict->GetElement("Kids"); | 1322 CPDF_Object* pKids = pDict->GetElement("Kids"); |
| 1498 if (!pKids) { | 1323 if (!pKids) { |
| 1499 m_docStatus = PDF_DATAAVAIL_PAGE; | 1324 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 1500 return TRUE; | 1325 return TRUE; |
| 1501 } | 1326 } |
| 1502 | 1327 |
| 1503 switch (pKids->GetType()) { | 1328 switch (pKids->GetType()) { |
| 1504 case CPDF_Object::REFERENCE: { | 1329 case CPDF_Object::REFERENCE: { |
| 1505 CPDF_Reference* pKid = pKids->AsReference(); | 1330 CPDF_Reference* pKid = pKids->AsReference(); |
| 1506 CPDF_PageNode* pNode = new CPDF_PageNode(); | 1331 PageNode* pNode = new PageNode(); |
| 1507 pPageNode->m_childNode.Add(pNode); | 1332 pPageNode->m_childNode.Add(pNode); |
| 1508 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1333 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 1509 } break; | 1334 } break; |
| 1510 case CPDF_Object::ARRAY: { | 1335 case CPDF_Object::ARRAY: { |
| 1511 CPDF_Array* pKidsArray = pKids->AsArray(); | 1336 CPDF_Array* pKidsArray = pKids->AsArray(); |
| 1512 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 1337 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
| 1513 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); | 1338 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); |
| 1514 if (!pKid) | 1339 if (!pKid) |
| 1515 continue; | 1340 continue; |
| 1516 | 1341 |
| 1517 CPDF_PageNode* pNode = new CPDF_PageNode(); | 1342 PageNode* pNode = new PageNode(); |
| 1518 pPageNode->m_childNode.Add(pNode); | 1343 pPageNode->m_childNode.Add(pNode); |
| 1519 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1344 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 1520 } | 1345 } |
| 1521 } break; | 1346 } break; |
| 1522 default: | 1347 default: |
| 1523 break; | 1348 break; |
| 1524 } | 1349 } |
| 1525 } else if (type == "Page") { | 1350 } else if (type == "Page") { |
| 1526 pPageNode->m_type = PDF_PAGENODE_PAGE; | 1351 pPageNode->m_type = PDF_PAGENODE_PAGE; |
| 1527 } else { | 1352 } else { |
| 1528 pPage->Release(); | 1353 pPage->Release(); |
| 1529 m_docStatus = PDF_DATAAVAIL_ERROR; | 1354 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1530 return FALSE; | 1355 return FALSE; |
| 1531 } | 1356 } |
| 1532 pPage->Release(); | 1357 pPage->Release(); |
| 1533 return TRUE; | 1358 return TRUE; |
| 1534 } | 1359 } |
| 1535 | 1360 |
| 1536 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_PageNode& pageNodes, | 1361 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_DataAvail::PageNode& pageNodes, |
| 1537 int32_t iPage, | 1362 int32_t iPage, |
| 1538 int32_t& iCount, | 1363 int32_t& iCount, |
| 1539 IFX_DownloadHints* pHints, | 1364 IPDF_DataAvail::DownloadHints* pHints, |
| 1540 int level) { | 1365 int level) { |
| 1541 if (level >= kMaxPageRecursionDepth) | 1366 if (level >= kMaxPageRecursionDepth) |
| 1542 return FALSE; | 1367 return FALSE; |
| 1543 | 1368 |
| 1544 int32_t iSize = pageNodes.m_childNode.GetSize(); | 1369 int32_t iSize = pageNodes.m_childNode.GetSize(); |
| 1545 if (iSize <= 0 || iPage >= iSize) { | 1370 if (iSize <= 0 || iPage >= iSize) { |
| 1546 m_docStatus = PDF_DATAAVAIL_ERROR; | 1371 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1547 return FALSE; | 1372 return FALSE; |
| 1548 } | 1373 } |
| 1549 | 1374 |
| 1550 for (int32_t i = 0; i < iSize; ++i) { | 1375 for (int32_t i = 0; i < iSize; ++i) { |
| 1551 CPDF_PageNode* pNode = pageNodes.m_childNode.GetAt(i); | 1376 PageNode* pNode = pageNodes.m_childNode.GetAt(i); |
| 1552 if (!pNode) | 1377 if (!pNode) |
| 1553 continue; | 1378 continue; |
| 1554 | 1379 |
| 1555 switch (pNode->m_type) { | 1380 switch (pNode->m_type) { |
| 1556 case PDF_PAGENODE_UNKNOWN: | 1381 case PDF_PAGENODE_UNKNOWN: |
| 1557 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { | 1382 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { |
| 1558 return FALSE; | 1383 return FALSE; |
| 1559 } | 1384 } |
| 1560 --i; | 1385 --i; |
| 1561 break; | 1386 break; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1576 } | 1401 } |
| 1577 | 1402 |
| 1578 if (iPage == iCount) { | 1403 if (iPage == iCount) { |
| 1579 m_docStatus = PDF_DATAAVAIL_DONE; | 1404 m_docStatus = PDF_DATAAVAIL_DONE; |
| 1580 return TRUE; | 1405 return TRUE; |
| 1581 } | 1406 } |
| 1582 } | 1407 } |
| 1583 return TRUE; | 1408 return TRUE; |
| 1584 } | 1409 } |
| 1585 | 1410 |
| 1586 FX_BOOL CPDF_DataAvail::LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints) { | 1411 FX_BOOL CPDF_DataAvail::LoadDocPage(int32_t iPage, |
| 1412 IPDF_DataAvail::DownloadHints* pHints) { |
| 1587 if (m_pDocument->GetPageCount() <= iPage || | 1413 if (m_pDocument->GetPageCount() <= iPage || |
| 1588 m_pDocument->m_PageList.GetAt(iPage)) { | 1414 m_pDocument->m_PageList.GetAt(iPage)) { |
| 1589 m_docStatus = PDF_DATAAVAIL_DONE; | 1415 m_docStatus = PDF_DATAAVAIL_DONE; |
| 1590 return TRUE; | 1416 return TRUE; |
| 1591 } | 1417 } |
| 1592 | 1418 |
| 1593 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { | 1419 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { |
| 1594 if (iPage == 0) { | 1420 if (iPage == 0) { |
| 1595 m_docStatus = PDF_DATAAVAIL_DONE; | 1421 m_docStatus = PDF_DATAAVAIL_DONE; |
| 1596 return TRUE; | 1422 return TRUE; |
| 1597 } | 1423 } |
| 1598 m_docStatus = PDF_DATAAVAIL_ERROR; | 1424 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1599 return TRUE; | 1425 return TRUE; |
| 1600 } | 1426 } |
| 1601 int32_t iCount = -1; | 1427 int32_t iCount = -1; |
| 1602 return CheckPageNode(m_pageNodes, iPage, iCount, pHints, 0); | 1428 return CheckPageNode(m_pageNodes, iPage, iCount, pHints, 0); |
| 1603 } | 1429 } |
| 1604 | 1430 |
| 1605 FX_BOOL CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints) { | 1431 FX_BOOL CPDF_DataAvail::CheckPageCount(IPDF_DataAvail::DownloadHints* pHints) { |
| 1606 FX_BOOL bExist = FALSE; | 1432 FX_BOOL bExist = FALSE; |
| 1607 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 1433 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
| 1608 if (!bExist) { | 1434 if (!bExist) { |
| 1609 m_docStatus = PDF_DATAAVAIL_ERROR; | 1435 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1610 return FALSE; | 1436 return FALSE; |
| 1611 } | 1437 } |
| 1612 | 1438 |
| 1613 if (!pPages) | 1439 if (!pPages) |
| 1614 return FALSE; | 1440 return FALSE; |
| 1615 | 1441 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1628 int count = pPagesDict->GetIntegerBy("Count"); | 1454 int count = pPagesDict->GetIntegerBy("Count"); |
| 1629 if (count > 0) { | 1455 if (count > 0) { |
| 1630 pPages->Release(); | 1456 pPages->Release(); |
| 1631 return TRUE; | 1457 return TRUE; |
| 1632 } | 1458 } |
| 1633 | 1459 |
| 1634 pPages->Release(); | 1460 pPages->Release(); |
| 1635 return FALSE; | 1461 return FALSE; |
| 1636 } | 1462 } |
| 1637 | 1463 |
| 1638 FX_BOOL CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) { | 1464 FX_BOOL CPDF_DataAvail::LoadDocPages(IPDF_DataAvail::DownloadHints* pHints) { |
| 1639 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) | 1465 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) |
| 1640 return FALSE; | 1466 return FALSE; |
| 1641 | 1467 |
| 1642 if (CheckPageCount(pHints)) { | 1468 if (CheckPageCount(pHints)) { |
| 1643 m_docStatus = PDF_DATAAVAIL_PAGE; | 1469 m_docStatus = PDF_DATAAVAIL_PAGE; |
| 1644 return TRUE; | 1470 return TRUE; |
| 1645 } | 1471 } |
| 1646 | 1472 |
| 1647 m_bTotalLoadPageTree = TRUE; | 1473 m_bTotalLoadPageTree = TRUE; |
| 1648 return FALSE; | 1474 return FALSE; |
| 1649 } | 1475 } |
| 1650 | 1476 |
| 1651 FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) { | 1477 FX_BOOL CPDF_DataAvail::LoadPages(IPDF_DataAvail::DownloadHints* pHints) { |
| 1652 while (!m_bPagesTreeLoad) { | 1478 while (!m_bPagesTreeLoad) { |
| 1653 if (!CheckPageStatus(pHints)) | 1479 if (!CheckPageStatus(pHints)) |
| 1654 return FALSE; | 1480 return FALSE; |
| 1655 } | 1481 } |
| 1656 | 1482 |
| 1657 if (m_bPagesLoad) | 1483 if (m_bPagesLoad) |
| 1658 return TRUE; | 1484 return TRUE; |
| 1659 | 1485 |
| 1660 m_pDocument->LoadPages(); | 1486 m_pDocument->LoadPages(); |
| 1661 return FALSE; | 1487 return FALSE; |
| 1662 } | 1488 } |
| 1663 | 1489 |
| 1664 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( | 1490 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( |
| 1665 IFX_DownloadHints* pHints) { | 1491 IPDF_DataAvail::DownloadHints* pHints) { |
| 1666 if (m_bLinearedDataOK) | 1492 if (m_bLinearedDataOK) |
| 1667 return DataAvailable; | 1493 return DataAvailable; |
| 1668 | 1494 |
| 1669 if (!m_bMainXRefLoadTried) { | 1495 if (!m_bMainXRefLoadTried) { |
| 1670 FX_SAFE_DWORD data_size = m_dwFileLen; | 1496 FX_SAFE_DWORD data_size = m_dwFileLen; |
| 1671 data_size -= m_dwLastXRefOffset; | 1497 data_size -= m_dwLastXRefOffset; |
| 1672 if (!data_size.IsValid()) | 1498 if (!data_size.IsValid()) |
| 1673 return DataError; | 1499 return DataError; |
| 1674 | 1500 |
| 1675 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 1501 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1688 return DataNotAvailable; | 1514 return DataNotAvailable; |
| 1689 | 1515 |
| 1690 m_bMainXRefLoadedOK = TRUE; | 1516 m_bMainXRefLoadedOK = TRUE; |
| 1691 m_bLinearedDataOK = TRUE; | 1517 m_bLinearedDataOK = TRUE; |
| 1692 } | 1518 } |
| 1693 | 1519 |
| 1694 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; | 1520 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; |
| 1695 } | 1521 } |
| 1696 | 1522 |
| 1697 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, | 1523 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, |
| 1698 IFX_DownloadHints* pHints) { | 1524 IPDF_DataAvail::DownloadHints* pHints) { |
| 1699 if (!m_objs_array.GetSize()) { | 1525 if (!m_objs_array.GetSize()) { |
| 1700 m_objs_array.RemoveAll(); | 1526 m_objs_array.RemoveAll(); |
| 1701 m_ObjectSet.clear(); | 1527 m_ObjectSet.clear(); |
| 1702 | 1528 |
| 1703 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); | 1529 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); |
| 1704 if (!pPageDict) | 1530 if (!pPageDict) |
| 1705 return TRUE; | 1531 return TRUE; |
| 1706 | 1532 |
| 1707 CPDF_Object* pAnnots = pPageDict->GetElement("Annots"); | 1533 CPDF_Object* pAnnots = pPageDict->GetElement("Annots"); |
| 1708 if (!pAnnots) | 1534 if (!pAnnots) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1722 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1548 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); |
| 1723 m_objs_array.RemoveAll(); | 1549 m_objs_array.RemoveAll(); |
| 1724 if (!bRet) | 1550 if (!bRet) |
| 1725 m_objs_array.Append(new_objs_array); | 1551 m_objs_array.Append(new_objs_array); |
| 1726 | 1552 |
| 1727 return bRet; | 1553 return bRet; |
| 1728 } | 1554 } |
| 1729 | 1555 |
| 1730 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( | 1556 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( |
| 1731 int32_t iPage, | 1557 int32_t iPage, |
| 1732 IFX_DownloadHints* pHints) { | 1558 IPDF_DataAvail::DownloadHints* pHints) { |
| 1733 if (!m_bAnnotsLoad) { | 1559 if (!m_bAnnotsLoad) { |
| 1734 if (!CheckPageAnnots(iPage, pHints)) | 1560 if (!CheckPageAnnots(iPage, pHints)) |
| 1735 return DataNotAvailable; | 1561 return DataNotAvailable; |
| 1736 m_bAnnotsLoad = TRUE; | 1562 m_bAnnotsLoad = TRUE; |
| 1737 } | 1563 } |
| 1738 | 1564 |
| 1739 DocAvailStatus nRet = CheckLinearizedData(pHints); | 1565 DocAvailStatus nRet = CheckLinearizedData(pHints); |
| 1740 if (nRet == DataAvailable) | 1566 if (nRet == DataAvailable) |
| 1741 m_bPageLoadedOK = FALSE; | 1567 m_bPageLoadedOK = FALSE; |
| 1742 return nRet; | 1568 return nRet; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1759 if (pRet) { | 1585 if (pRet) { |
| 1760 m_pPageResource = pRet; | 1586 m_pPageResource = pRet; |
| 1761 return TRUE; | 1587 return TRUE; |
| 1762 } | 1588 } |
| 1763 | 1589 |
| 1764 return HaveResourceAncestor(pParentDict); | 1590 return HaveResourceAncestor(pParentDict); |
| 1765 } | 1591 } |
| 1766 | 1592 |
| 1767 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( | 1593 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( |
| 1768 int32_t iPage, | 1594 int32_t iPage, |
| 1769 IFX_DownloadHints* pHints) { | 1595 IPDF_DataAvail::DownloadHints* pHints) { |
| 1770 if (!m_pDocument) | 1596 if (!m_pDocument) |
| 1771 return DataError; | 1597 return DataError; |
| 1772 | 1598 |
| 1773 if (IsFirstCheck(iPage)) { | 1599 if (IsFirstCheck(iPage)) { |
| 1774 m_bCurPageDictLoadOK = FALSE; | 1600 m_bCurPageDictLoadOK = FALSE; |
| 1775 m_bPageLoadedOK = FALSE; | 1601 m_bPageLoadedOK = FALSE; |
| 1776 m_bAnnotsLoad = FALSE; | 1602 m_bAnnotsLoad = FALSE; |
| 1777 m_bNeedDownLoadResource = FALSE; | 1603 m_bNeedDownLoadResource = FALSE; |
| 1778 m_objs_array.RemoveAll(); | 1604 m_objs_array.RemoveAll(); |
| 1779 m_ObjectSet.clear(); | 1605 m_ObjectSet.clear(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 | 1711 |
| 1886 m_bPageLoadedOK = FALSE; | 1712 m_bPageLoadedOK = FALSE; |
| 1887 m_bAnnotsLoad = FALSE; | 1713 m_bAnnotsLoad = FALSE; |
| 1888 m_bCurPageDictLoadOK = FALSE; | 1714 m_bCurPageDictLoadOK = FALSE; |
| 1889 | 1715 |
| 1890 ResetFirstCheck(iPage); | 1716 ResetFirstCheck(iPage); |
| 1891 m_pagesLoadState.insert(iPage); | 1717 m_pagesLoadState.insert(iPage); |
| 1892 return DataAvailable; | 1718 return DataAvailable; |
| 1893 } | 1719 } |
| 1894 | 1720 |
| 1895 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) { | 1721 FX_BOOL CPDF_DataAvail::CheckResources(IPDF_DataAvail::DownloadHints* pHints) { |
| 1896 if (!m_objs_array.GetSize()) { | 1722 if (!m_objs_array.GetSize()) { |
| 1897 m_objs_array.RemoveAll(); | 1723 m_objs_array.RemoveAll(); |
| 1898 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 1724 CFX_ArrayTemplate<CPDF_Object*> obj_array; |
| 1899 obj_array.Add(m_pPageResource); | 1725 obj_array.Add(m_pPageResource); |
| 1900 | 1726 |
| 1901 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 1727 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); |
| 1902 if (bRet) | 1728 if (bRet) |
| 1903 m_objs_array.RemoveAll(); | 1729 m_objs_array.RemoveAll(); |
| 1904 return bRet; | 1730 return bRet; |
| 1905 } | 1731 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 | 1780 |
| 1955 if (!m_pDocument->InsertIndirectObject(dwObjNum, pPageDict)) | 1781 if (!m_pDocument->InsertIndirectObject(dwObjNum, pPageDict)) |
| 1956 return nullptr; | 1782 return nullptr; |
| 1957 return pPageDict->GetDict(); | 1783 return pPageDict->GetDict(); |
| 1958 } | 1784 } |
| 1959 } | 1785 } |
| 1960 return m_pDocument->GetPage(index); | 1786 return m_pDocument->GetPage(index); |
| 1961 } | 1787 } |
| 1962 | 1788 |
| 1963 IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( | 1789 IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( |
| 1964 IFX_DownloadHints* pHints) { | 1790 IPDF_DataAvail::DownloadHints* pHints) { |
| 1965 if (!m_pDocument) | 1791 if (!m_pDocument) |
| 1966 return FormAvailable; | 1792 return FormAvailable; |
| 1967 | 1793 |
| 1968 if (!m_bLinearizedFormParamLoad) { | 1794 if (!m_bLinearizedFormParamLoad) { |
| 1969 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 1795 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 1970 if (!pRoot) | 1796 if (!pRoot) |
| 1971 return FormAvailable; | 1797 return FormAvailable; |
| 1972 | 1798 |
| 1973 CPDF_Object* pAcroForm = pRoot->GetElement("AcroForm"); | 1799 CPDF_Object* pAcroForm = pRoot->GetElement("AcroForm"); |
| 1974 if (!pAcroForm) | 1800 if (!pAcroForm) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1988 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 1814 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; |
| 1989 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1815 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); |
| 1990 m_objs_array.RemoveAll(); | 1816 m_objs_array.RemoveAll(); |
| 1991 if (!bRet) { | 1817 if (!bRet) { |
| 1992 m_objs_array.Append(new_objs_array); | 1818 m_objs_array.Append(new_objs_array); |
| 1993 return FormNotAvailable; | 1819 return FormNotAvailable; |
| 1994 } | 1820 } |
| 1995 return FormAvailable; | 1821 return FormAvailable; |
| 1996 } | 1822 } |
| 1997 | 1823 |
| 1998 CPDF_PageNode::CPDF_PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1824 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
| 1999 | 1825 |
| 2000 CPDF_PageNode::~CPDF_PageNode() { | 1826 CPDF_DataAvail::PageNode::~PageNode() { |
| 2001 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1827 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
| 2002 delete m_childNode[i]; | 1828 delete m_childNode[i]; |
| 2003 m_childNode.RemoveAll(); | 1829 m_childNode.RemoveAll(); |
| 2004 } | 1830 } |
| 2005 | |
| 2006 CPDF_HintTables::~CPDF_HintTables() { | |
| 2007 m_dwDeltaNObjsArray.RemoveAll(); | |
| 2008 m_dwNSharedObjsArray.RemoveAll(); | |
| 2009 m_dwSharedObjNumArray.RemoveAll(); | |
| 2010 m_dwIdentifierArray.RemoveAll(); | |
| 2011 } | |
| 2012 | |
| 2013 FX_DWORD CPDF_HintTables::GetItemLength( | |
| 2014 int index, | |
| 2015 const std::vector<FX_FILESIZE>& szArray) { | |
| 2016 if (index < 0 || szArray.size() < 2 || | |
| 2017 static_cast<size_t>(index) > szArray.size() - 2 || | |
| 2018 szArray[index] > szArray[index + 1]) { | |
| 2019 return 0; | |
| 2020 } | |
| 2021 return szArray[index + 1] - szArray[index]; | |
| 2022 } | |
| 2023 | |
| 2024 FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { | |
| 2025 if (!hStream || hStream->IsEOF()) | |
| 2026 return FALSE; | |
| 2027 | |
| 2028 int nStreamOffset = ReadPrimaryHintStreamOffset(); | |
| 2029 int nStreamLen = ReadPrimaryHintStreamLength(); | |
| 2030 if (nStreamOffset < 0 || nStreamLen < 1) | |
| 2031 return FALSE; | |
| 2032 | |
| 2033 const FX_DWORD kHeaderSize = 288; | |
| 2034 if (hStream->BitsRemaining() < kHeaderSize) | |
| 2035 return FALSE; | |
| 2036 | |
| 2037 // Item 1: The least number of objects in a page. | |
| 2038 FX_DWORD dwObjLeastNum = hStream->GetBits(32); | |
| 2039 | |
| 2040 // Item 2: The location of the first page's page object. | |
| 2041 FX_DWORD dwFirstObjLoc = hStream->GetBits(32); | |
| 2042 if (dwFirstObjLoc > nStreamOffset) { | |
| 2043 FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<FX_DWORD>(nStreamLen); | |
| 2044 safeLoc += dwFirstObjLoc; | |
| 2045 if (!safeLoc.IsValid()) | |
| 2046 return FALSE; | |
| 2047 m_szFirstPageObjOffset = | |
| 2048 pdfium::base::checked_cast<FX_FILESIZE>(safeLoc.ValueOrDie()); | |
| 2049 } else { | |
| 2050 m_szFirstPageObjOffset = | |
| 2051 pdfium::base::checked_cast<FX_FILESIZE>(dwFirstObjLoc); | |
| 2052 } | |
| 2053 | |
| 2054 // Item 3: The number of bits needed to represent the difference | |
| 2055 // between the greatest and least number of objects in a page. | |
| 2056 FX_DWORD dwDeltaObjectsBits = hStream->GetBits(16); | |
| 2057 | |
| 2058 // Item 4: The least length of a page in bytes. | |
| 2059 FX_DWORD dwPageLeastLen = hStream->GetBits(32); | |
| 2060 | |
| 2061 // Item 5: The number of bits needed to represent the difference | |
| 2062 // between the greatest and least length of a page, in bytes. | |
| 2063 FX_DWORD dwDeltaPageLenBits = hStream->GetBits(16); | |
| 2064 | |
| 2065 // Skip Item 6, 7, 8, 9 total 96 bits. | |
| 2066 hStream->SkipBits(96); | |
| 2067 | |
| 2068 // Item 10: The number of bits needed to represent the greatest | |
| 2069 // number of shared object references. | |
| 2070 FX_DWORD dwSharedObjBits = hStream->GetBits(16); | |
| 2071 | |
| 2072 // Item 11: The number of bits needed to represent the numerically | |
| 2073 // greatest shared object identifier used by the pages. | |
| 2074 FX_DWORD dwSharedIdBits = hStream->GetBits(16); | |
| 2075 | |
| 2076 // Item 12: The number of bits needed to represent the numerator of | |
| 2077 // the fractional position for each shared object reference. For each | |
| 2078 // shared object referenced from a page, there is an indication of | |
| 2079 // where in the page's content stream the object is first referenced. | |
| 2080 FX_DWORD dwSharedNumeratorBits = hStream->GetBits(16); | |
| 2081 | |
| 2082 // Item 13: Skip Item 13 which has 16 bits. | |
| 2083 hStream->SkipBits(16); | |
| 2084 | |
| 2085 CPDF_Object* pPageNum = m_pLinearizedDict->GetElementValue("N"); | |
| 2086 int nPages = pPageNum ? pPageNum->GetInteger() : 0; | |
| 2087 if (nPages < 1) | |
| 2088 return FALSE; | |
| 2089 | |
| 2090 FX_SAFE_DWORD required_bits = dwDeltaObjectsBits; | |
| 2091 required_bits *= pdfium::base::checked_cast<FX_DWORD>(nPages); | |
| 2092 if (!CanReadFromBitStream(hStream, required_bits)) | |
| 2093 return FALSE; | |
| 2094 | |
| 2095 for (int i = 0; i < nPages; ++i) { | |
| 2096 FX_SAFE_DWORD safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits); | |
| 2097 safeDeltaObj += dwObjLeastNum; | |
| 2098 if (!safeDeltaObj.IsValid()) | |
| 2099 return FALSE; | |
| 2100 m_dwDeltaNObjsArray.Add(safeDeltaObj.ValueOrDie()); | |
| 2101 } | |
| 2102 hStream->ByteAlign(); | |
| 2103 | |
| 2104 required_bits = dwDeltaPageLenBits; | |
| 2105 required_bits *= pdfium::base::checked_cast<FX_DWORD>(nPages); | |
| 2106 if (!CanReadFromBitStream(hStream, required_bits)) | |
| 2107 return FALSE; | |
| 2108 | |
| 2109 CFX_DWordArray dwPageLenArray; | |
| 2110 for (int i = 0; i < nPages; ++i) { | |
| 2111 FX_SAFE_DWORD safePageLen = hStream->GetBits(dwDeltaPageLenBits); | |
| 2112 safePageLen += dwPageLeastLen; | |
| 2113 if (!safePageLen.IsValid()) | |
| 2114 return FALSE; | |
| 2115 dwPageLenArray.Add(safePageLen.ValueOrDie()); | |
| 2116 } | |
| 2117 | |
| 2118 CPDF_Object* pOffsetE = m_pLinearizedDict->GetElementValue("E"); | |
| 2119 int nOffsetE = pOffsetE ? pOffsetE->GetInteger() : -1; | |
| 2120 if (nOffsetE < 0) | |
| 2121 return FALSE; | |
| 2122 | |
| 2123 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetElementValue("P"); | |
| 2124 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0; | |
| 2125 for (int i = 0; i < nPages; ++i) { | |
| 2126 if (i == nFirstPageNum) { | |
| 2127 m_szPageOffsetArray.push_back(m_szFirstPageObjOffset); | |
| 2128 } else if (i == nFirstPageNum + 1) { | |
| 2129 if (i == 1) { | |
| 2130 m_szPageOffsetArray.push_back(nOffsetE); | |
| 2131 } else { | |
| 2132 m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 2] + | |
| 2133 dwPageLenArray[i - 2]); | |
| 2134 } | |
| 2135 } else { | |
| 2136 if (i == 0) { | |
| 2137 m_szPageOffsetArray.push_back(nOffsetE); | |
| 2138 } else { | |
| 2139 m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 1] + | |
| 2140 dwPageLenArray[i - 1]); | |
| 2141 } | |
| 2142 } | |
| 2143 } | |
| 2144 | |
| 2145 if (nPages > 0) { | |
| 2146 m_szPageOffsetArray.push_back(m_szPageOffsetArray[nPages - 1] + | |
| 2147 dwPageLenArray[nPages - 1]); | |
| 2148 } | |
| 2149 hStream->ByteAlign(); | |
| 2150 | |
| 2151 // Number of shared objects. | |
| 2152 required_bits = dwSharedObjBits; | |
| 2153 required_bits *= pdfium::base::checked_cast<FX_DWORD>(nPages); | |
| 2154 if (!CanReadFromBitStream(hStream, required_bits)) | |
| 2155 return FALSE; | |
| 2156 | |
| 2157 for (int i = 0; i < nPages; i++) | |
| 2158 m_dwNSharedObjsArray.Add(hStream->GetBits(dwSharedObjBits)); | |
| 2159 hStream->ByteAlign(); | |
| 2160 | |
| 2161 // Array of identifiers, size = nshared_objects. | |
| 2162 for (int i = 0; i < nPages; i++) { | |
| 2163 required_bits = dwSharedIdBits; | |
| 2164 required_bits *= m_dwNSharedObjsArray[i]; | |
| 2165 if (!CanReadFromBitStream(hStream, required_bits)) | |
| 2166 return FALSE; | |
| 2167 | |
| 2168 for (int j = 0; j < m_dwNSharedObjsArray[i]; j++) | |
| 2169 m_dwIdentifierArray.Add(hStream->GetBits(dwSharedIdBits)); | |
| 2170 } | |
| 2171 hStream->ByteAlign(); | |
| 2172 | |
| 2173 for (int i = 0; i < nPages; i++) { | |
| 2174 FX_SAFE_DWORD safeSize = m_dwNSharedObjsArray[i]; | |
| 2175 safeSize *= dwSharedNumeratorBits; | |
| 2176 if (!CanReadFromBitStream(hStream, safeSize)) | |
| 2177 return FALSE; | |
| 2178 | |
| 2179 hStream->SkipBits(safeSize.ValueOrDie()); | |
| 2180 } | |
| 2181 hStream->ByteAlign(); | |
| 2182 | |
| 2183 FX_SAFE_DWORD safeTotalPageLen = pdfium::base::checked_cast<FX_DWORD>(nPages); | |
| 2184 safeTotalPageLen *= dwDeltaPageLenBits; | |
| 2185 if (!CanReadFromBitStream(hStream, safeTotalPageLen)) | |
| 2186 return FALSE; | |
| 2187 | |
| 2188 hStream->SkipBits(safeTotalPageLen.ValueOrDie()); | |
| 2189 hStream->ByteAlign(); | |
| 2190 return TRUE; | |
| 2191 } | |
| 2192 | |
| 2193 FX_BOOL CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, | |
| 2194 FX_DWORD offset) { | |
| 2195 if (!hStream || hStream->IsEOF()) | |
| 2196 return FALSE; | |
| 2197 | |
| 2198 int nStreamOffset = ReadPrimaryHintStreamOffset(); | |
| 2199 int nStreamLen = ReadPrimaryHintStreamLength(); | |
| 2200 if (nStreamOffset < 0 || nStreamLen < 1) | |
| 2201 return FALSE; | |
| 2202 | |
| 2203 FX_SAFE_DWORD bit_offset = offset; | |
| 2204 bit_offset *= 8; | |
| 2205 if (!bit_offset.IsValid() || hStream->GetPos() > bit_offset.ValueOrDie()) | |
| 2206 return FALSE; | |
| 2207 hStream->SkipBits(bit_offset.ValueOrDie() - hStream->GetPos()); | |
| 2208 | |
| 2209 const FX_DWORD kHeaderSize = 192; | |
| 2210 if (hStream->BitsRemaining() < kHeaderSize) | |
| 2211 return FALSE; | |
| 2212 | |
| 2213 // Item 1: The object number of the first object in the shared objects | |
| 2214 // section. | |
| 2215 FX_DWORD dwFirstSharedObjNum = hStream->GetBits(32); | |
| 2216 | |
| 2217 // Item 2: The location of the first object in the shared objects section. | |
| 2218 FX_DWORD dwFirstSharedObjLoc = hStream->GetBits(32); | |
| 2219 if (dwFirstSharedObjLoc > nStreamOffset) | |
| 2220 dwFirstSharedObjLoc += nStreamLen; | |
| 2221 | |
| 2222 // Item 3: The number of shared object entries for the first page. | |
| 2223 m_nFirstPageSharedObjs = hStream->GetBits(32); | |
| 2224 | |
| 2225 // Item 4: The number of shared object entries for the shared objects | |
| 2226 // section, including the number of shared object entries for the first page. | |
| 2227 FX_DWORD dwSharedObjTotal = hStream->GetBits(32); | |
| 2228 | |
| 2229 // Item 5: The number of bits needed to represent the greatest number of | |
| 2230 // objects in a shared object group. Skipped. | |
| 2231 hStream->SkipBits(16); | |
| 2232 | |
| 2233 // Item 6: The least length of a shared object group in bytes. | |
| 2234 FX_DWORD dwGroupLeastLen = hStream->GetBits(32); | |
| 2235 | |
| 2236 // Item 7: The number of bits needed to represent the difference between the | |
| 2237 // greatest and least length of a shared object group, in bytes. | |
| 2238 FX_DWORD dwDeltaGroupLen = hStream->GetBits(16); | |
| 2239 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); | |
| 2240 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | |
| 2241 if (nFirstPageObjNum < 0) | |
| 2242 return FALSE; | |
| 2243 | |
| 2244 FX_DWORD dwPrevObjLen = 0; | |
| 2245 FX_DWORD dwCurObjLen = 0; | |
| 2246 FX_SAFE_DWORD required_bits = dwSharedObjTotal; | |
| 2247 required_bits *= dwDeltaGroupLen; | |
| 2248 if (!CanReadFromBitStream(hStream, required_bits)) | |
| 2249 return FALSE; | |
| 2250 | |
| 2251 for (int i = 0; i < dwSharedObjTotal; ++i) { | |
| 2252 dwPrevObjLen = dwCurObjLen; | |
| 2253 FX_SAFE_DWORD safeObjLen = hStream->GetBits(dwDeltaGroupLen); | |
| 2254 safeObjLen += dwGroupLeastLen; | |
| 2255 if (!safeObjLen.IsValid()) | |
| 2256 return FALSE; | |
| 2257 | |
| 2258 dwCurObjLen = safeObjLen.ValueOrDie(); | |
| 2259 if (i < m_nFirstPageSharedObjs) { | |
| 2260 m_dwSharedObjNumArray.Add(nFirstPageObjNum + i); | |
| 2261 if (i == 0) | |
| 2262 m_szSharedObjOffsetArray.push_back(m_szFirstPageObjOffset); | |
| 2263 } else { | |
| 2264 FX_SAFE_DWORD safeObjNum = dwFirstSharedObjNum; | |
| 2265 safeObjNum += i - m_nFirstPageSharedObjs; | |
| 2266 if (!safeObjNum.IsValid()) | |
| 2267 return FALSE; | |
| 2268 | |
| 2269 m_dwSharedObjNumArray.Add(safeObjNum.ValueOrDie()); | |
| 2270 if (i == m_nFirstPageSharedObjs) { | |
| 2271 m_szSharedObjOffsetArray.push_back( | |
| 2272 pdfium::base::checked_cast<int32_t>(dwFirstSharedObjLoc)); | |
| 2273 } | |
| 2274 } | |
| 2275 | |
| 2276 if (i != 0 && i != m_nFirstPageSharedObjs) { | |
| 2277 FX_SAFE_INT32 safeLoc = pdfium::base::checked_cast<int32_t>(dwPrevObjLen); | |
| 2278 safeLoc += m_szSharedObjOffsetArray[i - 1]; | |
| 2279 if (!safeLoc.IsValid()) | |
| 2280 return FALSE; | |
| 2281 | |
| 2282 m_szSharedObjOffsetArray.push_back(safeLoc.ValueOrDie()); | |
| 2283 } | |
| 2284 } | |
| 2285 | |
| 2286 if (dwSharedObjTotal > 0) { | |
| 2287 FX_SAFE_INT32 safeLoc = pdfium::base::checked_cast<int32_t>(dwCurObjLen); | |
| 2288 safeLoc += m_szSharedObjOffsetArray[dwSharedObjTotal - 1]; | |
| 2289 if (!safeLoc.IsValid()) | |
| 2290 return FALSE; | |
| 2291 | |
| 2292 m_szSharedObjOffsetArray.push_back(safeLoc.ValueOrDie()); | |
| 2293 } | |
| 2294 | |
| 2295 hStream->ByteAlign(); | |
| 2296 if (hStream->BitsRemaining() < dwSharedObjTotal) | |
| 2297 return FALSE; | |
| 2298 | |
| 2299 hStream->SkipBits(dwSharedObjTotal); | |
| 2300 hStream->ByteAlign(); | |
| 2301 return TRUE; | |
| 2302 } | |
| 2303 | |
| 2304 FX_BOOL CPDF_HintTables::GetPagePos(int index, | |
| 2305 FX_FILESIZE& szPageStartPos, | |
| 2306 FX_FILESIZE& szPageLength, | |
| 2307 FX_DWORD& dwObjNum) { | |
| 2308 if (!m_pLinearizedDict) | |
| 2309 return FALSE; | |
| 2310 | |
| 2311 szPageStartPos = m_szPageOffsetArray[index]; | |
| 2312 szPageLength = GetItemLength(index, m_szPageOffsetArray); | |
| 2313 | |
| 2314 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetElementValue("P"); | |
| 2315 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0; | |
| 2316 | |
| 2317 CPDF_Object* pFirstPageObjNum = m_pLinearizedDict->GetElementValue("O"); | |
| 2318 if (!pFirstPageObjNum) | |
| 2319 return FALSE; | |
| 2320 | |
| 2321 int nFirstPageObjNum = pFirstPageObjNum->GetInteger(); | |
| 2322 if (index == nFirstPageNum) { | |
| 2323 dwObjNum = nFirstPageObjNum; | |
| 2324 return TRUE; | |
| 2325 } | |
| 2326 | |
| 2327 // The object number of remaining pages starts from 1. | |
| 2328 dwObjNum = 1; | |
| 2329 for (int i = 0; i < index; ++i) { | |
| 2330 if (i == nFirstPageNum) | |
| 2331 continue; | |
| 2332 dwObjNum += m_dwDeltaNObjsArray[i]; | |
| 2333 } | |
| 2334 return TRUE; | |
| 2335 } | |
| 2336 | |
| 2337 IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( | |
| 2338 int index, | |
| 2339 IFX_DownloadHints* pHints) { | |
| 2340 if (!m_pLinearizedDict || !pHints) | |
| 2341 return IPDF_DataAvail::DataError; | |
| 2342 | |
| 2343 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetElementValue("P"); | |
| 2344 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; | |
| 2345 if (index == nFirstAvailPage) | |
| 2346 return IPDF_DataAvail::DataAvailable; | |
| 2347 | |
| 2348 FX_DWORD dwLength = GetItemLength(index, m_szPageOffsetArray); | |
| 2349 // If two pages have the same offset, it should be treated as an error. | |
| 2350 if (!dwLength) | |
| 2351 return IPDF_DataAvail::DataError; | |
| 2352 | |
| 2353 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) | |
| 2354 return IPDF_DataAvail::DataNotAvailable; | |
| 2355 | |
| 2356 // Download data of shared objects in the page. | |
| 2357 FX_DWORD offset = 0; | |
| 2358 for (int i = 0; i < index; ++i) | |
| 2359 offset += m_dwNSharedObjsArray[i]; | |
| 2360 | |
| 2361 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); | |
| 2362 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | |
| 2363 if (nFirstPageObjNum < 0) | |
| 2364 return IPDF_DataAvail::DataError; | |
| 2365 | |
| 2366 FX_DWORD dwIndex = 0; | |
| 2367 FX_DWORD dwObjNum = 0; | |
| 2368 for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) { | |
| 2369 dwIndex = m_dwIdentifierArray[offset + j]; | |
| 2370 if (dwIndex >= m_dwSharedObjNumArray.GetSize()) | |
| 2371 return IPDF_DataAvail::DataNotAvailable; | |
| 2372 | |
| 2373 dwObjNum = m_dwSharedObjNumArray[dwIndex]; | |
| 2374 if (dwObjNum >= nFirstPageObjNum && | |
| 2375 dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) { | |
| 2376 continue; | |
| 2377 } | |
| 2378 | |
| 2379 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray); | |
| 2380 // If two objects have the same offset, it should be treated as an error. | |
| 2381 if (!dwLength) | |
| 2382 return IPDF_DataAvail::DataError; | |
| 2383 | |
| 2384 if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, | |
| 2385 pHints)) { | |
| 2386 return IPDF_DataAvail::DataNotAvailable; | |
| 2387 } | |
| 2388 } | |
| 2389 return IPDF_DataAvail::DataAvailable; | |
| 2390 } | |
| 2391 | |
| 2392 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { | |
| 2393 if (!pHintStream || !m_pLinearizedDict) | |
| 2394 return FALSE; | |
| 2395 | |
| 2396 CPDF_Dictionary* pDict = pHintStream->GetDict(); | |
| 2397 CPDF_Object* pOffset = pDict ? pDict->GetElement("S") : nullptr; | |
| 2398 if (!pOffset || !pOffset->IsNumber()) | |
| 2399 return FALSE; | |
| 2400 | |
| 2401 int shared_hint_table_offset = pOffset->GetInteger(); | |
| 2402 CPDF_StreamAcc acc; | |
| 2403 acc.LoadAllData(pHintStream); | |
| 2404 | |
| 2405 FX_DWORD size = acc.GetSize(); | |
| 2406 // The header section of page offset hint table is 36 bytes. | |
| 2407 // The header section of shared object hint table is 24 bytes. | |
| 2408 // Hint table has at least 60 bytes. | |
| 2409 const FX_DWORD MIN_STREAM_LEN = 60; | |
| 2410 if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || | |
| 2411 size < shared_hint_table_offset) { | |
| 2412 return FALSE; | |
| 2413 } | |
| 2414 | |
| 2415 CFX_BitStream bs; | |
| 2416 bs.Init(acc.GetData(), size); | |
| 2417 return ReadPageHintTable(&bs) && | |
| 2418 ReadSharedObjHintTable(&bs, pdfium::base::checked_cast<FX_DWORD>( | |
| 2419 shared_hint_table_offset)); | |
| 2420 } | |
| 2421 | |
| 2422 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { | |
| 2423 if (!m_pLinearizedDict) | |
| 2424 return -1; | |
| 2425 | |
| 2426 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | |
| 2427 if (!pRange) | |
| 2428 return -1; | |
| 2429 | |
| 2430 CPDF_Object* pStreamOffset = pRange->GetElementValue(0); | |
| 2431 if (!pStreamOffset) | |
| 2432 return -1; | |
| 2433 | |
| 2434 return pStreamOffset->GetInteger(); | |
| 2435 } | |
| 2436 | |
| 2437 int CPDF_HintTables::ReadPrimaryHintStreamLength() const { | |
| 2438 if (!m_pLinearizedDict) | |
| 2439 return -1; | |
| 2440 | |
| 2441 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | |
| 2442 if (!pRange) | |
| 2443 return -1; | |
| 2444 | |
| 2445 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | |
| 2446 if (!pStreamLen) | |
| 2447 return -1; | |
| 2448 | |
| 2449 return pStreamLen->GetInteger(); | |
| 2450 } | |
| OLD | NEW |