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/parser/cpdf_data_avail.h" | 7 #include "core/fpdfapi/parser/cpdf_data_avail.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 CPDF_DataAvail::FileAvail::~FileAvail() {} | 27 CPDF_DataAvail::FileAvail::~FileAvail() {} |
28 | 28 |
29 CPDF_DataAvail::DownloadHints::~DownloadHints() {} | 29 CPDF_DataAvail::DownloadHints::~DownloadHints() {} |
30 | 30 |
31 // static | 31 // static |
32 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; | 32 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; |
33 | 33 |
34 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, | 34 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, |
35 IFX_SeekableReadStream* pFileRead, | 35 IFX_SeekableReadStream* pFileRead, |
36 FX_BOOL bSupportHintTable) | 36 bool bSupportHintTable) |
37 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { | 37 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { |
38 m_Pos = 0; | 38 m_Pos = 0; |
39 m_dwFileLen = 0; | 39 m_dwFileLen = 0; |
40 if (m_pFileRead) { | 40 if (m_pFileRead) { |
41 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); | 41 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
42 } | 42 } |
43 m_dwCurrentOffset = 0; | 43 m_dwCurrentOffset = 0; |
44 m_dwXRefOffset = 0; | 44 m_dwXRefOffset = 0; |
45 m_bufferOffset = 0; | 45 m_bufferOffset = 0; |
46 m_dwFirstPageNo = 0; | 46 m_dwFirstPageNo = 0; |
47 m_bufferSize = 0; | 47 m_bufferSize = 0; |
48 m_PagesObjNum = 0; | 48 m_PagesObjNum = 0; |
49 m_dwCurrentXRefSteam = 0; | 49 m_dwCurrentXRefSteam = 0; |
50 m_dwAcroFormObjNum = 0; | 50 m_dwAcroFormObjNum = 0; |
51 m_dwInfoObjNum = 0; | 51 m_dwInfoObjNum = 0; |
52 m_pDocument = 0; | 52 m_pDocument = 0; |
53 m_dwEncryptObjNum = 0; | 53 m_dwEncryptObjNum = 0; |
54 m_dwPrevXRefOffset = 0; | 54 m_dwPrevXRefOffset = 0; |
55 m_dwLastXRefOffset = 0; | 55 m_dwLastXRefOffset = 0; |
56 m_bDocAvail = FALSE; | 56 m_bDocAvail = false; |
57 m_bMainXRefLoadTried = FALSE; | 57 m_bMainXRefLoadTried = false; |
58 m_bDocAvail = FALSE; | 58 m_bDocAvail = false; |
59 m_bLinearized = FALSE; | 59 m_bLinearized = false; |
60 m_bPagesLoad = FALSE; | 60 m_bPagesLoad = false; |
61 m_bPagesTreeLoad = FALSE; | 61 m_bPagesTreeLoad = false; |
62 m_bMainXRefLoadedOK = FALSE; | 62 m_bMainXRefLoadedOK = false; |
63 m_bAnnotsLoad = FALSE; | 63 m_bAnnotsLoad = false; |
64 m_bHaveAcroForm = FALSE; | 64 m_bHaveAcroForm = false; |
65 m_bAcroFormLoad = FALSE; | 65 m_bAcroFormLoad = false; |
66 m_bPageLoadedOK = FALSE; | 66 m_bPageLoadedOK = false; |
67 m_bNeedDownLoadResource = FALSE; | 67 m_bNeedDownLoadResource = false; |
68 m_bLinearizedFormParamLoad = FALSE; | 68 m_bLinearizedFormParamLoad = false; |
69 m_pLinearized = nullptr; | 69 m_pLinearized = nullptr; |
70 m_pRoot = nullptr; | 70 m_pRoot = nullptr; |
71 m_pTrailer = nullptr; | 71 m_pTrailer = nullptr; |
72 m_pCurrentParser = nullptr; | 72 m_pCurrentParser = nullptr; |
73 m_pAcroForm = nullptr; | 73 m_pAcroForm = nullptr; |
74 m_pPageDict = nullptr; | 74 m_pPageDict = nullptr; |
75 m_pPageResource = nullptr; | 75 m_pPageResource = nullptr; |
76 m_docStatus = PDF_DATAAVAIL_HEADER; | 76 m_docStatus = PDF_DATAAVAIL_HEADER; |
77 m_parser.m_bOwnFileRead = false; | 77 m_parser.m_bOwnFileRead = false; |
78 m_bTotalLoadPageTree = FALSE; | 78 m_bTotalLoadPageTree = false; |
79 m_bCurPageDictLoadOK = FALSE; | 79 m_bCurPageDictLoadOK = false; |
80 m_bLinearedDataOK = FALSE; | 80 m_bLinearedDataOK = false; |
81 m_bSupportHintTable = bSupportHintTable; | 81 m_bSupportHintTable = bSupportHintTable; |
82 } | 82 } |
83 | 83 |
84 CPDF_DataAvail::~CPDF_DataAvail() { | 84 CPDF_DataAvail::~CPDF_DataAvail() { |
85 m_pHintTables.reset(); | 85 m_pHintTables.reset(); |
86 if (m_pLinearized) | 86 if (m_pLinearized) |
87 m_pLinearized->Release(); | 87 m_pLinearized->Release(); |
88 | 88 |
89 if (m_pRoot) | 89 if (m_pRoot) |
90 m_pRoot->Release(); | 90 m_pRoot->Release(); |
(...skipping 27 matching lines...) Expand all Loading... |
118 return 0; | 118 return 0; |
119 | 119 |
120 auto it = pParser->m_SortedOffset.find(offset); | 120 auto it = pParser->m_SortedOffset.find(offset); |
121 if (it == pParser->m_SortedOffset.end() || | 121 if (it == pParser->m_SortedOffset.end() || |
122 ++it == pParser->m_SortedOffset.end()) { | 122 ++it == pParser->m_SortedOffset.end()) { |
123 return 0; | 123 return 0; |
124 } | 124 } |
125 return *it - offset; | 125 return *it - offset; |
126 } | 126 } |
127 | 127 |
128 FX_BOOL CPDF_DataAvail::AreObjectsAvailable( | 128 bool CPDF_DataAvail::AreObjectsAvailable(std::vector<CPDF_Object*>& obj_array, |
129 std::vector<CPDF_Object*>& obj_array, | 129 bool bParsePage, |
130 FX_BOOL bParsePage, | 130 DownloadHints* pHints, |
131 DownloadHints* pHints, | 131 std::vector<CPDF_Object*>& ret_array) { |
132 std::vector<CPDF_Object*>& ret_array) { | |
133 if (obj_array.empty()) | 132 if (obj_array.empty()) |
134 return TRUE; | 133 return true; |
135 | 134 |
136 uint32_t count = 0; | 135 uint32_t count = 0; |
137 std::vector<CPDF_Object*> new_obj_array; | 136 std::vector<CPDF_Object*> new_obj_array; |
138 for (CPDF_Object* pObj : obj_array) { | 137 for (CPDF_Object* pObj : obj_array) { |
139 if (!pObj) | 138 if (!pObj) |
140 continue; | 139 continue; |
141 | 140 |
142 int32_t type = pObj->GetType(); | 141 int32_t type = pObj->GetType(); |
143 switch (type) { | 142 switch (type) { |
144 case CPDF_Object::ARRAY: { | 143 case CPDF_Object::ARRAY: { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 182 } |
184 } | 183 } |
185 | 184 |
186 if (count > 0) { | 185 if (count > 0) { |
187 for (CPDF_Object* pObj : new_obj_array) { | 186 for (CPDF_Object* pObj : new_obj_array) { |
188 CPDF_Reference* pRef = pObj->AsReference(); | 187 CPDF_Reference* pRef = pObj->AsReference(); |
189 if (pRef && pdfium::ContainsKey(m_ObjectSet, pRef->GetRefObjNum())) | 188 if (pRef && pdfium::ContainsKey(m_ObjectSet, pRef->GetRefObjNum())) |
190 continue; | 189 continue; |
191 ret_array.push_back(pObj); | 190 ret_array.push_back(pObj); |
192 } | 191 } |
193 return FALSE; | 192 return false; |
194 } | 193 } |
195 | 194 |
196 obj_array = new_obj_array; | 195 obj_array = new_obj_array; |
197 return AreObjectsAvailable(obj_array, FALSE, pHints, ret_array); | 196 return AreObjectsAvailable(obj_array, false, pHints, ret_array); |
198 } | 197 } |
199 | 198 |
200 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( | 199 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( |
201 DownloadHints* pHints) { | 200 DownloadHints* pHints) { |
202 if (!m_dwFileLen && m_pFileRead) { | 201 if (!m_dwFileLen && m_pFileRead) { |
203 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); | 202 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
204 if (!m_dwFileLen) | 203 if (!m_dwFileLen) |
205 return DataError; | 204 return DataError; |
206 } | 205 } |
207 | 206 |
208 while (!m_bDocAvail) { | 207 while (!m_bDocAvail) { |
209 if (!CheckDocStatus(pHints)) | 208 if (!CheckDocStatus(pHints)) |
210 return DataNotAvailable; | 209 return DataNotAvailable; |
211 } | 210 } |
212 | 211 |
213 return DataAvailable; | 212 return DataAvailable; |
214 } | 213 } |
215 | 214 |
216 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) { | 215 bool CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) { |
217 if (m_objs_array.empty()) { | 216 if (m_objs_array.empty()) { |
218 m_ObjectSet.clear(); | 217 m_ObjectSet.clear(); |
219 std::vector<CPDF_Object*> obj_array = m_arrayAcroforms; | 218 std::vector<CPDF_Object*> obj_array = m_arrayAcroforms; |
220 if (!AreObjectsAvailable(obj_array, FALSE, pHints, m_objs_array)) | 219 if (!AreObjectsAvailable(obj_array, false, pHints, m_objs_array)) |
221 return FALSE; | 220 return false; |
222 | 221 |
223 m_objs_array.clear(); | 222 m_objs_array.clear(); |
224 return TRUE; | 223 return true; |
225 } | 224 } |
226 | 225 |
227 std::vector<CPDF_Object*> new_objs_array; | 226 std::vector<CPDF_Object*> new_objs_array; |
228 if (!AreObjectsAvailable(m_objs_array, FALSE, pHints, new_objs_array)) { | 227 if (!AreObjectsAvailable(m_objs_array, false, pHints, new_objs_array)) { |
229 m_objs_array = new_objs_array; | 228 m_objs_array = new_objs_array; |
230 return FALSE; | 229 return false; |
231 } | 230 } |
232 | 231 |
233 for (CPDF_Object* pObject : m_arrayAcroforms) | 232 for (CPDF_Object* pObject : m_arrayAcroforms) |
234 pObject->Release(); | 233 pObject->Release(); |
235 | 234 |
236 m_arrayAcroforms.clear(); | 235 m_arrayAcroforms.clear(); |
237 return TRUE; | 236 return true; |
238 } | 237 } |
239 | 238 |
240 FX_BOOL CPDF_DataAvail::CheckAcroForm(DownloadHints* pHints) { | 239 bool CPDF_DataAvail::CheckAcroForm(DownloadHints* pHints) { |
241 FX_BOOL bExist = FALSE; | 240 bool bExist = false; |
242 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 241 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); |
243 if (!bExist) { | 242 if (!bExist) { |
244 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 243 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
245 return TRUE; | 244 return true; |
246 } | 245 } |
247 | 246 |
248 if (!m_pAcroForm) { | 247 if (!m_pAcroForm) { |
249 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 248 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
250 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 249 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
251 return TRUE; | 250 return true; |
252 } | 251 } |
253 return FALSE; | 252 return false; |
254 } | 253 } |
255 | 254 |
256 m_arrayAcroforms.push_back(m_pAcroForm); | 255 m_arrayAcroforms.push_back(m_pAcroForm); |
257 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 256 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
258 return TRUE; | 257 return true; |
259 } | 258 } |
260 | 259 |
261 FX_BOOL CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { | 260 bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { |
262 switch (m_docStatus) { | 261 switch (m_docStatus) { |
263 case PDF_DATAAVAIL_HEADER: | 262 case PDF_DATAAVAIL_HEADER: |
264 return CheckHeader(pHints); | 263 return CheckHeader(pHints); |
265 case PDF_DATAAVAIL_FIRSTPAGE: | 264 case PDF_DATAAVAIL_FIRSTPAGE: |
266 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: | 265 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: |
267 return CheckFirstPage(pHints); | 266 return CheckFirstPage(pHints); |
268 case PDF_DATAAVAIL_HINTTABLE: | 267 case PDF_DATAAVAIL_HINTTABLE: |
269 return CheckHintTables(pHints); | 268 return CheckHintTables(pHints); |
270 case PDF_DATAAVAIL_END: | 269 case PDF_DATAAVAIL_END: |
271 return CheckEnd(pHints); | 270 return CheckEnd(pHints); |
(...skipping 18 matching lines...) Expand all Loading... |
290 case PDF_DATAAVAIL_ACROFORM: | 289 case PDF_DATAAVAIL_ACROFORM: |
291 return CheckAcroForm(pHints); | 290 return CheckAcroForm(pHints); |
292 case PDF_DATAAVAIL_PAGETREE: | 291 case PDF_DATAAVAIL_PAGETREE: |
293 if (m_bTotalLoadPageTree) | 292 if (m_bTotalLoadPageTree) |
294 return CheckPages(pHints); | 293 return CheckPages(pHints); |
295 return LoadDocPages(pHints); | 294 return LoadDocPages(pHints); |
296 case PDF_DATAAVAIL_PAGE: | 295 case PDF_DATAAVAIL_PAGE: |
297 if (m_bTotalLoadPageTree) | 296 if (m_bTotalLoadPageTree) |
298 return CheckPage(pHints); | 297 return CheckPage(pHints); |
299 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; | 298 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; |
300 return TRUE; | 299 return true; |
301 case PDF_DATAAVAIL_ERROR: | 300 case PDF_DATAAVAIL_ERROR: |
302 return LoadAllFile(pHints); | 301 return LoadAllFile(pHints); |
303 case PDF_DATAAVAIL_PAGE_LATERLOAD: | 302 case PDF_DATAAVAIL_PAGE_LATERLOAD: |
304 m_docStatus = PDF_DATAAVAIL_PAGE; | 303 m_docStatus = PDF_DATAAVAIL_PAGE; |
305 default: | 304 default: |
306 m_bDocAvail = TRUE; | 305 m_bDocAvail = true; |
307 return TRUE; | 306 return true; |
308 } | 307 } |
309 } | 308 } |
310 | 309 |
311 FX_BOOL CPDF_DataAvail::CheckPageStatus(DownloadHints* pHints) { | 310 bool CPDF_DataAvail::CheckPageStatus(DownloadHints* pHints) { |
312 switch (m_docStatus) { | 311 switch (m_docStatus) { |
313 case PDF_DATAAVAIL_PAGETREE: | 312 case PDF_DATAAVAIL_PAGETREE: |
314 return CheckPages(pHints); | 313 return CheckPages(pHints); |
315 case PDF_DATAAVAIL_PAGE: | 314 case PDF_DATAAVAIL_PAGE: |
316 return CheckPage(pHints); | 315 return CheckPage(pHints); |
317 case PDF_DATAAVAIL_ERROR: | 316 case PDF_DATAAVAIL_ERROR: |
318 return LoadAllFile(pHints); | 317 return LoadAllFile(pHints); |
319 default: | 318 default: |
320 m_bPagesTreeLoad = TRUE; | 319 m_bPagesTreeLoad = true; |
321 m_bPagesLoad = TRUE; | 320 m_bPagesLoad = true; |
322 return TRUE; | 321 return true; |
323 } | 322 } |
324 } | 323 } |
325 | 324 |
326 FX_BOOL CPDF_DataAvail::LoadAllFile(DownloadHints* pHints) { | 325 bool CPDF_DataAvail::LoadAllFile(DownloadHints* pHints) { |
327 if (m_pFileAvail->IsDataAvail(0, (uint32_t)m_dwFileLen)) { | 326 if (m_pFileAvail->IsDataAvail(0, (uint32_t)m_dwFileLen)) { |
328 m_docStatus = PDF_DATAAVAIL_DONE; | 327 m_docStatus = PDF_DATAAVAIL_DONE; |
329 return TRUE; | 328 return true; |
330 } | 329 } |
331 | 330 |
332 pHints->AddSegment(0, (uint32_t)m_dwFileLen); | 331 pHints->AddSegment(0, (uint32_t)m_dwFileLen); |
333 return FALSE; | 332 return false; |
334 } | 333 } |
335 | 334 |
336 FX_BOOL CPDF_DataAvail::LoadAllXref(DownloadHints* pHints) { | 335 bool CPDF_DataAvail::LoadAllXref(DownloadHints* pHints) { |
337 m_parser.m_pSyntax->InitParser(m_pFileRead, (uint32_t)m_dwHeaderOffset); | 336 m_parser.m_pSyntax->InitParser(m_pFileRead, (uint32_t)m_dwHeaderOffset); |
338 m_parser.m_bOwnFileRead = false; | 337 m_parser.m_bOwnFileRead = false; |
339 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && | 338 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && |
340 !m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) { | 339 !m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) { |
341 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 340 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
342 return FALSE; | 341 return false; |
343 } | 342 } |
344 | 343 |
345 m_dwRootObjNum = m_parser.GetRootObjNum(); | 344 m_dwRootObjNum = m_parser.GetRootObjNum(); |
346 m_dwInfoObjNum = m_parser.GetInfoObjNum(); | 345 m_dwInfoObjNum = m_parser.GetInfoObjNum(); |
347 m_pCurrentParser = &m_parser; | 346 m_pCurrentParser = &m_parser; |
348 m_docStatus = PDF_DATAAVAIL_ROOT; | 347 m_docStatus = PDF_DATAAVAIL_ROOT; |
349 return TRUE; | 348 return true; |
350 } | 349 } |
351 | 350 |
352 CPDF_Object* CPDF_DataAvail::GetObject(uint32_t objnum, | 351 CPDF_Object* CPDF_DataAvail::GetObject(uint32_t objnum, |
353 DownloadHints* pHints, | 352 DownloadHints* pHints, |
354 FX_BOOL* pExistInFile) { | 353 bool* pExistInFile) { |
355 CPDF_Object* pRet = nullptr; | 354 CPDF_Object* pRet = nullptr; |
356 uint32_t size = 0; | 355 uint32_t size = 0; |
357 FX_FILESIZE offset = 0; | 356 FX_FILESIZE offset = 0; |
358 CPDF_Parser* pParser = nullptr; | 357 CPDF_Parser* pParser = nullptr; |
359 | 358 |
360 if (pExistInFile) | 359 if (pExistInFile) |
361 *pExistInFile = TRUE; | 360 *pExistInFile = true; |
362 | 361 |
363 if (m_pDocument) { | 362 if (m_pDocument) { |
364 size = GetObjectSize(objnum, offset); | 363 size = GetObjectSize(objnum, offset); |
365 pParser = m_pDocument->GetParser(); | 364 pParser = m_pDocument->GetParser(); |
366 } else { | 365 } else { |
367 size = (uint32_t)m_parser.GetObjectSize(objnum); | 366 size = (uint32_t)m_parser.GetObjectSize(objnum); |
368 offset = m_parser.GetObjectOffset(objnum); | 367 offset = m_parser.GetObjectOffset(objnum); |
369 pParser = &m_parser; | 368 pParser = &m_parser; |
370 } | 369 } |
371 | 370 |
372 if (!IsDataAvail(offset, size, pHints)) | 371 if (!IsDataAvail(offset, size, pHints)) |
373 return nullptr; | 372 return nullptr; |
374 | 373 |
375 if (pParser) | 374 if (pParser) |
376 pRet = pParser->ParseIndirectObject(nullptr, objnum); | 375 pRet = pParser->ParseIndirectObject(nullptr, objnum); |
377 | 376 |
378 if (!pRet && pExistInFile) | 377 if (!pRet && pExistInFile) |
379 *pExistInFile = FALSE; | 378 *pExistInFile = false; |
380 | 379 |
381 return pRet; | 380 return pRet; |
382 } | 381 } |
383 | 382 |
384 FX_BOOL CPDF_DataAvail::CheckInfo(DownloadHints* pHints) { | 383 bool CPDF_DataAvail::CheckInfo(DownloadHints* pHints) { |
385 FX_BOOL bExist = FALSE; | 384 bool bExist = false; |
386 CPDF_Object* pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); | 385 CPDF_Object* pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); |
387 if (!bExist) { | 386 if (!bExist) { |
388 m_docStatus = | 387 m_docStatus = |
389 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); | 388 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); |
390 return TRUE; | 389 return true; |
391 } | 390 } |
392 | 391 |
393 if (!pInfo) { | 392 if (!pInfo) { |
394 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 393 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
395 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 394 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
396 return TRUE; | 395 return true; |
397 } | 396 } |
398 | 397 |
399 if (m_Pos == m_dwFileLen) | 398 if (m_Pos == m_dwFileLen) |
400 m_docStatus = PDF_DATAAVAIL_ERROR; | 399 m_docStatus = PDF_DATAAVAIL_ERROR; |
401 return FALSE; | 400 return false; |
402 } | 401 } |
403 | 402 |
404 if (pInfo) | 403 if (pInfo) |
405 pInfo->Release(); | 404 pInfo->Release(); |
406 | 405 |
407 m_docStatus = | 406 m_docStatus = |
408 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); | 407 (m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE); |
409 | 408 |
410 return TRUE; | 409 return true; |
411 } | 410 } |
412 | 411 |
413 FX_BOOL CPDF_DataAvail::CheckRoot(DownloadHints* pHints) { | 412 bool CPDF_DataAvail::CheckRoot(DownloadHints* pHints) { |
414 FX_BOOL bExist = FALSE; | 413 bool bExist = false; |
415 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); | 414 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); |
416 if (!bExist) { | 415 if (!bExist) { |
417 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 416 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
418 return TRUE; | 417 return true; |
419 } | 418 } |
420 | 419 |
421 if (!m_pRoot) { | 420 if (!m_pRoot) { |
422 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 421 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
423 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 422 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
424 return TRUE; | 423 return true; |
425 } | 424 } |
426 return FALSE; | 425 return false; |
427 } | 426 } |
428 | 427 |
429 CPDF_Dictionary* pDict = m_pRoot->GetDict(); | 428 CPDF_Dictionary* pDict = m_pRoot->GetDict(); |
430 if (!pDict) { | 429 if (!pDict) { |
431 m_docStatus = PDF_DATAAVAIL_ERROR; | 430 m_docStatus = PDF_DATAAVAIL_ERROR; |
432 return FALSE; | 431 return false; |
433 } | 432 } |
434 | 433 |
435 CPDF_Reference* pRef = ToReference(pDict->GetObjectFor("Pages")); | 434 CPDF_Reference* pRef = ToReference(pDict->GetObjectFor("Pages")); |
436 if (!pRef) { | 435 if (!pRef) { |
437 m_docStatus = PDF_DATAAVAIL_ERROR; | 436 m_docStatus = PDF_DATAAVAIL_ERROR; |
438 return FALSE; | 437 return false; |
439 } | 438 } |
440 | 439 |
441 m_PagesObjNum = pRef->GetRefObjNum(); | 440 m_PagesObjNum = pRef->GetRefObjNum(); |
442 CPDF_Reference* pAcroFormRef = | 441 CPDF_Reference* pAcroFormRef = |
443 ToReference(m_pRoot->GetDict()->GetObjectFor("AcroForm")); | 442 ToReference(m_pRoot->GetDict()->GetObjectFor("AcroForm")); |
444 if (pAcroFormRef) { | 443 if (pAcroFormRef) { |
445 m_bHaveAcroForm = TRUE; | 444 m_bHaveAcroForm = true; |
446 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); | 445 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); |
447 } | 446 } |
448 | 447 |
449 if (m_dwInfoObjNum) { | 448 if (m_dwInfoObjNum) { |
450 m_docStatus = PDF_DATAAVAIL_INFO; | 449 m_docStatus = PDF_DATAAVAIL_INFO; |
451 } else { | 450 } else { |
452 m_docStatus = | 451 m_docStatus = |
453 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; | 452 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; |
454 } | 453 } |
455 return TRUE; | 454 return true; |
456 } | 455 } |
457 | 456 |
458 FX_BOOL CPDF_DataAvail::PreparePageItem() { | 457 bool CPDF_DataAvail::PreparePageItem() { |
459 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 458 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
460 CPDF_Reference* pRef = | 459 CPDF_Reference* pRef = |
461 ToReference(pRoot ? pRoot->GetObjectFor("Pages") : nullptr); | 460 ToReference(pRoot ? pRoot->GetObjectFor("Pages") : nullptr); |
462 if (!pRef) { | 461 if (!pRef) { |
463 m_docStatus = PDF_DATAAVAIL_ERROR; | 462 m_docStatus = PDF_DATAAVAIL_ERROR; |
464 return FALSE; | 463 return false; |
465 } | 464 } |
466 | 465 |
467 m_PagesObjNum = pRef->GetRefObjNum(); | 466 m_PagesObjNum = pRef->GetRefObjNum(); |
468 m_pCurrentParser = m_pDocument->GetParser(); | 467 m_pCurrentParser = m_pDocument->GetParser(); |
469 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 468 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
470 return TRUE; | 469 return true; |
471 } | 470 } |
472 | 471 |
473 bool CPDF_DataAvail::IsFirstCheck(uint32_t dwPage) { | 472 bool CPDF_DataAvail::IsFirstCheck(uint32_t dwPage) { |
474 return m_pageMapCheckState.insert(dwPage).second; | 473 return m_pageMapCheckState.insert(dwPage).second; |
475 } | 474 } |
476 | 475 |
477 void CPDF_DataAvail::ResetFirstCheck(uint32_t dwPage) { | 476 void CPDF_DataAvail::ResetFirstCheck(uint32_t dwPage) { |
478 m_pageMapCheckState.erase(dwPage); | 477 m_pageMapCheckState.erase(dwPage); |
479 } | 478 } |
480 | 479 |
481 FX_BOOL CPDF_DataAvail::CheckPage(DownloadHints* pHints) { | 480 bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { |
482 uint32_t iPageObjs = m_PageObjList.GetSize(); | 481 uint32_t iPageObjs = m_PageObjList.GetSize(); |
483 CFX_ArrayTemplate<uint32_t> UnavailObjList; | 482 CFX_ArrayTemplate<uint32_t> UnavailObjList; |
484 for (uint32_t i = 0; i < iPageObjs; ++i) { | 483 for (uint32_t i = 0; i < iPageObjs; ++i) { |
485 uint32_t dwPageObjNum = m_PageObjList.GetAt(i); | 484 uint32_t dwPageObjNum = m_PageObjList.GetAt(i); |
486 FX_BOOL bExist = FALSE; | 485 bool bExist = false; |
487 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); | 486 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); |
488 if (!pObj) { | 487 if (!pObj) { |
489 if (bExist) | 488 if (bExist) |
490 UnavailObjList.Add(dwPageObjNum); | 489 UnavailObjList.Add(dwPageObjNum); |
491 continue; | 490 continue; |
492 } | 491 } |
493 | 492 |
494 CPDF_Array* pArray = ToArray(pObj); | 493 CPDF_Array* pArray = ToArray(pObj); |
495 if (pArray) { | 494 if (pArray) { |
496 for (CPDF_Object* pArrayObj : *pArray) { | 495 for (CPDF_Object* pArrayObj : *pArray) { |
(...skipping 11 matching lines...) Expand all Loading... |
508 if (type == "Pages") { | 507 if (type == "Pages") { |
509 m_PagesArray.push_back(pObj); | 508 m_PagesArray.push_back(pObj); |
510 continue; | 509 continue; |
511 } | 510 } |
512 pObj->Release(); | 511 pObj->Release(); |
513 } | 512 } |
514 | 513 |
515 m_PageObjList.RemoveAll(); | 514 m_PageObjList.RemoveAll(); |
516 if (UnavailObjList.GetSize()) { | 515 if (UnavailObjList.GetSize()) { |
517 m_PageObjList.Append(UnavailObjList); | 516 m_PageObjList.Append(UnavailObjList); |
518 return FALSE; | 517 return false; |
519 } | 518 } |
520 | 519 |
521 uint32_t iPages = m_PagesArray.size(); | 520 uint32_t iPages = m_PagesArray.size(); |
522 for (uint32_t i = 0; i < iPages; i++) { | 521 for (uint32_t i = 0; i < iPages; i++) { |
523 CPDF_Object* pPages = m_PagesArray[i]; | 522 CPDF_Object* pPages = m_PagesArray[i]; |
524 if (!pPages) | 523 if (!pPages) |
525 continue; | 524 continue; |
526 | 525 |
527 if (!GetPageKids(m_pCurrentParser, pPages)) { | 526 if (!GetPageKids(m_pCurrentParser, pPages)) { |
528 pPages->Release(); | 527 pPages->Release(); |
529 while (++i < iPages) | 528 while (++i < iPages) |
530 m_PagesArray[i]->Release(); | 529 m_PagesArray[i]->Release(); |
531 | 530 |
532 m_PagesArray.clear(); | 531 m_PagesArray.clear(); |
533 m_docStatus = PDF_DATAAVAIL_ERROR; | 532 m_docStatus = PDF_DATAAVAIL_ERROR; |
534 return FALSE; | 533 return false; |
535 } | 534 } |
536 pPages->Release(); | 535 pPages->Release(); |
537 } | 536 } |
538 | 537 |
539 m_PagesArray.clear(); | 538 m_PagesArray.clear(); |
540 if (!m_PageObjList.GetSize()) | 539 if (!m_PageObjList.GetSize()) |
541 m_docStatus = PDF_DATAAVAIL_DONE; | 540 m_docStatus = PDF_DATAAVAIL_DONE; |
542 return TRUE; | 541 return true; |
543 } | 542 } |
544 | 543 |
545 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { | 544 bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { |
546 if (!pParser) { | 545 if (!pParser) { |
547 m_docStatus = PDF_DATAAVAIL_ERROR; | 546 m_docStatus = PDF_DATAAVAIL_ERROR; |
548 return FALSE; | 547 return false; |
549 } | 548 } |
550 | 549 |
551 CPDF_Dictionary* pDict = pPages->GetDict(); | 550 CPDF_Dictionary* pDict = pPages->GetDict(); |
552 CPDF_Object* pKids = pDict ? pDict->GetObjectFor("Kids") : nullptr; | 551 CPDF_Object* pKids = pDict ? pDict->GetObjectFor("Kids") : nullptr; |
553 if (!pKids) | 552 if (!pKids) |
554 return TRUE; | 553 return true; |
555 | 554 |
556 switch (pKids->GetType()) { | 555 switch (pKids->GetType()) { |
557 case CPDF_Object::REFERENCE: | 556 case CPDF_Object::REFERENCE: |
558 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); | 557 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); |
559 break; | 558 break; |
560 case CPDF_Object::ARRAY: { | 559 case CPDF_Object::ARRAY: { |
561 CPDF_Array* pKidsArray = pKids->AsArray(); | 560 CPDF_Array* pKidsArray = pKids->AsArray(); |
562 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { | 561 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { |
563 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) | 562 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) |
564 m_PageObjList.Add(pRef->GetRefObjNum()); | 563 m_PageObjList.Add(pRef->GetRefObjNum()); |
565 } | 564 } |
566 } break; | 565 } break; |
567 default: | 566 default: |
568 m_docStatus = PDF_DATAAVAIL_ERROR; | 567 m_docStatus = PDF_DATAAVAIL_ERROR; |
569 return FALSE; | 568 return false; |
570 } | 569 } |
571 return TRUE; | 570 return true; |
572 } | 571 } |
573 | 572 |
574 FX_BOOL CPDF_DataAvail::CheckPages(DownloadHints* pHints) { | 573 bool CPDF_DataAvail::CheckPages(DownloadHints* pHints) { |
575 FX_BOOL bExist = FALSE; | 574 bool bExist = false; |
576 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 575 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
577 if (!bExist) { | 576 if (!bExist) { |
578 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 577 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
579 return TRUE; | 578 return true; |
580 } | 579 } |
581 | 580 |
582 if (!pPages) { | 581 if (!pPages) { |
583 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 582 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
584 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 583 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
585 return TRUE; | 584 return true; |
586 } | 585 } |
587 return FALSE; | 586 return false; |
588 } | 587 } |
589 | 588 |
590 if (!GetPageKids(m_pCurrentParser, pPages)) { | 589 if (!GetPageKids(m_pCurrentParser, pPages)) { |
591 pPages->Release(); | 590 pPages->Release(); |
592 m_docStatus = PDF_DATAAVAIL_ERROR; | 591 m_docStatus = PDF_DATAAVAIL_ERROR; |
593 return FALSE; | 592 return false; |
594 } | 593 } |
595 | 594 |
596 pPages->Release(); | 595 pPages->Release(); |
597 m_docStatus = PDF_DATAAVAIL_PAGE; | 596 m_docStatus = PDF_DATAAVAIL_PAGE; |
598 return TRUE; | 597 return true; |
599 } | 598 } |
600 | 599 |
601 FX_BOOL CPDF_DataAvail::CheckHeader(DownloadHints* pHints) { | 600 bool CPDF_DataAvail::CheckHeader(DownloadHints* pHints) { |
602 ASSERT(m_dwFileLen >= 0); | 601 ASSERT(m_dwFileLen >= 0); |
603 const uint32_t kReqSize = std::min(static_cast<uint32_t>(m_dwFileLen), 1024U); | 602 const uint32_t kReqSize = std::min(static_cast<uint32_t>(m_dwFileLen), 1024U); |
604 | 603 |
605 if (m_pFileAvail->IsDataAvail(0, kReqSize)) { | 604 if (m_pFileAvail->IsDataAvail(0, kReqSize)) { |
606 uint8_t buffer[1024]; | 605 uint8_t buffer[1024]; |
607 m_pFileRead->ReadBlock(buffer, 0, kReqSize); | 606 m_pFileRead->ReadBlock(buffer, 0, kReqSize); |
608 | 607 |
609 if (IsLinearizedFile(buffer, kReqSize)) { | 608 if (IsLinearizedFile(buffer, kReqSize)) { |
610 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; | 609 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; |
611 } else { | 610 } else { |
612 if (m_docStatus == PDF_DATAAVAIL_ERROR) | 611 if (m_docStatus == PDF_DATAAVAIL_ERROR) |
613 return FALSE; | 612 return false; |
614 m_docStatus = PDF_DATAAVAIL_END; | 613 m_docStatus = PDF_DATAAVAIL_END; |
615 } | 614 } |
616 return TRUE; | 615 return true; |
617 } | 616 } |
618 | 617 |
619 pHints->AddSegment(0, kReqSize); | 618 pHints->AddSegment(0, kReqSize); |
620 return FALSE; | 619 return false; |
621 } | 620 } |
622 | 621 |
623 FX_BOOL CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { | 622 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { |
624 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 623 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
625 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr; | 624 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr; |
626 if (!pEndOffSet) { | 625 if (!pEndOffSet) { |
627 m_docStatus = PDF_DATAAVAIL_ERROR; | 626 m_docStatus = PDF_DATAAVAIL_ERROR; |
628 return FALSE; | 627 return false; |
629 } | 628 } |
630 | 629 |
631 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr; | 630 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr; |
632 if (!pXRefOffset) { | 631 if (!pXRefOffset) { |
633 m_docStatus = PDF_DATAAVAIL_ERROR; | 632 m_docStatus = PDF_DATAAVAIL_ERROR; |
634 return FALSE; | 633 return false; |
635 } | 634 } |
636 | 635 |
637 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr; | 636 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr; |
638 if (!pFileLen) { | 637 if (!pFileLen) { |
639 m_docStatus = PDF_DATAAVAIL_ERROR; | 638 m_docStatus = PDF_DATAAVAIL_ERROR; |
640 return FALSE; | 639 return false; |
641 } | 640 } |
642 | 641 |
643 FX_BOOL bNeedDownLoad = FALSE; | 642 bool bNeedDownLoad = false; |
644 if (pEndOffSet->IsNumber()) { | 643 if (pEndOffSet->IsNumber()) { |
645 uint32_t dwEnd = pEndOffSet->GetInteger(); | 644 uint32_t dwEnd = pEndOffSet->GetInteger(); |
646 dwEnd += 512; | 645 dwEnd += 512; |
647 if ((FX_FILESIZE)dwEnd > m_dwFileLen) | 646 if ((FX_FILESIZE)dwEnd > m_dwFileLen) |
648 dwEnd = (uint32_t)m_dwFileLen; | 647 dwEnd = (uint32_t)m_dwFileLen; |
649 | 648 |
650 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 649 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
651 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 650 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
652 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 651 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
653 pHints->AddSegment(iStartPos, iSize); | 652 pHints->AddSegment(iStartPos, iSize); |
654 bNeedDownLoad = TRUE; | 653 bNeedDownLoad = true; |
655 } | 654 } |
656 } | 655 } |
657 | 656 |
658 m_dwLastXRefOffset = 0; | 657 m_dwLastXRefOffset = 0; |
659 FX_FILESIZE dwFileLen = 0; | 658 FX_FILESIZE dwFileLen = 0; |
660 if (pXRefOffset->IsNumber()) | 659 if (pXRefOffset->IsNumber()) |
661 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | 660 m_dwLastXRefOffset = pXRefOffset->GetInteger(); |
662 | 661 |
663 if (pFileLen->IsNumber()) | 662 if (pFileLen->IsNumber()) |
664 dwFileLen = pFileLen->GetInteger(); | 663 dwFileLen = pFileLen->GetInteger(); |
665 | 664 |
666 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 665 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
667 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { | 666 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { |
668 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 667 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
669 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); | 668 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); |
670 FX_FILESIZE offset = m_dwLastXRefOffset; | 669 FX_FILESIZE offset = m_dwLastXRefOffset; |
671 if (dwSize < 512 && dwFileLen > 512) { | 670 if (dwSize < 512 && dwFileLen > 512) { |
672 dwSize = 512; | 671 dwSize = 512; |
673 offset = dwFileLen - 512; | 672 offset = dwFileLen - 512; |
674 } | 673 } |
675 pHints->AddSegment(offset, dwSize); | 674 pHints->AddSegment(offset, dwSize); |
676 } | 675 } |
677 } else { | 676 } else { |
678 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 677 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
679 } | 678 } |
680 | 679 |
681 if (bNeedDownLoad || m_docStatus != PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { | 680 if (bNeedDownLoad || m_docStatus != PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { |
682 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 681 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
683 return FALSE; | 682 return false; |
684 } | 683 } |
685 | 684 |
686 m_docStatus = | 685 m_docStatus = |
687 m_bSupportHintTable ? PDF_DATAAVAIL_HINTTABLE : PDF_DATAAVAIL_DONE; | 686 m_bSupportHintTable ? PDF_DATAAVAIL_HINTTABLE : PDF_DATAAVAIL_DONE; |
688 return TRUE; | 687 return true; |
689 } | 688 } |
690 | 689 |
691 FX_BOOL CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, | 690 bool CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, |
692 uint32_t size, | 691 uint32_t size, |
693 DownloadHints* pHints) { | 692 DownloadHints* pHints) { |
694 if (offset < 0 || offset > m_dwFileLen) | 693 if (offset < 0 || offset > m_dwFileLen) |
695 return TRUE; | 694 return true; |
696 | 695 |
697 FX_SAFE_FILESIZE safeSize = offset; | 696 FX_SAFE_FILESIZE safeSize = offset; |
698 safeSize += size; | 697 safeSize += size; |
699 safeSize += 512; | 698 safeSize += 512; |
700 if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) | 699 if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) |
701 size = m_dwFileLen - offset; | 700 size = m_dwFileLen - offset; |
702 else | 701 else |
703 size += 512; | 702 size += 512; |
704 | 703 |
705 if (!m_pFileAvail->IsDataAvail(offset, size)) { | 704 if (!m_pFileAvail->IsDataAvail(offset, size)) { |
706 pHints->AddSegment(offset, size); | 705 pHints->AddSegment(offset, size); |
707 return FALSE; | 706 return false; |
708 } | 707 } |
709 return TRUE; | 708 return true; |
710 } | 709 } |
711 | 710 |
712 FX_BOOL CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { | 711 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { |
713 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 712 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
714 if (!pDict) { | 713 if (!pDict) { |
715 m_docStatus = PDF_DATAAVAIL_ERROR; | 714 m_docStatus = PDF_DATAAVAIL_ERROR; |
716 return FALSE; | 715 return false; |
717 } | 716 } |
718 | 717 |
719 // The actual value is not required here, but validate its existence and type. | 718 // The actual value is not required here, but validate its existence and type. |
720 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O")); | 719 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O")); |
721 if (!pFirstPage || !pFirstPage->IsInteger()) { | 720 if (!pFirstPage || !pFirstPage->IsInteger()) { |
722 m_docStatus = PDF_DATAAVAIL_ERROR; | 721 m_docStatus = PDF_DATAAVAIL_ERROR; |
723 return FALSE; | 722 return false; |
724 } | 723 } |
725 | 724 |
726 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N")); | 725 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N")); |
727 if (!pPageCount || !pPageCount->IsInteger()) { | 726 if (!pPageCount || !pPageCount->IsInteger()) { |
728 m_docStatus = PDF_DATAAVAIL_ERROR; | 727 m_docStatus = PDF_DATAAVAIL_ERROR; |
729 return FALSE; | 728 return false; |
730 } | 729 } |
731 | 730 |
732 int nPageCount = pPageCount->GetInteger(); | 731 int nPageCount = pPageCount->GetInteger(); |
733 if (nPageCount <= 1) { | 732 if (nPageCount <= 1) { |
734 m_docStatus = PDF_DATAAVAIL_DONE; | 733 m_docStatus = PDF_DATAAVAIL_DONE; |
735 return TRUE; | 734 return true; |
736 } | 735 } |
737 | 736 |
738 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); | 737 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); |
739 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0; | 738 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0; |
740 if (nHintStreamSize != 2 && nHintStreamSize != 4) { | 739 if (nHintStreamSize != 2 && nHintStreamSize != 4) { |
741 m_docStatus = PDF_DATAAVAIL_ERROR; | 740 m_docStatus = PDF_DATAAVAIL_ERROR; |
742 return FALSE; | 741 return false; |
743 } | 742 } |
744 | 743 |
745 for (const CPDF_Object* pArrayObject : *pHintStreamRange) { | 744 for (const CPDF_Object* pArrayObject : *pHintStreamRange) { |
746 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect()); | 745 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect()); |
747 if (!pNumber || !pNumber->IsInteger()) { | 746 if (!pNumber || !pNumber->IsInteger()) { |
748 m_docStatus = PDF_DATAAVAIL_ERROR; | 747 m_docStatus = PDF_DATAAVAIL_ERROR; |
749 return FALSE; | 748 return false; |
750 } | 749 } |
751 } | 750 } |
752 | 751 |
753 FX_FILESIZE szHintStart = pHintStreamRange->GetIntegerAt(0); | 752 FX_FILESIZE szHintStart = pHintStreamRange->GetIntegerAt(0); |
754 FX_FILESIZE szHintLength = pHintStreamRange->GetIntegerAt(1); | 753 FX_FILESIZE szHintLength = pHintStreamRange->GetIntegerAt(1); |
755 if (szHintStart < 0 || szHintLength <= 0) { | 754 if (szHintStart < 0 || szHintLength <= 0) { |
756 m_docStatus = PDF_DATAAVAIL_ERROR; | 755 m_docStatus = PDF_DATAAVAIL_ERROR; |
757 return FALSE; | 756 return false; |
758 } | 757 } |
759 | 758 |
760 if (!IsDataAvail(szHintStart, szHintLength, pHints)) | 759 if (!IsDataAvail(szHintStart, szHintLength, pHints)) |
761 return FALSE; | 760 return false; |
762 | 761 |
763 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); | 762 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); |
764 | 763 |
765 std::unique_ptr<CPDF_HintTables> pHintTables( | 764 std::unique_ptr<CPDF_HintTables> pHintTables( |
766 new CPDF_HintTables(this, pDict)); | 765 new CPDF_HintTables(this, pDict)); |
767 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( | 766 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( |
768 ParseIndirectObjectAt(szHintStart, 0)); | 767 ParseIndirectObjectAt(szHintStart, 0)); |
769 CPDF_Stream* pStream = ToStream(pHintStream.get()); | 768 CPDF_Stream* pStream = ToStream(pHintStream.get()); |
770 if (pStream && pHintTables->LoadHintStream(pStream)) | 769 if (pStream && pHintTables->LoadHintStream(pStream)) |
771 m_pHintTables = std::move(pHintTables); | 770 m_pHintTables = std::move(pHintTables); |
772 | 771 |
773 m_docStatus = PDF_DATAAVAIL_DONE; | 772 m_docStatus = PDF_DATAAVAIL_DONE; |
774 return TRUE; | 773 return true; |
775 } | 774 } |
776 | 775 |
777 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( | 776 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( |
778 FX_FILESIZE pos, | 777 FX_FILESIZE pos, |
779 uint32_t objnum, | 778 uint32_t objnum, |
780 CPDF_IndirectObjectHolder* pObjList) { | 779 CPDF_IndirectObjectHolder* pObjList) { |
781 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 780 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
782 m_syntaxParser.RestorePos(pos); | 781 m_syntaxParser.RestorePos(pos); |
783 | 782 |
784 bool bIsNumber; | 783 bool bIsNumber; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 return LinearizationUnknown; | 818 return LinearizationUnknown; |
820 | 819 |
821 uint8_t buffer[1024]; | 820 uint8_t buffer[1024]; |
822 m_pFileRead->ReadBlock(buffer, 0, kReqSize); | 821 m_pFileRead->ReadBlock(buffer, 0, kReqSize); |
823 if (IsLinearizedFile(buffer, kReqSize)) | 822 if (IsLinearizedFile(buffer, kReqSize)) |
824 return Linearized; | 823 return Linearized; |
825 | 824 |
826 return NotLinearized; | 825 return NotLinearized; |
827 } | 826 } |
828 | 827 |
829 FX_BOOL CPDF_DataAvail::IsLinearized() { | 828 bool CPDF_DataAvail::IsLinearized() { |
830 return m_bLinearized; | 829 return m_bLinearized; |
831 } | 830 } |
832 | 831 |
833 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { | 832 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { |
834 if (m_pLinearized) | 833 if (m_pLinearized) |
835 return m_bLinearized; | 834 return m_bLinearized; |
836 | 835 |
837 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); | 836 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false)); |
838 | 837 |
839 int32_t offset = GetHeaderOffset(file.get()); | 838 int32_t offset = GetHeaderOffset(file.get()); |
840 if (offset == -1) { | 839 if (offset == -1) { |
841 m_docStatus = PDF_DATAAVAIL_ERROR; | 840 m_docStatus = PDF_DATAAVAIL_ERROR; |
842 return FALSE; | 841 return false; |
843 } | 842 } |
844 | 843 |
845 m_dwHeaderOffset = offset; | 844 m_dwHeaderOffset = offset; |
846 m_syntaxParser.InitParser(file.get(), offset); | 845 m_syntaxParser.InitParser(file.get(), offset); |
847 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 846 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
848 | 847 |
849 bool bNumber; | 848 bool bNumber; |
850 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); | 849 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); |
851 if (!bNumber) | 850 if (!bNumber) |
852 return FALSE; | 851 return false; |
853 | 852 |
854 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); | 853 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); |
855 m_pLinearized = | 854 m_pLinearized = |
856 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 855 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); |
857 if (!m_pLinearized) | 856 if (!m_pLinearized) |
858 return FALSE; | 857 return false; |
859 | 858 |
860 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 859 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
861 if (!pDict || !pDict->GetObjectFor("Linearized")) | 860 if (!pDict || !pDict->GetObjectFor("Linearized")) |
862 return FALSE; | 861 return false; |
863 | 862 |
864 CPDF_Object* pLen = pDict->GetObjectFor("L"); | 863 CPDF_Object* pLen = pDict->GetObjectFor("L"); |
865 if (!pLen) | 864 if (!pLen) |
866 return FALSE; | 865 return false; |
867 | 866 |
868 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) | 867 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) |
869 return FALSE; | 868 return false; |
870 | 869 |
871 m_bLinearized = TRUE; | 870 m_bLinearized = true; |
872 | 871 |
873 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) | 872 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) |
874 m_dwFirstPageNo = pNo->GetInteger(); | 873 m_dwFirstPageNo = pNo->GetInteger(); |
875 | 874 |
876 return TRUE; | 875 return true; |
877 } | 876 } |
878 | 877 |
879 FX_BOOL CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { | 878 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { |
880 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 879 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
881 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); | 880 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); |
882 | 881 |
883 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 882 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
884 uint8_t buffer[1024]; | 883 uint8_t buffer[1024]; |
885 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 884 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
886 | 885 |
887 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); | 886 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, false)); |
888 m_syntaxParser.InitParser(file.get(), 0); | 887 m_syntaxParser.InitParser(file.get(), 0); |
889 m_syntaxParser.RestorePos(dwSize - 1); | 888 m_syntaxParser.RestorePos(dwSize - 1); |
890 | 889 |
891 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { | 890 if (m_syntaxParser.SearchWord("startxref", true, false, dwSize)) { |
892 m_syntaxParser.GetNextWord(nullptr); | 891 m_syntaxParser.GetNextWord(nullptr); |
893 | 892 |
894 bool bNumber; | 893 bool bNumber; |
895 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(&bNumber); | 894 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(&bNumber); |
896 if (!bNumber) { | 895 if (!bNumber) { |
897 m_docStatus = PDF_DATAAVAIL_ERROR; | 896 m_docStatus = PDF_DATAAVAIL_ERROR; |
898 return FALSE; | 897 return false; |
899 } | 898 } |
900 | 899 |
901 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str.c_str()); | 900 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str.c_str()); |
902 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 901 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { |
903 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 902 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
904 return TRUE; | 903 return true; |
905 } | 904 } |
906 | 905 |
907 m_dwLastXRefOffset = m_dwXRefOffset; | 906 m_dwLastXRefOffset = m_dwXRefOffset; |
908 SetStartOffset(m_dwXRefOffset); | 907 SetStartOffset(m_dwXRefOffset); |
909 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 908 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
910 return TRUE; | 909 return true; |
911 } | 910 } |
912 | 911 |
913 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 912 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
914 return TRUE; | 913 return true; |
915 } | 914 } |
916 | 915 |
917 pHints->AddSegment(req_pos, dwSize); | 916 pHints->AddSegment(req_pos, dwSize); |
918 return FALSE; | 917 return false; |
919 } | 918 } |
920 | 919 |
921 int32_t CPDF_DataAvail::CheckCrossRefStream(DownloadHints* pHints, | 920 int32_t CPDF_DataAvail::CheckCrossRefStream(DownloadHints* pHints, |
922 FX_FILESIZE& xref_offset) { | 921 FX_FILESIZE& xref_offset) { |
923 xref_offset = 0; | 922 xref_offset = 0; |
924 uint32_t req_size = | 923 uint32_t req_size = |
925 (uint32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 924 (uint32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
926 | 925 |
927 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 926 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
928 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 927 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
929 CFX_BinaryBuf buf(iSize); | 928 CFX_BinaryBuf buf(iSize); |
930 uint8_t* pBuf = buf.GetBuffer(); | 929 uint8_t* pBuf = buf.GetBuffer(); |
931 | 930 |
932 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 931 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
933 | 932 |
934 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 933 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false)); |
935 m_parser.m_pSyntax->InitParser(file.get(), 0); | 934 m_parser.m_pSyntax->InitParser(file.get(), 0); |
936 | 935 |
937 bool bNumber; | 936 bool bNumber; |
938 CFX_ByteString objnum = m_parser.m_pSyntax->GetNextWord(&bNumber); | 937 CFX_ByteString objnum = m_parser.m_pSyntax->GetNextWord(&bNumber); |
939 if (!bNumber) | 938 if (!bNumber) |
940 return -1; | 939 return -1; |
941 | 940 |
942 uint32_t objNum = FXSYS_atoui(objnum.c_str()); | 941 uint32_t objNum = FXSYS_atoui(objnum.c_str()); |
943 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); | 942 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); |
944 if (!pObj) { | 943 if (!pObj) { |
(...skipping 15 matching lines...) Expand all Loading... |
960 return -1; | 959 return -1; |
961 } | 960 } |
962 pHints->AddSegment(m_Pos, req_size); | 961 pHints->AddSegment(m_Pos, req_size); |
963 return 0; | 962 return 0; |
964 } | 963 } |
965 | 964 |
966 void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) { | 965 void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) { |
967 m_Pos = dwOffset; | 966 m_Pos = dwOffset; |
968 } | 967 } |
969 | 968 |
970 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString& token) { | 969 bool CPDF_DataAvail::GetNextToken(CFX_ByteString& token) { |
971 uint8_t ch; | 970 uint8_t ch; |
972 if (!GetNextChar(ch)) | 971 if (!GetNextChar(ch)) |
973 return FALSE; | 972 return false; |
974 | 973 |
975 while (1) { | 974 while (1) { |
976 while (PDFCharIsWhitespace(ch)) { | 975 while (PDFCharIsWhitespace(ch)) { |
977 if (!GetNextChar(ch)) | 976 if (!GetNextChar(ch)) |
978 return FALSE; | 977 return false; |
979 } | 978 } |
980 | 979 |
981 if (ch != '%') | 980 if (ch != '%') |
982 break; | 981 break; |
983 | 982 |
984 while (1) { | 983 while (1) { |
985 if (!GetNextChar(ch)) | 984 if (!GetNextChar(ch)) |
986 return FALSE; | 985 return false; |
987 if (PDFCharIsLineEnding(ch)) | 986 if (PDFCharIsLineEnding(ch)) |
988 break; | 987 break; |
989 } | 988 } |
990 } | 989 } |
991 | 990 |
992 uint8_t buffer[256]; | 991 uint8_t buffer[256]; |
993 uint32_t index = 0; | 992 uint32_t index = 0; |
994 if (PDFCharIsDelimiter(ch)) { | 993 if (PDFCharIsDelimiter(ch)) { |
995 buffer[index++] = ch; | 994 buffer[index++] = ch; |
996 if (ch == '/') { | 995 if (ch == '/') { |
997 while (1) { | 996 while (1) { |
998 if (!GetNextChar(ch)) | 997 if (!GetNextChar(ch)) |
999 return FALSE; | 998 return false; |
1000 | 999 |
1001 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { | 1000 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { |
1002 m_Pos--; | 1001 m_Pos--; |
1003 CFX_ByteString ret(buffer, index); | 1002 CFX_ByteString ret(buffer, index); |
1004 token = ret; | 1003 token = ret; |
1005 return TRUE; | 1004 return true; |
1006 } | 1005 } |
1007 | 1006 |
1008 if (index < sizeof(buffer)) | 1007 if (index < sizeof(buffer)) |
1009 buffer[index++] = ch; | 1008 buffer[index++] = ch; |
1010 } | 1009 } |
1011 } else if (ch == '<') { | 1010 } else if (ch == '<') { |
1012 if (!GetNextChar(ch)) | 1011 if (!GetNextChar(ch)) |
1013 return FALSE; | 1012 return false; |
1014 | 1013 |
1015 if (ch == '<') | 1014 if (ch == '<') |
1016 buffer[index++] = ch; | 1015 buffer[index++] = ch; |
1017 else | 1016 else |
1018 m_Pos--; | 1017 m_Pos--; |
1019 } else if (ch == '>') { | 1018 } else if (ch == '>') { |
1020 if (!GetNextChar(ch)) | 1019 if (!GetNextChar(ch)) |
1021 return FALSE; | 1020 return false; |
1022 | 1021 |
1023 if (ch == '>') | 1022 if (ch == '>') |
1024 buffer[index++] = ch; | 1023 buffer[index++] = ch; |
1025 else | 1024 else |
1026 m_Pos--; | 1025 m_Pos--; |
1027 } | 1026 } |
1028 | 1027 |
1029 CFX_ByteString ret(buffer, index); | 1028 CFX_ByteString ret(buffer, index); |
1030 token = ret; | 1029 token = ret; |
1031 return TRUE; | 1030 return true; |
1032 } | 1031 } |
1033 | 1032 |
1034 while (1) { | 1033 while (1) { |
1035 if (index < sizeof(buffer)) | 1034 if (index < sizeof(buffer)) |
1036 buffer[index++] = ch; | 1035 buffer[index++] = ch; |
1037 | 1036 |
1038 if (!GetNextChar(ch)) | 1037 if (!GetNextChar(ch)) |
1039 return FALSE; | 1038 return false; |
1040 | 1039 |
1041 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { | 1040 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { |
1042 m_Pos--; | 1041 m_Pos--; |
1043 break; | 1042 break; |
1044 } | 1043 } |
1045 } | 1044 } |
1046 | 1045 |
1047 token = CFX_ByteString(buffer, index); | 1046 token = CFX_ByteString(buffer, index); |
1048 return TRUE; | 1047 return true; |
1049 } | 1048 } |
1050 | 1049 |
1051 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t& ch) { | 1050 bool CPDF_DataAvail::GetNextChar(uint8_t& ch) { |
1052 FX_FILESIZE pos = m_Pos; | 1051 FX_FILESIZE pos = m_Pos; |
1053 if (pos >= m_dwFileLen) | 1052 if (pos >= m_dwFileLen) |
1054 return FALSE; | 1053 return false; |
1055 | 1054 |
1056 if (m_bufferOffset >= pos || | 1055 if (m_bufferOffset >= pos || |
1057 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { | 1056 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { |
1058 FX_FILESIZE read_pos = pos; | 1057 FX_FILESIZE read_pos = pos; |
1059 uint32_t read_size = 512; | 1058 uint32_t read_size = 512; |
1060 if ((FX_FILESIZE)read_size > m_dwFileLen) | 1059 if ((FX_FILESIZE)read_size > m_dwFileLen) |
1061 read_size = (uint32_t)m_dwFileLen; | 1060 read_size = (uint32_t)m_dwFileLen; |
1062 | 1061 |
1063 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) | 1062 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) |
1064 read_pos = m_dwFileLen - read_size; | 1063 read_pos = m_dwFileLen - read_size; |
1065 | 1064 |
1066 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) | 1065 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) |
1067 return FALSE; | 1066 return false; |
1068 | 1067 |
1069 m_bufferOffset = read_pos; | 1068 m_bufferOffset = read_pos; |
1070 m_bufferSize = read_size; | 1069 m_bufferSize = read_size; |
1071 } | 1070 } |
1072 ch = m_bufferData[pos - m_bufferOffset]; | 1071 ch = m_bufferData[pos - m_bufferOffset]; |
1073 m_Pos++; | 1072 m_Pos++; |
1074 return TRUE; | 1073 return true; |
1075 } | 1074 } |
1076 | 1075 |
1077 FX_BOOL CPDF_DataAvail::CheckCrossRefItem(DownloadHints* pHints) { | 1076 bool CPDF_DataAvail::CheckCrossRefItem(DownloadHints* pHints) { |
1078 int32_t iSize = 0; | 1077 int32_t iSize = 0; |
1079 CFX_ByteString token; | 1078 CFX_ByteString token; |
1080 while (1) { | 1079 while (1) { |
1081 if (!GetNextToken(token)) { | 1080 if (!GetNextToken(token)) { |
1082 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1081 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
1083 pHints->AddSegment(m_Pos, iSize); | 1082 pHints->AddSegment(m_Pos, iSize); |
1084 return FALSE; | 1083 return false; |
1085 } | 1084 } |
1086 | 1085 |
1087 if (token == "trailer") { | 1086 if (token == "trailer") { |
1088 m_dwTrailerOffset = m_Pos; | 1087 m_dwTrailerOffset = m_Pos; |
1089 m_docStatus = PDF_DATAAVAIL_TRAILER; | 1088 m_docStatus = PDF_DATAAVAIL_TRAILER; |
1090 return TRUE; | 1089 return true; |
1091 } | 1090 } |
1092 } | 1091 } |
1093 } | 1092 } |
1094 | 1093 |
1095 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(DownloadHints* pHints) { | 1094 bool CPDF_DataAvail::CheckAllCrossRefStream(DownloadHints* pHints) { |
1096 FX_FILESIZE xref_offset = 0; | 1095 FX_FILESIZE xref_offset = 0; |
1097 | 1096 |
1098 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); | 1097 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); |
1099 if (nRet == 1) { | 1098 if (nRet == 1) { |
1100 if (!xref_offset) { | 1099 if (!xref_offset) { |
1101 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; | 1100 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; |
1102 } else { | 1101 } else { |
1103 m_dwCurrentXRefSteam = xref_offset; | 1102 m_dwCurrentXRefSteam = xref_offset; |
1104 m_Pos = xref_offset; | 1103 m_Pos = xref_offset; |
1105 } | 1104 } |
1106 return TRUE; | 1105 return true; |
1107 } | 1106 } |
1108 | 1107 |
1109 if (nRet == -1) | 1108 if (nRet == -1) |
1110 m_docStatus = PDF_DATAAVAIL_ERROR; | 1109 m_docStatus = PDF_DATAAVAIL_ERROR; |
1111 return FALSE; | 1110 return false; |
1112 } | 1111 } |
1113 | 1112 |
1114 FX_BOOL CPDF_DataAvail::CheckCrossRef(DownloadHints* pHints) { | 1113 bool CPDF_DataAvail::CheckCrossRef(DownloadHints* pHints) { |
1115 int32_t iSize = 0; | 1114 int32_t iSize = 0; |
1116 CFX_ByteString token; | 1115 CFX_ByteString token; |
1117 if (!GetNextToken(token)) { | 1116 if (!GetNextToken(token)) { |
1118 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1117 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
1119 pHints->AddSegment(m_Pos, iSize); | 1118 pHints->AddSegment(m_Pos, iSize); |
1120 return FALSE; | 1119 return false; |
1121 } | 1120 } |
1122 | 1121 |
1123 if (token == "xref") { | 1122 if (token == "xref") { |
1124 while (1) { | 1123 while (1) { |
1125 if (!GetNextToken(token)) { | 1124 if (!GetNextToken(token)) { |
1126 iSize = | 1125 iSize = |
1127 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1126 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
1128 pHints->AddSegment(m_Pos, iSize); | 1127 pHints->AddSegment(m_Pos, iSize); |
1129 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; | 1128 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; |
1130 return FALSE; | 1129 return false; |
1131 } | 1130 } |
1132 | 1131 |
1133 if (token == "trailer") { | 1132 if (token == "trailer") { |
1134 m_dwTrailerOffset = m_Pos; | 1133 m_dwTrailerOffset = m_Pos; |
1135 m_docStatus = PDF_DATAAVAIL_TRAILER; | 1134 m_docStatus = PDF_DATAAVAIL_TRAILER; |
1136 return TRUE; | 1135 return true; |
1137 } | 1136 } |
1138 } | 1137 } |
1139 } else { | 1138 } else { |
1140 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1139 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1141 return TRUE; | 1140 return true; |
1142 } | 1141 } |
1143 return FALSE; | 1142 return false; |
1144 } | 1143 } |
1145 | 1144 |
1146 FX_BOOL CPDF_DataAvail::CheckTrailerAppend(DownloadHints* pHints) { | 1145 bool CPDF_DataAvail::CheckTrailerAppend(DownloadHints* pHints) { |
1147 if (m_Pos < m_dwFileLen) { | 1146 if (m_Pos < m_dwFileLen) { |
1148 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); | 1147 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); |
1149 int32_t iSize = (int32_t)( | 1148 int32_t iSize = (int32_t)( |
1150 dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen - dwAppendPos : 512); | 1149 dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen - dwAppendPos : 512); |
1151 | 1150 |
1152 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { | 1151 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { |
1153 pHints->AddSegment(dwAppendPos, iSize); | 1152 pHints->AddSegment(dwAppendPos, iSize); |
1154 return FALSE; | 1153 return false; |
1155 } | 1154 } |
1156 } | 1155 } |
1157 | 1156 |
1158 if (m_dwPrevXRefOffset) { | 1157 if (m_dwPrevXRefOffset) { |
1159 SetStartOffset(m_dwPrevXRefOffset); | 1158 SetStartOffset(m_dwPrevXRefOffset); |
1160 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 1159 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
1161 } else { | 1160 } else { |
1162 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; | 1161 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; |
1163 } | 1162 } |
1164 return TRUE; | 1163 return true; |
1165 } | 1164 } |
1166 | 1165 |
1167 FX_BOOL CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { | 1166 bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { |
1168 int32_t iTrailerSize = | 1167 int32_t iTrailerSize = |
1169 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1168 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
1170 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { | 1169 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { |
1171 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); | 1170 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); |
1172 CFX_BinaryBuf buf(iSize); | 1171 CFX_BinaryBuf buf(iSize); |
1173 uint8_t* pBuf = buf.GetBuffer(); | 1172 uint8_t* pBuf = buf.GetBuffer(); |
1174 if (!pBuf) { | 1173 if (!pBuf) { |
1175 m_docStatus = PDF_DATAAVAIL_ERROR; | 1174 m_docStatus = PDF_DATAAVAIL_ERROR; |
1176 return FALSE; | 1175 return false; |
1177 } | 1176 } |
1178 | 1177 |
1179 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) | 1178 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) |
1180 return FALSE; | 1179 return false; |
1181 | 1180 |
1182 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 1181 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false)); |
1183 m_syntaxParser.InitParser(file.get(), 0); | 1182 m_syntaxParser.InitParser(file.get(), 0); |
1184 | 1183 |
1185 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( | 1184 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( |
1186 m_syntaxParser.GetObject(nullptr, 0, 0, true)); | 1185 m_syntaxParser.GetObject(nullptr, 0, 0, true)); |
1187 if (!pTrailer) { | 1186 if (!pTrailer) { |
1188 m_Pos += m_syntaxParser.SavePos(); | 1187 m_Pos += m_syntaxParser.SavePos(); |
1189 pHints->AddSegment(m_Pos, iTrailerSize); | 1188 pHints->AddSegment(m_Pos, iTrailerSize); |
1190 return FALSE; | 1189 return false; |
1191 } | 1190 } |
1192 | 1191 |
1193 if (!pTrailer->IsDictionary()) | 1192 if (!pTrailer->IsDictionary()) |
1194 return FALSE; | 1193 return false; |
1195 | 1194 |
1196 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); | 1195 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); |
1197 CPDF_Object* pEncrypt = pTrailerDict->GetObjectFor("Encrypt"); | 1196 CPDF_Object* pEncrypt = pTrailerDict->GetObjectFor("Encrypt"); |
1198 if (ToReference(pEncrypt)) { | 1197 if (ToReference(pEncrypt)) { |
1199 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1198 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1200 return TRUE; | 1199 return true; |
1201 } | 1200 } |
1202 | 1201 |
1203 uint32_t xrefpos = GetDirectInteger(pTrailerDict, "Prev"); | 1202 uint32_t xrefpos = GetDirectInteger(pTrailerDict, "Prev"); |
1204 if (xrefpos) { | 1203 if (xrefpos) { |
1205 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, "XRefStm"); | 1204 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, "XRefStm"); |
1206 if (m_dwPrevXRefOffset) { | 1205 if (m_dwPrevXRefOffset) { |
1207 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1206 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1208 } else { | 1207 } else { |
1209 m_dwPrevXRefOffset = xrefpos; | 1208 m_dwPrevXRefOffset = xrefpos; |
1210 if (m_dwPrevXRefOffset >= m_dwFileLen) { | 1209 if (m_dwPrevXRefOffset >= m_dwFileLen) { |
1211 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1210 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1212 } else { | 1211 } else { |
1213 SetStartOffset(m_dwPrevXRefOffset); | 1212 SetStartOffset(m_dwPrevXRefOffset); |
1214 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 1213 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
1215 } | 1214 } |
1216 } | 1215 } |
1217 return TRUE; | 1216 return true; |
1218 } | 1217 } |
1219 m_dwPrevXRefOffset = 0; | 1218 m_dwPrevXRefOffset = 0; |
1220 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 1219 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
1221 return TRUE; | 1220 return true; |
1222 } | 1221 } |
1223 pHints->AddSegment(m_Pos, iTrailerSize); | 1222 pHints->AddSegment(m_Pos, iTrailerSize); |
1224 return FALSE; | 1223 return false; |
1225 } | 1224 } |
1226 | 1225 |
1227 FX_BOOL CPDF_DataAvail::CheckPage(uint32_t dwPage, DownloadHints* pHints) { | 1226 bool CPDF_DataAvail::CheckPage(uint32_t dwPage, DownloadHints* pHints) { |
1228 while (TRUE) { | 1227 while (true) { |
1229 switch (m_docStatus) { | 1228 switch (m_docStatus) { |
1230 case PDF_DATAAVAIL_PAGETREE: | 1229 case PDF_DATAAVAIL_PAGETREE: |
1231 if (!LoadDocPages(pHints)) | 1230 if (!LoadDocPages(pHints)) |
1232 return FALSE; | 1231 return false; |
1233 break; | 1232 break; |
1234 case PDF_DATAAVAIL_PAGE: | 1233 case PDF_DATAAVAIL_PAGE: |
1235 if (!LoadDocPage(dwPage, pHints)) | 1234 if (!LoadDocPage(dwPage, pHints)) |
1236 return FALSE; | 1235 return false; |
1237 break; | 1236 break; |
1238 case PDF_DATAAVAIL_ERROR: | 1237 case PDF_DATAAVAIL_ERROR: |
1239 return LoadAllFile(pHints); | 1238 return LoadAllFile(pHints); |
1240 default: | 1239 default: |
1241 m_bPagesTreeLoad = TRUE; | 1240 m_bPagesTreeLoad = true; |
1242 m_bPagesLoad = TRUE; | 1241 m_bPagesLoad = true; |
1243 m_bCurPageDictLoadOK = TRUE; | 1242 m_bCurPageDictLoadOK = true; |
1244 m_docStatus = PDF_DATAAVAIL_PAGE; | 1243 m_docStatus = PDF_DATAAVAIL_PAGE; |
1245 return TRUE; | 1244 return true; |
1246 } | 1245 } |
1247 } | 1246 } |
1248 } | 1247 } |
1249 | 1248 |
1250 FX_BOOL CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, | 1249 bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, |
1251 PageNode* pPageNode, | 1250 PageNode* pPageNode, |
1252 DownloadHints* pHints) { | 1251 DownloadHints* pHints) { |
1253 FX_BOOL bExist = FALSE; | 1252 bool bExist = false; |
1254 CPDF_Object* pPages = GetObject(dwPageNo, pHints, &bExist); | 1253 CPDF_Object* pPages = GetObject(dwPageNo, pHints, &bExist); |
1255 if (!bExist) { | 1254 if (!bExist) { |
1256 m_docStatus = PDF_DATAAVAIL_ERROR; | 1255 m_docStatus = PDF_DATAAVAIL_ERROR; |
1257 return FALSE; | 1256 return false; |
1258 } | 1257 } |
1259 | 1258 |
1260 if (!pPages) { | 1259 if (!pPages) { |
1261 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 1260 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
1262 m_docStatus = PDF_DATAAVAIL_ERROR; | 1261 m_docStatus = PDF_DATAAVAIL_ERROR; |
1263 return FALSE; | 1262 return false; |
1264 } | 1263 } |
1265 return FALSE; | 1264 return false; |
1266 } | 1265 } |
1267 | 1266 |
1268 CPDF_Array* pArray = pPages->AsArray(); | 1267 CPDF_Array* pArray = pPages->AsArray(); |
1269 if (!pArray) { | 1268 if (!pArray) { |
1270 pPages->Release(); | 1269 pPages->Release(); |
1271 m_docStatus = PDF_DATAAVAIL_ERROR; | 1270 m_docStatus = PDF_DATAAVAIL_ERROR; |
1272 return FALSE; | 1271 return false; |
1273 } | 1272 } |
1274 | 1273 |
1275 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1274 pPageNode->m_type = PDF_PAGENODE_PAGES; |
1276 for (size_t i = 0; i < pArray->GetCount(); ++i) { | 1275 for (size_t i = 0; i < pArray->GetCount(); ++i) { |
1277 CPDF_Reference* pKid = ToReference(pArray->GetObjectAt(i)); | 1276 CPDF_Reference* pKid = ToReference(pArray->GetObjectAt(i)); |
1278 if (!pKid) | 1277 if (!pKid) |
1279 continue; | 1278 continue; |
1280 | 1279 |
1281 PageNode* pNode = new PageNode(); | 1280 PageNode* pNode = new PageNode(); |
1282 pPageNode->m_childNode.Add(pNode); | 1281 pPageNode->m_childNode.Add(pNode); |
1283 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1282 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
1284 } | 1283 } |
1285 pPages->Release(); | 1284 pPages->Release(); |
1286 return TRUE; | 1285 return true; |
1287 } | 1286 } |
1288 | 1287 |
1289 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(uint32_t dwPageNo, | 1288 bool CPDF_DataAvail::CheckUnkownPageNode(uint32_t dwPageNo, |
1290 PageNode* pPageNode, | 1289 PageNode* pPageNode, |
1291 DownloadHints* pHints) { | 1290 DownloadHints* pHints) { |
1292 FX_BOOL bExist = FALSE; | 1291 bool bExist = false; |
1293 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); | 1292 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); |
1294 if (!bExist) { | 1293 if (!bExist) { |
1295 m_docStatus = PDF_DATAAVAIL_ERROR; | 1294 m_docStatus = PDF_DATAAVAIL_ERROR; |
1296 return FALSE; | 1295 return false; |
1297 } | 1296 } |
1298 | 1297 |
1299 if (!pPage) { | 1298 if (!pPage) { |
1300 if (m_docStatus == PDF_DATAAVAIL_ERROR) | 1299 if (m_docStatus == PDF_DATAAVAIL_ERROR) |
1301 m_docStatus = PDF_DATAAVAIL_ERROR; | 1300 m_docStatus = PDF_DATAAVAIL_ERROR; |
1302 return FALSE; | 1301 return false; |
1303 } | 1302 } |
1304 | 1303 |
1305 if (pPage->IsArray()) { | 1304 if (pPage->IsArray()) { |
1306 pPageNode->m_dwPageNo = dwPageNo; | 1305 pPageNode->m_dwPageNo = dwPageNo; |
1307 pPageNode->m_type = PDF_PAGENODE_ARRAY; | 1306 pPageNode->m_type = PDF_PAGENODE_ARRAY; |
1308 pPage->Release(); | 1307 pPage->Release(); |
1309 return TRUE; | 1308 return true; |
1310 } | 1309 } |
1311 | 1310 |
1312 if (!pPage->IsDictionary()) { | 1311 if (!pPage->IsDictionary()) { |
1313 pPage->Release(); | 1312 pPage->Release(); |
1314 m_docStatus = PDF_DATAAVAIL_ERROR; | 1313 m_docStatus = PDF_DATAAVAIL_ERROR; |
1315 return FALSE; | 1314 return false; |
1316 } | 1315 } |
1317 | 1316 |
1318 pPageNode->m_dwPageNo = dwPageNo; | 1317 pPageNode->m_dwPageNo = dwPageNo; |
1319 CPDF_Dictionary* pDict = pPage->GetDict(); | 1318 CPDF_Dictionary* pDict = pPage->GetDict(); |
1320 CFX_ByteString type = pDict->GetStringFor("Type"); | 1319 CFX_ByteString type = pDict->GetStringFor("Type"); |
1321 if (type == "Pages") { | 1320 if (type == "Pages") { |
1322 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1321 pPageNode->m_type = PDF_PAGENODE_PAGES; |
1323 CPDF_Object* pKids = pDict->GetObjectFor("Kids"); | 1322 CPDF_Object* pKids = pDict->GetObjectFor("Kids"); |
1324 if (!pKids) { | 1323 if (!pKids) { |
1325 m_docStatus = PDF_DATAAVAIL_PAGE; | 1324 m_docStatus = PDF_DATAAVAIL_PAGE; |
1326 return TRUE; | 1325 return true; |
1327 } | 1326 } |
1328 | 1327 |
1329 switch (pKids->GetType()) { | 1328 switch (pKids->GetType()) { |
1330 case CPDF_Object::REFERENCE: { | 1329 case CPDF_Object::REFERENCE: { |
1331 CPDF_Reference* pKid = pKids->AsReference(); | 1330 CPDF_Reference* pKid = pKids->AsReference(); |
1332 PageNode* pNode = new PageNode(); | 1331 PageNode* pNode = new PageNode(); |
1333 pPageNode->m_childNode.Add(pNode); | 1332 pPageNode->m_childNode.Add(pNode); |
1334 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1333 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
1335 } break; | 1334 } break; |
1336 case CPDF_Object::ARRAY: { | 1335 case CPDF_Object::ARRAY: { |
1337 CPDF_Array* pKidsArray = pKids->AsArray(); | 1336 CPDF_Array* pKidsArray = pKids->AsArray(); |
1338 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { | 1337 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { |
1339 CPDF_Reference* pKid = ToReference(pKidsArray->GetObjectAt(i)); | 1338 CPDF_Reference* pKid = ToReference(pKidsArray->GetObjectAt(i)); |
1340 if (!pKid) | 1339 if (!pKid) |
1341 continue; | 1340 continue; |
1342 | 1341 |
1343 PageNode* pNode = new PageNode(); | 1342 PageNode* pNode = new PageNode(); |
1344 pPageNode->m_childNode.Add(pNode); | 1343 pPageNode->m_childNode.Add(pNode); |
1345 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1344 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
1346 } | 1345 } |
1347 } break; | 1346 } break; |
1348 default: | 1347 default: |
1349 break; | 1348 break; |
1350 } | 1349 } |
1351 } else if (type == "Page") { | 1350 } else if (type == "Page") { |
1352 pPageNode->m_type = PDF_PAGENODE_PAGE; | 1351 pPageNode->m_type = PDF_PAGENODE_PAGE; |
1353 } else { | 1352 } else { |
1354 pPage->Release(); | 1353 pPage->Release(); |
1355 m_docStatus = PDF_DATAAVAIL_ERROR; | 1354 m_docStatus = PDF_DATAAVAIL_ERROR; |
1356 return FALSE; | 1355 return false; |
1357 } | 1356 } |
1358 pPage->Release(); | 1357 pPage->Release(); |
1359 return TRUE; | 1358 return true; |
1360 } | 1359 } |
1361 | 1360 |
1362 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_DataAvail::PageNode& pageNodes, | 1361 bool CPDF_DataAvail::CheckPageNode(CPDF_DataAvail::PageNode& pageNodes, |
1363 int32_t iPage, | 1362 int32_t iPage, |
1364 int32_t& iCount, | 1363 int32_t& iCount, |
1365 DownloadHints* pHints, | 1364 DownloadHints* pHints, |
1366 int level) { | 1365 int level) { |
1367 if (level >= kMaxPageRecursionDepth) | 1366 if (level >= kMaxPageRecursionDepth) |
1368 return FALSE; | 1367 return false; |
1369 | 1368 |
1370 int32_t iSize = pageNodes.m_childNode.GetSize(); | 1369 int32_t iSize = pageNodes.m_childNode.GetSize(); |
1371 if (iSize <= 0 || iPage >= iSize) { | 1370 if (iSize <= 0 || iPage >= iSize) { |
1372 m_docStatus = PDF_DATAAVAIL_ERROR; | 1371 m_docStatus = PDF_DATAAVAIL_ERROR; |
1373 return FALSE; | 1372 return false; |
1374 } | 1373 } |
1375 | 1374 |
1376 for (int32_t i = 0; i < iSize; ++i) { | 1375 for (int32_t i = 0; i < iSize; ++i) { |
1377 PageNode* pNode = pageNodes.m_childNode.GetAt(i); | 1376 PageNode* pNode = pageNodes.m_childNode.GetAt(i); |
1378 if (!pNode) | 1377 if (!pNode) |
1379 continue; | 1378 continue; |
1380 | 1379 |
1381 switch (pNode->m_type) { | 1380 switch (pNode->m_type) { |
1382 case PDF_PAGENODE_UNKNOWN: | 1381 case PDF_PAGENODE_UNKNOWN: |
1383 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { | 1382 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { |
1384 return FALSE; | 1383 return false; |
1385 } | 1384 } |
1386 --i; | 1385 --i; |
1387 break; | 1386 break; |
1388 case PDF_PAGENODE_PAGE: | 1387 case PDF_PAGENODE_PAGE: |
1389 iCount++; | 1388 iCount++; |
1390 if (iPage == iCount && m_pDocument) | 1389 if (iPage == iCount && m_pDocument) |
1391 m_pDocument->SetPageObjNum(iPage, pNode->m_dwPageNo); | 1390 m_pDocument->SetPageObjNum(iPage, pNode->m_dwPageNo); |
1392 break; | 1391 break; |
1393 case PDF_PAGENODE_PAGES: | 1392 case PDF_PAGENODE_PAGES: |
1394 if (!CheckPageNode(*pNode, iPage, iCount, pHints, level + 1)) | 1393 if (!CheckPageNode(*pNode, iPage, iCount, pHints, level + 1)) |
1395 return FALSE; | 1394 return false; |
1396 break; | 1395 break; |
1397 case PDF_PAGENODE_ARRAY: | 1396 case PDF_PAGENODE_ARRAY: |
1398 if (!CheckArrayPageNode(pNode->m_dwPageNo, pNode, pHints)) | 1397 if (!CheckArrayPageNode(pNode->m_dwPageNo, pNode, pHints)) |
1399 return FALSE; | 1398 return false; |
1400 --i; | 1399 --i; |
1401 break; | 1400 break; |
1402 } | 1401 } |
1403 | 1402 |
1404 if (iPage == iCount) { | 1403 if (iPage == iCount) { |
1405 m_docStatus = PDF_DATAAVAIL_DONE; | 1404 m_docStatus = PDF_DATAAVAIL_DONE; |
1406 return TRUE; | 1405 return true; |
1407 } | 1406 } |
1408 } | 1407 } |
1409 return TRUE; | 1408 return true; |
1410 } | 1409 } |
1411 | 1410 |
1412 FX_BOOL CPDF_DataAvail::LoadDocPage(uint32_t dwPage, DownloadHints* pHints) { | 1411 bool CPDF_DataAvail::LoadDocPage(uint32_t dwPage, DownloadHints* pHints) { |
1413 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); | 1412 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); |
1414 int32_t iPage = safePage.ValueOrDie(); | 1413 int32_t iPage = safePage.ValueOrDie(); |
1415 if (m_pDocument->GetPageCount() <= iPage || | 1414 if (m_pDocument->GetPageCount() <= iPage || |
1416 m_pDocument->IsPageLoaded(iPage)) { | 1415 m_pDocument->IsPageLoaded(iPage)) { |
1417 m_docStatus = PDF_DATAAVAIL_DONE; | 1416 m_docStatus = PDF_DATAAVAIL_DONE; |
1418 return TRUE; | 1417 return true; |
1419 } | 1418 } |
1420 | 1419 |
1421 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { | 1420 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { |
1422 if (iPage == 0) { | 1421 if (iPage == 0) { |
1423 m_docStatus = PDF_DATAAVAIL_DONE; | 1422 m_docStatus = PDF_DATAAVAIL_DONE; |
1424 return TRUE; | 1423 return true; |
1425 } | 1424 } |
1426 m_docStatus = PDF_DATAAVAIL_ERROR; | 1425 m_docStatus = PDF_DATAAVAIL_ERROR; |
1427 return TRUE; | 1426 return true; |
1428 } | 1427 } |
1429 int32_t iCount = -1; | 1428 int32_t iCount = -1; |
1430 return CheckPageNode(m_pageNodes, iPage, iCount, pHints, 0); | 1429 return CheckPageNode(m_pageNodes, iPage, iCount, pHints, 0); |
1431 } | 1430 } |
1432 | 1431 |
1433 FX_BOOL CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { | 1432 bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { |
1434 FX_BOOL bExist = FALSE; | 1433 bool bExist = false; |
1435 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 1434 CPDF_Object* pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
1436 if (!bExist) { | 1435 if (!bExist) { |
1437 m_docStatus = PDF_DATAAVAIL_ERROR; | 1436 m_docStatus = PDF_DATAAVAIL_ERROR; |
1438 return FALSE; | 1437 return false; |
1439 } | 1438 } |
1440 | 1439 |
1441 if (!pPages) | 1440 if (!pPages) |
1442 return FALSE; | 1441 return false; |
1443 | 1442 |
1444 CPDF_Dictionary* pPagesDict = pPages->GetDict(); | 1443 CPDF_Dictionary* pPagesDict = pPages->GetDict(); |
1445 if (!pPagesDict) { | 1444 if (!pPagesDict) { |
1446 pPages->Release(); | 1445 pPages->Release(); |
1447 m_docStatus = PDF_DATAAVAIL_ERROR; | 1446 m_docStatus = PDF_DATAAVAIL_ERROR; |
1448 return FALSE; | 1447 return false; |
1449 } | 1448 } |
1450 | 1449 |
1451 if (!pPagesDict->KeyExist("Kids")) { | 1450 if (!pPagesDict->KeyExist("Kids")) { |
1452 pPages->Release(); | 1451 pPages->Release(); |
1453 return TRUE; | 1452 return true; |
1454 } | 1453 } |
1455 | 1454 |
1456 int count = pPagesDict->GetIntegerFor("Count"); | 1455 int count = pPagesDict->GetIntegerFor("Count"); |
1457 if (count > 0) { | 1456 if (count > 0) { |
1458 pPages->Release(); | 1457 pPages->Release(); |
1459 return TRUE; | 1458 return true; |
1460 } | 1459 } |
1461 | 1460 |
1462 pPages->Release(); | 1461 pPages->Release(); |
1463 return FALSE; | 1462 return false; |
1464 } | 1463 } |
1465 | 1464 |
1466 FX_BOOL CPDF_DataAvail::LoadDocPages(DownloadHints* pHints) { | 1465 bool CPDF_DataAvail::LoadDocPages(DownloadHints* pHints) { |
1467 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) | 1466 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) |
1468 return FALSE; | 1467 return false; |
1469 | 1468 |
1470 if (CheckPageCount(pHints)) { | 1469 if (CheckPageCount(pHints)) { |
1471 m_docStatus = PDF_DATAAVAIL_PAGE; | 1470 m_docStatus = PDF_DATAAVAIL_PAGE; |
1472 return TRUE; | 1471 return true; |
1473 } | 1472 } |
1474 | 1473 |
1475 m_bTotalLoadPageTree = TRUE; | 1474 m_bTotalLoadPageTree = true; |
1476 return FALSE; | 1475 return false; |
1477 } | 1476 } |
1478 | 1477 |
1479 FX_BOOL CPDF_DataAvail::LoadPages(DownloadHints* pHints) { | 1478 bool CPDF_DataAvail::LoadPages(DownloadHints* pHints) { |
1480 while (!m_bPagesTreeLoad) { | 1479 while (!m_bPagesTreeLoad) { |
1481 if (!CheckPageStatus(pHints)) | 1480 if (!CheckPageStatus(pHints)) |
1482 return FALSE; | 1481 return false; |
1483 } | 1482 } |
1484 | 1483 |
1485 if (m_bPagesLoad) | 1484 if (m_bPagesLoad) |
1486 return TRUE; | 1485 return true; |
1487 | 1486 |
1488 m_pDocument->LoadPages(); | 1487 m_pDocument->LoadPages(); |
1489 return FALSE; | 1488 return false; |
1490 } | 1489 } |
1491 | 1490 |
1492 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( | 1491 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( |
1493 DownloadHints* pHints) { | 1492 DownloadHints* pHints) { |
1494 if (m_bLinearedDataOK) | 1493 if (m_bLinearedDataOK) |
1495 return DataAvailable; | 1494 return DataAvailable; |
1496 | 1495 |
1497 if (!m_bMainXRefLoadTried) { | 1496 if (!m_bMainXRefLoadTried) { |
1498 FX_SAFE_UINT32 data_size = m_dwFileLen; | 1497 FX_SAFE_UINT32 data_size = m_dwFileLen; |
1499 data_size -= m_dwLastXRefOffset; | 1498 data_size -= m_dwLastXRefOffset; |
1500 if (!data_size.IsValid()) | 1499 if (!data_size.IsValid()) |
1501 return DataError; | 1500 return DataError; |
1502 | 1501 |
1503 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 1502 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
1504 data_size.ValueOrDie())) { | 1503 data_size.ValueOrDie())) { |
1505 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); | 1504 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); |
1506 return DataNotAvailable; | 1505 return DataNotAvailable; |
1507 } | 1506 } |
1508 | 1507 |
1509 CPDF_Parser::Error eRet = | 1508 CPDF_Parser::Error eRet = |
1510 m_pDocument->GetParser()->LoadLinearizedMainXRefTable(); | 1509 m_pDocument->GetParser()->LoadLinearizedMainXRefTable(); |
1511 m_bMainXRefLoadTried = TRUE; | 1510 m_bMainXRefLoadTried = true; |
1512 if (eRet != CPDF_Parser::SUCCESS) | 1511 if (eRet != CPDF_Parser::SUCCESS) |
1513 return DataError; | 1512 return DataError; |
1514 | 1513 |
1515 if (!PreparePageItem()) | 1514 if (!PreparePageItem()) |
1516 return DataNotAvailable; | 1515 return DataNotAvailable; |
1517 | 1516 |
1518 m_bMainXRefLoadedOK = TRUE; | 1517 m_bMainXRefLoadedOK = true; |
1519 m_bLinearedDataOK = TRUE; | 1518 m_bLinearedDataOK = true; |
1520 } | 1519 } |
1521 | 1520 |
1522 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; | 1521 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; |
1523 } | 1522 } |
1524 | 1523 |
1525 FX_BOOL CPDF_DataAvail::CheckPageAnnots(uint32_t dwPage, | 1524 bool CPDF_DataAvail::CheckPageAnnots(uint32_t dwPage, DownloadHints* pHints) { |
1526 DownloadHints* pHints) { | |
1527 if (m_objs_array.empty()) { | 1525 if (m_objs_array.empty()) { |
1528 m_ObjectSet.clear(); | 1526 m_ObjectSet.clear(); |
1529 | 1527 |
1530 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); | 1528 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); |
1531 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); | 1529 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); |
1532 if (!pPageDict) | 1530 if (!pPageDict) |
1533 return TRUE; | 1531 return true; |
1534 | 1532 |
1535 CPDF_Object* pAnnots = pPageDict->GetObjectFor("Annots"); | 1533 CPDF_Object* pAnnots = pPageDict->GetObjectFor("Annots"); |
1536 if (!pAnnots) | 1534 if (!pAnnots) |
1537 return TRUE; | 1535 return true; |
1538 | 1536 |
1539 std::vector<CPDF_Object*> obj_array; | 1537 std::vector<CPDF_Object*> obj_array; |
1540 obj_array.push_back(pAnnots); | 1538 obj_array.push_back(pAnnots); |
1541 if (!AreObjectsAvailable(obj_array, FALSE, pHints, m_objs_array)) | 1539 if (!AreObjectsAvailable(obj_array, false, pHints, m_objs_array)) |
1542 return FALSE; | 1540 return false; |
1543 | 1541 |
1544 m_objs_array.clear(); | 1542 m_objs_array.clear(); |
1545 return TRUE; | 1543 return true; |
1546 } | 1544 } |
1547 | 1545 |
1548 std::vector<CPDF_Object*> new_objs_array; | 1546 std::vector<CPDF_Object*> new_objs_array; |
1549 if (!AreObjectsAvailable(m_objs_array, FALSE, pHints, new_objs_array)) { | 1547 if (!AreObjectsAvailable(m_objs_array, false, pHints, new_objs_array)) { |
1550 m_objs_array = new_objs_array; | 1548 m_objs_array = new_objs_array; |
1551 return FALSE; | 1549 return false; |
1552 } | 1550 } |
1553 m_objs_array.clear(); | 1551 m_objs_array.clear(); |
1554 return TRUE; | 1552 return true; |
1555 } | 1553 } |
1556 | 1554 |
1557 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( | 1555 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( |
1558 uint32_t dwPage, | 1556 uint32_t dwPage, |
1559 DownloadHints* pHints) { | 1557 DownloadHints* pHints) { |
1560 if (!m_bAnnotsLoad) { | 1558 if (!m_bAnnotsLoad) { |
1561 if (!CheckPageAnnots(dwPage, pHints)) | 1559 if (!CheckPageAnnots(dwPage, pHints)) |
1562 return DataNotAvailable; | 1560 return DataNotAvailable; |
1563 m_bAnnotsLoad = TRUE; | 1561 m_bAnnotsLoad = true; |
1564 } | 1562 } |
1565 | 1563 |
1566 DocAvailStatus nRet = CheckLinearizedData(pHints); | 1564 DocAvailStatus nRet = CheckLinearizedData(pHints); |
1567 if (nRet == DataAvailable) | 1565 if (nRet == DataAvailable) |
1568 m_bPageLoadedOK = FALSE; | 1566 m_bPageLoadedOK = false; |
1569 return nRet; | 1567 return nRet; |
1570 } | 1568 } |
1571 | 1569 |
1572 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) { | 1570 bool CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) { |
1573 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); | 1571 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); |
1574 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) | 1572 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) |
1575 return FALSE; | 1573 return false; |
1576 | 1574 |
1577 CPDF_Object* pParent = pDict->GetObjectFor("Parent"); | 1575 CPDF_Object* pParent = pDict->GetObjectFor("Parent"); |
1578 if (!pParent) | 1576 if (!pParent) |
1579 return FALSE; | 1577 return false; |
1580 | 1578 |
1581 CPDF_Dictionary* pParentDict = pParent->GetDict(); | 1579 CPDF_Dictionary* pParentDict = pParent->GetDict(); |
1582 if (!pParentDict) | 1580 if (!pParentDict) |
1583 return FALSE; | 1581 return false; |
1584 | 1582 |
1585 CPDF_Object* pRet = pParentDict->GetObjectFor("Resources"); | 1583 CPDF_Object* pRet = pParentDict->GetObjectFor("Resources"); |
1586 if (pRet) { | 1584 if (pRet) { |
1587 m_pPageResource = pRet; | 1585 m_pPageResource = pRet; |
1588 return TRUE; | 1586 return true; |
1589 } | 1587 } |
1590 | 1588 |
1591 return HaveResourceAncestor(pParentDict); | 1589 return HaveResourceAncestor(pParentDict); |
1592 } | 1590 } |
1593 | 1591 |
1594 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( | 1592 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( |
1595 uint32_t dwPage, | 1593 uint32_t dwPage, |
1596 DownloadHints* pHints) { | 1594 DownloadHints* pHints) { |
1597 if (!m_pDocument) | 1595 if (!m_pDocument) |
1598 return DataError; | 1596 return DataError; |
1599 | 1597 |
1600 if (IsFirstCheck(dwPage)) { | 1598 if (IsFirstCheck(dwPage)) { |
1601 m_bCurPageDictLoadOK = FALSE; | 1599 m_bCurPageDictLoadOK = false; |
1602 m_bPageLoadedOK = FALSE; | 1600 m_bPageLoadedOK = false; |
1603 m_bAnnotsLoad = FALSE; | 1601 m_bAnnotsLoad = false; |
1604 m_bNeedDownLoadResource = FALSE; | 1602 m_bNeedDownLoadResource = false; |
1605 m_objs_array.clear(); | 1603 m_objs_array.clear(); |
1606 m_ObjectSet.clear(); | 1604 m_ObjectSet.clear(); |
1607 } | 1605 } |
1608 | 1606 |
1609 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) | 1607 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) |
1610 return DataAvailable; | 1608 return DataAvailable; |
1611 | 1609 |
1612 if (m_bLinearized) { | 1610 if (m_bLinearized) { |
1613 if (dwPage == m_dwFirstPageNo) { | 1611 if (dwPage == m_dwFirstPageNo) { |
1614 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); | 1612 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 } else { | 1645 } else { |
1648 if (!m_bTotalLoadPageTree && !m_bCurPageDictLoadOK && | 1646 if (!m_bTotalLoadPageTree && !m_bCurPageDictLoadOK && |
1649 !CheckPage(dwPage, pHints)) { | 1647 !CheckPage(dwPage, pHints)) { |
1650 return DataNotAvailable; | 1648 return DataNotAvailable; |
1651 } | 1649 } |
1652 } | 1650 } |
1653 | 1651 |
1654 if (m_bHaveAcroForm && !m_bAcroFormLoad) { | 1652 if (m_bHaveAcroForm && !m_bAcroFormLoad) { |
1655 if (!CheckAcroFormSubObject(pHints)) | 1653 if (!CheckAcroFormSubObject(pHints)) |
1656 return DataNotAvailable; | 1654 return DataNotAvailable; |
1657 m_bAcroFormLoad = TRUE; | 1655 m_bAcroFormLoad = true; |
1658 } | 1656 } |
1659 | 1657 |
1660 if (!m_bPageLoadedOK) { | 1658 if (!m_bPageLoadedOK) { |
1661 if (m_objs_array.empty()) { | 1659 if (m_objs_array.empty()) { |
1662 m_ObjectSet.clear(); | 1660 m_ObjectSet.clear(); |
1663 | 1661 |
1664 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); | 1662 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); |
1665 m_pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); | 1663 m_pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); |
1666 if (!m_pPageDict) { | 1664 if (!m_pPageDict) { |
1667 ResetFirstCheck(dwPage); | 1665 ResetFirstCheck(dwPage); |
1668 return DataAvailable; | 1666 return DataAvailable; |
1669 } | 1667 } |
1670 | 1668 |
1671 std::vector<CPDF_Object*> obj_array; | 1669 std::vector<CPDF_Object*> obj_array; |
1672 obj_array.push_back(m_pPageDict); | 1670 obj_array.push_back(m_pPageDict); |
1673 if (!AreObjectsAvailable(obj_array, TRUE, pHints, m_objs_array)) | 1671 if (!AreObjectsAvailable(obj_array, true, pHints, m_objs_array)) |
1674 return DataNotAvailable; | 1672 return DataNotAvailable; |
1675 | 1673 |
1676 m_objs_array.clear(); | 1674 m_objs_array.clear(); |
1677 } else { | 1675 } else { |
1678 std::vector<CPDF_Object*> new_objs_array; | 1676 std::vector<CPDF_Object*> new_objs_array; |
1679 if (!AreObjectsAvailable(m_objs_array, FALSE, pHints, new_objs_array)) { | 1677 if (!AreObjectsAvailable(m_objs_array, false, pHints, new_objs_array)) { |
1680 m_objs_array = new_objs_array; | 1678 m_objs_array = new_objs_array; |
1681 return DataNotAvailable; | 1679 return DataNotAvailable; |
1682 } | 1680 } |
1683 } | 1681 } |
1684 m_objs_array.clear(); | 1682 m_objs_array.clear(); |
1685 m_bPageLoadedOK = TRUE; | 1683 m_bPageLoadedOK = true; |
1686 } | 1684 } |
1687 | 1685 |
1688 if (!m_bAnnotsLoad) { | 1686 if (!m_bAnnotsLoad) { |
1689 if (!CheckPageAnnots(dwPage, pHints)) | 1687 if (!CheckPageAnnots(dwPage, pHints)) |
1690 return DataNotAvailable; | 1688 return DataNotAvailable; |
1691 m_bAnnotsLoad = TRUE; | 1689 m_bAnnotsLoad = true; |
1692 } | 1690 } |
1693 | 1691 |
1694 if (m_pPageDict && !m_bNeedDownLoadResource) { | 1692 if (m_pPageDict && !m_bNeedDownLoadResource) { |
1695 m_pPageResource = m_pPageDict->GetObjectFor("Resources"); | 1693 m_pPageResource = m_pPageDict->GetObjectFor("Resources"); |
1696 m_bNeedDownLoadResource = | 1694 m_bNeedDownLoadResource = |
1697 m_pPageResource || HaveResourceAncestor(m_pPageDict); | 1695 m_pPageResource || HaveResourceAncestor(m_pPageDict); |
1698 } | 1696 } |
1699 | 1697 |
1700 if (m_bNeedDownLoadResource) { | 1698 if (m_bNeedDownLoadResource) { |
1701 if (!CheckResources(pHints)) | 1699 if (!CheckResources(pHints)) |
1702 return DataNotAvailable; | 1700 return DataNotAvailable; |
1703 m_bNeedDownLoadResource = FALSE; | 1701 m_bNeedDownLoadResource = false; |
1704 } | 1702 } |
1705 | 1703 |
1706 m_bPageLoadedOK = FALSE; | 1704 m_bPageLoadedOK = false; |
1707 m_bAnnotsLoad = FALSE; | 1705 m_bAnnotsLoad = false; |
1708 m_bCurPageDictLoadOK = FALSE; | 1706 m_bCurPageDictLoadOK = false; |
1709 | 1707 |
1710 ResetFirstCheck(dwPage); | 1708 ResetFirstCheck(dwPage); |
1711 m_pagesLoadState.insert(dwPage); | 1709 m_pagesLoadState.insert(dwPage); |
1712 return DataAvailable; | 1710 return DataAvailable; |
1713 } | 1711 } |
1714 | 1712 |
1715 FX_BOOL CPDF_DataAvail::CheckResources(DownloadHints* pHints) { | 1713 bool CPDF_DataAvail::CheckResources(DownloadHints* pHints) { |
1716 if (m_objs_array.empty()) { | 1714 if (m_objs_array.empty()) { |
1717 std::vector<CPDF_Object*> obj_array; | 1715 std::vector<CPDF_Object*> obj_array; |
1718 obj_array.push_back(m_pPageResource); | 1716 obj_array.push_back(m_pPageResource); |
1719 if (!AreObjectsAvailable(obj_array, TRUE, pHints, m_objs_array)) | 1717 if (!AreObjectsAvailable(obj_array, true, pHints, m_objs_array)) |
1720 return FALSE; | 1718 return false; |
1721 | 1719 |
1722 m_objs_array.clear(); | 1720 m_objs_array.clear(); |
1723 return TRUE; | 1721 return true; |
1724 } | 1722 } |
1725 std::vector<CPDF_Object*> new_objs_array; | 1723 std::vector<CPDF_Object*> new_objs_array; |
1726 if (!AreObjectsAvailable(m_objs_array, FALSE, pHints, new_objs_array)) { | 1724 if (!AreObjectsAvailable(m_objs_array, false, pHints, new_objs_array)) { |
1727 m_objs_array = new_objs_array; | 1725 m_objs_array = new_objs_array; |
1728 return FALSE; | 1726 return false; |
1729 } | 1727 } |
1730 m_objs_array.clear(); | 1728 m_objs_array.clear(); |
1731 return TRUE; | 1729 return true; |
1732 } | 1730 } |
1733 | 1731 |
1734 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, | 1732 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, |
1735 uint32_t* pSize) { | 1733 uint32_t* pSize) { |
1736 if (pPos) | 1734 if (pPos) |
1737 *pPos = m_dwLastXRefOffset; | 1735 *pPos = m_dwLastXRefOffset; |
1738 if (pSize) | 1736 if (pSize) |
1739 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); | 1737 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); |
1740 } | 1738 } |
1741 | 1739 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 return FormNotExist; | 1796 return FormNotExist; |
1799 | 1797 |
1800 DocAvailStatus nDocStatus = CheckLinearizedData(pHints); | 1798 DocAvailStatus nDocStatus = CheckLinearizedData(pHints); |
1801 if (nDocStatus == DataError) | 1799 if (nDocStatus == DataError) |
1802 return FormError; | 1800 return FormError; |
1803 if (nDocStatus == DataNotAvailable) | 1801 if (nDocStatus == DataNotAvailable) |
1804 return FormNotAvailable; | 1802 return FormNotAvailable; |
1805 | 1803 |
1806 if (m_objs_array.empty()) | 1804 if (m_objs_array.empty()) |
1807 m_objs_array.push_back(pAcroForm->GetDict()); | 1805 m_objs_array.push_back(pAcroForm->GetDict()); |
1808 m_bLinearizedFormParamLoad = TRUE; | 1806 m_bLinearizedFormParamLoad = true; |
1809 } | 1807 } |
1810 | 1808 |
1811 std::vector<CPDF_Object*> new_objs_array; | 1809 std::vector<CPDF_Object*> new_objs_array; |
1812 if (!AreObjectsAvailable(m_objs_array, FALSE, pHints, new_objs_array)) { | 1810 if (!AreObjectsAvailable(m_objs_array, false, pHints, new_objs_array)) { |
1813 m_objs_array = new_objs_array; | 1811 m_objs_array = new_objs_array; |
1814 return FormNotAvailable; | 1812 return FormNotAvailable; |
1815 } | 1813 } |
1816 | 1814 |
1817 m_objs_array.clear(); | 1815 m_objs_array.clear(); |
1818 return FormAvailable; | 1816 return FormAvailable; |
1819 } | 1817 } |
1820 | 1818 |
1821 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1819 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
1822 | 1820 |
1823 CPDF_DataAvail::PageNode::~PageNode() { | 1821 CPDF_DataAvail::PageNode::~PageNode() { |
1824 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1822 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
1825 delete m_childNode[i]; | 1823 delete m_childNode[i]; |
1826 m_childNode.RemoveAll(); | 1824 m_childNode.RemoveAll(); |
1827 } | 1825 } |
OLD | NEW |