OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" | 7 #include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" | 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" |
10 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" | 10 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // static | 39 // static |
40 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; | 40 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; |
41 | 41 |
42 CPDF_DataAvail::CPDF_DataAvail(IPDF_DataAvail::FileAvail* pFileAvail, | 42 CPDF_DataAvail::CPDF_DataAvail(IPDF_DataAvail::FileAvail* pFileAvail, |
43 IFX_FileRead* pFileRead, | 43 IFX_FileRead* pFileRead, |
44 FX_BOOL bSupportHintTable) | 44 FX_BOOL bSupportHintTable) |
45 : IPDF_DataAvail(pFileAvail, pFileRead) { | 45 : IPDF_DataAvail(pFileAvail, pFileRead) { |
46 m_Pos = 0; | 46 m_Pos = 0; |
47 m_dwFileLen = 0; | 47 m_dwFileLen = 0; |
48 if (m_pFileRead) { | 48 if (m_pFileRead) { |
49 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 49 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
50 } | 50 } |
51 m_dwCurrentOffset = 0; | 51 m_dwCurrentOffset = 0; |
52 m_dwXRefOffset = 0; | 52 m_dwXRefOffset = 0; |
53 m_bufferOffset = 0; | 53 m_bufferOffset = 0; |
54 m_dwFirstPageNo = 0; | 54 m_dwFirstPageNo = 0; |
55 m_bufferSize = 0; | 55 m_bufferSize = 0; |
56 m_PagesObjNum = 0; | 56 m_PagesObjNum = 0; |
57 m_dwCurrentXRefSteam = 0; | 57 m_dwCurrentXRefSteam = 0; |
58 m_dwAcroFormObjNum = 0; | 58 m_dwAcroFormObjNum = 0; |
59 m_dwInfoObjNum = 0; | 59 m_dwInfoObjNum = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 int iSize = m_arrayAcroforms.GetSize(); | 101 int iSize = m_arrayAcroforms.GetSize(); |
102 for (int i = 0; i < iSize; ++i) | 102 for (int i = 0; i < iSize; ++i) |
103 m_arrayAcroforms.GetAt(i)->Release(); | 103 m_arrayAcroforms.GetAt(i)->Release(); |
104 } | 104 } |
105 | 105 |
106 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 106 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
107 m_pDocument = pDoc; | 107 m_pDocument = pDoc; |
108 } | 108 } |
109 | 109 |
110 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { | 110 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { |
111 CPDF_Parser* pParser = m_pDocument->GetParser(); | 111 CPDF_Parser* pParser = m_pDocument->GetParser(); |
112 if (!pParser || !pParser->IsValidObjectNumber(objnum)) | 112 if (!pParser || !pParser->IsValidObjectNumber(objnum)) |
113 return 0; | 113 return 0; |
114 | 114 |
115 if (pParser->GetObjectType(objnum) == 2) | 115 if (pParser->GetObjectType(objnum) == 2) |
116 objnum = pParser->GetObjectPositionOrZero(objnum); | 116 objnum = pParser->GetObjectPositionOrZero(objnum); |
117 | 117 |
118 if (pParser->GetObjectType(objnum) != 1 && | 118 if (pParser->GetObjectType(objnum) != 1 && |
119 pParser->GetObjectType(objnum) != 255) { | 119 pParser->GetObjectType(objnum) != 255) { |
120 return 0; | 120 return 0; |
(...skipping 12 matching lines...) Expand all Loading... |
133 } | 133 } |
134 | 134 |
135 FX_BOOL CPDF_DataAvail::IsObjectsAvail( | 135 FX_BOOL CPDF_DataAvail::IsObjectsAvail( |
136 CFX_ArrayTemplate<CPDF_Object*>& obj_array, | 136 CFX_ArrayTemplate<CPDF_Object*>& obj_array, |
137 FX_BOOL bParsePage, | 137 FX_BOOL bParsePage, |
138 IPDF_DataAvail::DownloadHints* pHints, | 138 IPDF_DataAvail::DownloadHints* pHints, |
139 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { | 139 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { |
140 if (!obj_array.GetSize()) | 140 if (!obj_array.GetSize()) |
141 return TRUE; | 141 return TRUE; |
142 | 142 |
143 FX_DWORD count = 0; | 143 uint32_t count = 0; |
144 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; | 144 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; |
145 int32_t i = 0; | 145 int32_t i = 0; |
146 for (i = 0; i < obj_array.GetSize(); i++) { | 146 for (i = 0; i < obj_array.GetSize(); i++) { |
147 CPDF_Object* pObj = obj_array[i]; | 147 CPDF_Object* pObj = obj_array[i]; |
148 if (!pObj) | 148 if (!pObj) |
149 continue; | 149 continue; |
150 | 150 |
151 int32_t type = pObj->GetType(); | 151 int32_t type = pObj->GetType(); |
152 switch (type) { | 152 switch (type) { |
153 case CPDF_Object::ARRAY: { | 153 case CPDF_Object::ARRAY: { |
154 CPDF_Array* pArray = pObj->GetArray(); | 154 CPDF_Array* pArray = pObj->GetArray(); |
155 for (FX_DWORD k = 0; k < pArray->GetCount(); ++k) | 155 for (uint32_t k = 0; k < pArray->GetCount(); ++k) |
156 new_obj_array.Add(pArray->GetElement(k)); | 156 new_obj_array.Add(pArray->GetElement(k)); |
157 } break; | 157 } break; |
158 case CPDF_Object::STREAM: | 158 case CPDF_Object::STREAM: |
159 pObj = pObj->GetDict(); | 159 pObj = pObj->GetDict(); |
160 case CPDF_Object::DICTIONARY: { | 160 case CPDF_Object::DICTIONARY: { |
161 CPDF_Dictionary* pDict = pObj->GetDict(); | 161 CPDF_Dictionary* pDict = pObj->GetDict(); |
162 if (pDict && pDict->GetStringBy("Type") == "Page" && !bParsePage) | 162 if (pDict && pDict->GetStringBy("Type") == "Page" && !bParsePage) |
163 continue; | 163 continue; |
164 | 164 |
165 for (const auto& it : *pDict) { | 165 for (const auto& it : *pDict) { |
166 const CFX_ByteString& key = it.first; | 166 const CFX_ByteString& key = it.first; |
167 CPDF_Object* value = it.second; | 167 CPDF_Object* value = it.second; |
168 if (key != "Parent") | 168 if (key != "Parent") |
169 new_obj_array.Add(value); | 169 new_obj_array.Add(value); |
170 } | 170 } |
171 } break; | 171 } break; |
172 case CPDF_Object::REFERENCE: { | 172 case CPDF_Object::REFERENCE: { |
173 CPDF_Reference* pRef = pObj->AsReference(); | 173 CPDF_Reference* pRef = pObj->AsReference(); |
174 FX_DWORD dwNum = pRef->GetRefObjNum(); | 174 uint32_t dwNum = pRef->GetRefObjNum(); |
175 | 175 |
176 FX_FILESIZE offset; | 176 FX_FILESIZE offset; |
177 FX_DWORD size = GetObjectSize(dwNum, offset); | 177 uint32_t size = GetObjectSize(dwNum, offset); |
178 if (size == 0 || offset < 0 || offset >= m_dwFileLen) | 178 if (size == 0 || offset < 0 || offset >= m_dwFileLen) |
179 break; | 179 break; |
180 | 180 |
181 if (!IsDataAvail(offset, size, pHints)) { | 181 if (!IsDataAvail(offset, size, pHints)) { |
182 ret_array.Add(pObj); | 182 ret_array.Add(pObj); |
183 count++; | 183 count++; |
184 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { | 184 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { |
185 m_ObjectSet.insert(dwNum); | 185 m_ObjectSet.insert(dwNum); |
186 CPDF_Object* pReferred = | 186 CPDF_Object* pReferred = |
187 m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); | 187 m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
188 if (pReferred) | 188 if (pReferred) |
189 new_obj_array.Add(pReferred); | 189 new_obj_array.Add(pReferred); |
190 } | 190 } |
191 } break; | 191 } break; |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 if (count > 0) { | 195 if (count > 0) { |
196 int32_t iSize = new_obj_array.GetSize(); | 196 int32_t iSize = new_obj_array.GetSize(); |
197 for (i = 0; i < iSize; ++i) { | 197 for (i = 0; i < iSize; ++i) { |
198 CPDF_Object* pObj = new_obj_array[i]; | 198 CPDF_Object* pObj = new_obj_array[i]; |
199 if (CPDF_Reference* pRef = pObj->AsReference()) { | 199 if (CPDF_Reference* pRef = pObj->AsReference()) { |
200 FX_DWORD dwNum = pRef->GetRefObjNum(); | 200 uint32_t dwNum = pRef->GetRefObjNum(); |
201 if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) | 201 if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) |
202 ret_array.Add(pObj); | 202 ret_array.Add(pObj); |
203 } else { | 203 } else { |
204 ret_array.Add(pObj); | 204 ret_array.Add(pObj); |
205 } | 205 } |
206 } | 206 } |
207 return FALSE; | 207 return FALSE; |
208 } | 208 } |
209 | 209 |
210 obj_array.RemoveAll(); | 210 obj_array.RemoveAll(); |
211 obj_array.Append(new_obj_array); | 211 obj_array.Append(new_obj_array); |
212 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 212 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); |
213 } | 213 } |
214 | 214 |
215 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( | 215 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( |
216 IPDF_DataAvail::DownloadHints* pHints) { | 216 IPDF_DataAvail::DownloadHints* pHints) { |
217 if (!m_dwFileLen && m_pFileRead) { | 217 if (!m_dwFileLen && m_pFileRead) { |
218 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 218 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
219 if (!m_dwFileLen) | 219 if (!m_dwFileLen) |
220 return DataError; | 220 return DataError; |
221 } | 221 } |
222 | 222 |
223 while (!m_bDocAvail) { | 223 while (!m_bDocAvail) { |
224 if (!CheckDocStatus(pHints)) | 224 if (!CheckDocStatus(pHints)) |
225 return DataNotAvailable; | 225 return DataNotAvailable; |
226 } | 226 } |
227 | 227 |
228 return DataAvailable; | 228 return DataAvailable; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 case PDF_DATAAVAIL_ERROR: | 336 case PDF_DATAAVAIL_ERROR: |
337 return LoadAllFile(pHints); | 337 return LoadAllFile(pHints); |
338 default: | 338 default: |
339 m_bPagesTreeLoad = TRUE; | 339 m_bPagesTreeLoad = TRUE; |
340 m_bPagesLoad = TRUE; | 340 m_bPagesLoad = TRUE; |
341 return TRUE; | 341 return TRUE; |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 FX_BOOL CPDF_DataAvail::LoadAllFile(IPDF_DataAvail::DownloadHints* pHints) { | 345 FX_BOOL CPDF_DataAvail::LoadAllFile(IPDF_DataAvail::DownloadHints* pHints) { |
346 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { | 346 if (m_pFileAvail->IsDataAvail(0, (uint32_t)m_dwFileLen)) { |
347 m_docStatus = PDF_DATAAVAIL_DONE; | 347 m_docStatus = PDF_DATAAVAIL_DONE; |
348 return TRUE; | 348 return TRUE; |
349 } | 349 } |
350 | 350 |
351 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); | 351 pHints->AddSegment(0, (uint32_t)m_dwFileLen); |
352 return FALSE; | 352 return FALSE; |
353 } | 353 } |
354 | 354 |
355 FX_BOOL CPDF_DataAvail::LoadAllXref(IPDF_DataAvail::DownloadHints* pHints) { | 355 FX_BOOL CPDF_DataAvail::LoadAllXref(IPDF_DataAvail::DownloadHints* pHints) { |
356 m_parser.m_pSyntax->InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); | 356 m_parser.m_pSyntax->InitParser(m_pFileRead, (uint32_t)m_dwHeaderOffset); |
357 m_parser.m_bOwnFileRead = false; | 357 m_parser.m_bOwnFileRead = false; |
358 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && | 358 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && |
359 !m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) { | 359 !m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) { |
360 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 360 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
361 return FALSE; | 361 return FALSE; |
362 } | 362 } |
363 | 363 |
364 m_dwRootObjNum = m_parser.GetRootObjNum(); | 364 m_dwRootObjNum = m_parser.GetRootObjNum(); |
365 m_dwInfoObjNum = m_parser.GetInfoObjNum(); | 365 m_dwInfoObjNum = m_parser.GetInfoObjNum(); |
366 m_pCurrentParser = &m_parser; | 366 m_pCurrentParser = &m_parser; |
367 m_docStatus = PDF_DATAAVAIL_ROOT; | 367 m_docStatus = PDF_DATAAVAIL_ROOT; |
368 return TRUE; | 368 return TRUE; |
369 } | 369 } |
370 | 370 |
371 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, | 371 CPDF_Object* CPDF_DataAvail::GetObject(uint32_t objnum, |
372 IPDF_DataAvail::DownloadHints* pHints, | 372 IPDF_DataAvail::DownloadHints* pHints, |
373 FX_BOOL* pExistInFile) { | 373 FX_BOOL* pExistInFile) { |
374 CPDF_Object* pRet = nullptr; | 374 CPDF_Object* pRet = nullptr; |
375 FX_DWORD size = 0; | 375 uint32_t size = 0; |
376 FX_FILESIZE offset = 0; | 376 FX_FILESIZE offset = 0; |
377 CPDF_Parser* pParser = nullptr; | 377 CPDF_Parser* pParser = nullptr; |
378 | 378 |
379 if (pExistInFile) | 379 if (pExistInFile) |
380 *pExistInFile = TRUE; | 380 *pExistInFile = TRUE; |
381 | 381 |
382 if (m_pDocument) { | 382 if (m_pDocument) { |
383 size = GetObjectSize(objnum, offset); | 383 size = GetObjectSize(objnum, offset); |
384 pParser = m_pDocument->GetParser(); | 384 pParser = m_pDocument->GetParser(); |
385 } else { | 385 } else { |
386 size = (FX_DWORD)m_parser.GetObjectSize(objnum); | 386 size = (uint32_t)m_parser.GetObjectSize(objnum); |
387 offset = m_parser.GetObjectOffset(objnum); | 387 offset = m_parser.GetObjectOffset(objnum); |
388 pParser = &m_parser; | 388 pParser = &m_parser; |
389 } | 389 } |
390 | 390 |
391 if (!IsDataAvail(offset, size, pHints)) | 391 if (!IsDataAvail(offset, size, pHints)) |
392 return nullptr; | 392 return nullptr; |
393 | 393 |
394 if (pParser) | 394 if (pParser) |
395 pRet = pParser->ParseIndirectObject(nullptr, objnum); | 395 pRet = pParser->ParseIndirectObject(nullptr, objnum); |
396 | 396 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 491 |
492 bool CPDF_DataAvail::IsFirstCheck(int iPage) { | 492 bool CPDF_DataAvail::IsFirstCheck(int iPage) { |
493 return m_pageMapCheckState.insert(iPage).second; | 493 return m_pageMapCheckState.insert(iPage).second; |
494 } | 494 } |
495 | 495 |
496 void CPDF_DataAvail::ResetFirstCheck(int iPage) { | 496 void CPDF_DataAvail::ResetFirstCheck(int iPage) { |
497 m_pageMapCheckState.erase(iPage); | 497 m_pageMapCheckState.erase(iPage); |
498 } | 498 } |
499 | 499 |
500 FX_BOOL CPDF_DataAvail::CheckPage(IPDF_DataAvail::DownloadHints* pHints) { | 500 FX_BOOL CPDF_DataAvail::CheckPage(IPDF_DataAvail::DownloadHints* pHints) { |
501 FX_DWORD iPageObjs = m_PageObjList.GetSize(); | 501 uint32_t iPageObjs = m_PageObjList.GetSize(); |
502 CFX_ArrayTemplate<FX_DWORD> UnavailObjList; | 502 CFX_ArrayTemplate<uint32_t> UnavailObjList; |
503 for (FX_DWORD i = 0; i < iPageObjs; ++i) { | 503 for (uint32_t i = 0; i < iPageObjs; ++i) { |
504 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); | 504 uint32_t dwPageObjNum = m_PageObjList.GetAt(i); |
505 FX_BOOL bExist = FALSE; | 505 FX_BOOL bExist = FALSE; |
506 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); | 506 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); |
507 if (!pObj) { | 507 if (!pObj) { |
508 if (bExist) | 508 if (bExist) |
509 UnavailObjList.Add(dwPageObjNum); | 509 UnavailObjList.Add(dwPageObjNum); |
510 continue; | 510 continue; |
511 } | 511 } |
512 | 512 |
513 if (pObj->IsArray()) { | 513 if (pObj->IsArray()) { |
514 CPDF_Array* pArray = pObj->GetArray(); | 514 CPDF_Array* pArray = pObj->GetArray(); |
(...skipping 18 matching lines...) Expand all Loading... |
533 } | 533 } |
534 pObj->Release(); | 534 pObj->Release(); |
535 } | 535 } |
536 | 536 |
537 m_PageObjList.RemoveAll(); | 537 m_PageObjList.RemoveAll(); |
538 if (UnavailObjList.GetSize()) { | 538 if (UnavailObjList.GetSize()) { |
539 m_PageObjList.Append(UnavailObjList); | 539 m_PageObjList.Append(UnavailObjList); |
540 return FALSE; | 540 return FALSE; |
541 } | 541 } |
542 | 542 |
543 FX_DWORD iPages = m_PagesArray.GetSize(); | 543 uint32_t iPages = m_PagesArray.GetSize(); |
544 for (FX_DWORD i = 0; i < iPages; i++) { | 544 for (uint32_t i = 0; i < iPages; i++) { |
545 CPDF_Object* pPages = m_PagesArray.GetAt(i); | 545 CPDF_Object* pPages = m_PagesArray.GetAt(i); |
546 if (!pPages) | 546 if (!pPages) |
547 continue; | 547 continue; |
548 | 548 |
549 if (!GetPageKids(m_pCurrentParser, pPages)) { | 549 if (!GetPageKids(m_pCurrentParser, pPages)) { |
550 pPages->Release(); | 550 pPages->Release(); |
551 while (++i < iPages) { | 551 while (++i < iPages) { |
552 pPages = m_PagesArray.GetAt(i); | 552 pPages = m_PagesArray.GetAt(i); |
553 pPages->Release(); | 553 pPages->Release(); |
554 } | 554 } |
(...skipping 21 matching lines...) Expand all Loading... |
576 CPDF_Object* pKids = pDict ? pDict->GetElement("Kids") : NULL; | 576 CPDF_Object* pKids = pDict ? pDict->GetElement("Kids") : NULL; |
577 if (!pKids) | 577 if (!pKids) |
578 return TRUE; | 578 return TRUE; |
579 | 579 |
580 switch (pKids->GetType()) { | 580 switch (pKids->GetType()) { |
581 case CPDF_Object::REFERENCE: | 581 case CPDF_Object::REFERENCE: |
582 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); | 582 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); |
583 break; | 583 break; |
584 case CPDF_Object::ARRAY: { | 584 case CPDF_Object::ARRAY: { |
585 CPDF_Array* pKidsArray = pKids->AsArray(); | 585 CPDF_Array* pKidsArray = pKids->AsArray(); |
586 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 586 for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) { |
587 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i))) | 587 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i))) |
588 m_PageObjList.Add(pRef->GetRefObjNum()); | 588 m_PageObjList.Add(pRef->GetRefObjNum()); |
589 } | 589 } |
590 } break; | 590 } break; |
591 default: | 591 default: |
592 m_docStatus = PDF_DATAAVAIL_ERROR; | 592 m_docStatus = PDF_DATAAVAIL_ERROR; |
593 return FALSE; | 593 return FALSE; |
594 } | 594 } |
595 return TRUE; | 595 return TRUE; |
596 } | 596 } |
(...skipping 19 matching lines...) Expand all Loading... |
616 m_docStatus = PDF_DATAAVAIL_ERROR; | 616 m_docStatus = PDF_DATAAVAIL_ERROR; |
617 return FALSE; | 617 return FALSE; |
618 } | 618 } |
619 | 619 |
620 pPages->Release(); | 620 pPages->Release(); |
621 m_docStatus = PDF_DATAAVAIL_PAGE; | 621 m_docStatus = PDF_DATAAVAIL_PAGE; |
622 return TRUE; | 622 return TRUE; |
623 } | 623 } |
624 | 624 |
625 FX_BOOL CPDF_DataAvail::CheckHeader(IPDF_DataAvail::DownloadHints* pHints) { | 625 FX_BOOL CPDF_DataAvail::CheckHeader(IPDF_DataAvail::DownloadHints* pHints) { |
626 FX_DWORD req_size = 1024; | 626 uint32_t req_size = 1024; |
627 if ((FX_FILESIZE)req_size > m_dwFileLen) | 627 if ((FX_FILESIZE)req_size > m_dwFileLen) |
628 req_size = (FX_DWORD)m_dwFileLen; | 628 req_size = (uint32_t)m_dwFileLen; |
629 | 629 |
630 if (m_pFileAvail->IsDataAvail(0, req_size)) { | 630 if (m_pFileAvail->IsDataAvail(0, req_size)) { |
631 uint8_t buffer[1024]; | 631 uint8_t buffer[1024]; |
632 m_pFileRead->ReadBlock(buffer, 0, req_size); | 632 m_pFileRead->ReadBlock(buffer, 0, req_size); |
633 | 633 |
634 if (IsLinearizedFile(buffer, req_size)) { | 634 if (IsLinearizedFile(buffer, req_size)) { |
635 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; | 635 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; |
636 } else { | 636 } else { |
637 if (m_docStatus == PDF_DATAAVAIL_ERROR) | 637 if (m_docStatus == PDF_DATAAVAIL_ERROR) |
638 return FALSE; | 638 return FALSE; |
(...skipping 21 matching lines...) Expand all Loading... |
660 } | 660 } |
661 | 661 |
662 CPDF_Object* pFileLen = pDict ? pDict->GetElement("L") : NULL; | 662 CPDF_Object* pFileLen = pDict ? pDict->GetElement("L") : NULL; |
663 if (!pFileLen) { | 663 if (!pFileLen) { |
664 m_docStatus = PDF_DATAAVAIL_ERROR; | 664 m_docStatus = PDF_DATAAVAIL_ERROR; |
665 return FALSE; | 665 return FALSE; |
666 } | 666 } |
667 | 667 |
668 FX_BOOL bNeedDownLoad = FALSE; | 668 FX_BOOL bNeedDownLoad = FALSE; |
669 if (pEndOffSet->IsNumber()) { | 669 if (pEndOffSet->IsNumber()) { |
670 FX_DWORD dwEnd = pEndOffSet->GetInteger(); | 670 uint32_t dwEnd = pEndOffSet->GetInteger(); |
671 dwEnd += 512; | 671 dwEnd += 512; |
672 if ((FX_FILESIZE)dwEnd > m_dwFileLen) | 672 if ((FX_FILESIZE)dwEnd > m_dwFileLen) |
673 dwEnd = (FX_DWORD)m_dwFileLen; | 673 dwEnd = (uint32_t)m_dwFileLen; |
674 | 674 |
675 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 675 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
676 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 676 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
677 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 677 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
678 pHints->AddSegment(iStartPos, iSize); | 678 pHints->AddSegment(iStartPos, iSize); |
679 bNeedDownLoad = TRUE; | 679 bNeedDownLoad = TRUE; |
680 } | 680 } |
681 } | 681 } |
682 | 682 |
683 m_dwLastXRefOffset = 0; | 683 m_dwLastXRefOffset = 0; |
684 FX_FILESIZE dwFileLen = 0; | 684 FX_FILESIZE dwFileLen = 0; |
685 if (pXRefOffset->IsNumber()) | 685 if (pXRefOffset->IsNumber()) |
686 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | 686 m_dwLastXRefOffset = pXRefOffset->GetInteger(); |
687 | 687 |
688 if (pFileLen->IsNumber()) | 688 if (pFileLen->IsNumber()) |
689 dwFileLen = pFileLen->GetInteger(); | 689 dwFileLen = pFileLen->GetInteger(); |
690 | 690 |
691 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 691 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
692 (FX_DWORD)(dwFileLen - m_dwLastXRefOffset))) { | 692 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { |
693 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 693 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
694 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); | 694 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); |
695 FX_FILESIZE offset = m_dwLastXRefOffset; | 695 FX_FILESIZE offset = m_dwLastXRefOffset; |
696 if (dwSize < 512 && dwFileLen > 512) { | 696 if (dwSize < 512 && dwFileLen > 512) { |
697 dwSize = 512; | 697 dwSize = 512; |
698 offset = dwFileLen - 512; | 698 offset = dwFileLen - 512; |
699 } | 699 } |
700 pHints->AddSegment(offset, dwSize); | 700 pHints->AddSegment(offset, dwSize); |
701 } | 701 } |
702 } else { | 702 } else { |
703 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 703 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
704 } | 704 } |
705 | 705 |
706 if (bNeedDownLoad || m_docStatus != PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { | 706 if (bNeedDownLoad || m_docStatus != PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { |
707 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 707 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
708 return FALSE; | 708 return FALSE; |
709 } | 709 } |
710 | 710 |
711 m_docStatus = | 711 m_docStatus = |
712 m_bSupportHintTable ? PDF_DATAAVAIL_HINTTABLE : PDF_DATAAVAIL_DONE; | 712 m_bSupportHintTable ? PDF_DATAAVAIL_HINTTABLE : PDF_DATAAVAIL_DONE; |
713 return TRUE; | 713 return TRUE; |
714 } | 714 } |
715 | 715 |
716 FX_BOOL CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, | 716 FX_BOOL CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, |
717 FX_DWORD size, | 717 uint32_t size, |
718 IPDF_DataAvail::DownloadHints* pHints) { | 718 IPDF_DataAvail::DownloadHints* pHints) { |
719 if (offset > m_dwFileLen) | 719 if (offset > m_dwFileLen) |
720 return TRUE; | 720 return TRUE; |
721 | 721 |
722 FX_SAFE_DWORD safeSize = pdfium::base::checked_cast<FX_DWORD>(offset); | 722 FX_SAFE_DWORD safeSize = pdfium::base::checked_cast<uint32_t>(offset); |
723 safeSize += size; | 723 safeSize += size; |
724 safeSize += 512; | 724 safeSize += 512; |
725 if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) | 725 if (!safeSize.IsValid() || safeSize.ValueOrDie() > m_dwFileLen) |
726 size = m_dwFileLen - offset; | 726 size = m_dwFileLen - offset; |
727 else | 727 else |
728 size += 512; | 728 size += 512; |
729 | 729 |
730 if (!m_pFileAvail->IsDataAvail(offset, size)) { | 730 if (!m_pFileAvail->IsDataAvail(offset, size)) { |
731 pHints->AddSegment(offset, size); | 731 pHints->AddSegment(offset, size); |
732 return FALSE; | 732 return FALSE; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 CPDF_Stream* pStream = ToStream(pHintStream.get()); | 778 CPDF_Stream* pStream = ToStream(pHintStream.get()); |
779 if (pStream && pHintTables->LoadHintStream(pStream)) | 779 if (pStream && pHintTables->LoadHintStream(pStream)) |
780 m_pHintTables = std::move(pHintTables); | 780 m_pHintTables = std::move(pHintTables); |
781 | 781 |
782 m_docStatus = PDF_DATAAVAIL_DONE; | 782 m_docStatus = PDF_DATAAVAIL_DONE; |
783 return TRUE; | 783 return TRUE; |
784 } | 784 } |
785 | 785 |
786 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( | 786 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( |
787 FX_FILESIZE pos, | 787 FX_FILESIZE pos, |
788 FX_DWORD objnum, | 788 uint32_t objnum, |
789 CPDF_IndirectObjectHolder* pObjList) { | 789 CPDF_IndirectObjectHolder* pObjList) { |
790 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 790 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
791 m_syntaxParser.RestorePos(pos); | 791 m_syntaxParser.RestorePos(pos); |
792 | 792 |
793 bool bIsNumber; | 793 bool bIsNumber; |
794 CFX_ByteString word = m_syntaxParser.GetNextWord(&bIsNumber); | 794 CFX_ByteString word = m_syntaxParser.GetNextWord(&bIsNumber); |
795 if (!bIsNumber) | 795 if (!bIsNumber) |
796 return nullptr; | 796 return nullptr; |
797 | 797 |
798 FX_DWORD parser_objnum = FXSYS_atoui(word); | 798 uint32_t parser_objnum = FXSYS_atoui(word); |
799 if (objnum && parser_objnum != objnum) | 799 if (objnum && parser_objnum != objnum) |
800 return nullptr; | 800 return nullptr; |
801 | 801 |
802 word = m_syntaxParser.GetNextWord(&bIsNumber); | 802 word = m_syntaxParser.GetNextWord(&bIsNumber); |
803 if (!bIsNumber) | 803 if (!bIsNumber) |
804 return nullptr; | 804 return nullptr; |
805 | 805 |
806 FX_DWORD gennum = FXSYS_atoui(word); | 806 uint32_t gennum = FXSYS_atoui(word); |
807 if (m_syntaxParser.GetKeyword() != "obj") { | 807 if (m_syntaxParser.GetKeyword() != "obj") { |
808 m_syntaxParser.RestorePos(SavedPos); | 808 m_syntaxParser.RestorePos(SavedPos); |
809 return nullptr; | 809 return nullptr; |
810 } | 810 } |
811 | 811 |
812 CPDF_Object* pObj = | 812 CPDF_Object* pObj = |
813 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, true); | 813 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, true); |
814 m_syntaxParser.RestorePos(SavedPos); | 814 m_syntaxParser.RestorePos(SavedPos); |
815 return pObj; | 815 return pObj; |
816 } | 816 } |
817 | 817 |
818 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { | 818 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { |
819 FX_DWORD req_size = 1024; | 819 uint32_t req_size = 1024; |
820 if (!m_pFileAvail->IsDataAvail(0, req_size)) | 820 if (!m_pFileAvail->IsDataAvail(0, req_size)) |
821 return LinearizationUnknown; | 821 return LinearizationUnknown; |
822 | 822 |
823 if (!m_pFileRead) | 823 if (!m_pFileRead) |
824 return NotLinearized; | 824 return NotLinearized; |
825 | 825 |
826 FX_FILESIZE dwSize = m_pFileRead->GetSize(); | 826 FX_FILESIZE dwSize = m_pFileRead->GetSize(); |
827 if (dwSize < (FX_FILESIZE)req_size) | 827 if (dwSize < (FX_FILESIZE)req_size) |
828 return LinearizationUnknown; | 828 return LinearizationUnknown; |
829 | 829 |
830 uint8_t buffer[1024]; | 830 uint8_t buffer[1024]; |
831 m_pFileRead->ReadBlock(buffer, 0, req_size); | 831 m_pFileRead->ReadBlock(buffer, 0, req_size); |
832 if (IsLinearizedFile(buffer, req_size)) | 832 if (IsLinearizedFile(buffer, req_size)) |
833 return Linearized; | 833 return Linearized; |
834 | 834 |
835 return NotLinearized; | 835 return NotLinearized; |
836 } | 836 } |
837 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) { | 837 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { |
838 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); | 838 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); |
839 | 839 |
840 int32_t offset = GetHeaderOffset(file.get()); | 840 int32_t offset = GetHeaderOffset(file.get()); |
841 if (offset == -1) { | 841 if (offset == -1) { |
842 m_docStatus = PDF_DATAAVAIL_ERROR; | 842 m_docStatus = PDF_DATAAVAIL_ERROR; |
843 return FALSE; | 843 return FALSE; |
844 } | 844 } |
845 | 845 |
846 m_dwHeaderOffset = offset; | 846 m_dwHeaderOffset = offset; |
847 m_syntaxParser.InitParser(file.get(), offset); | 847 m_syntaxParser.InitParser(file.get(), offset); |
848 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 848 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
849 | 849 |
850 bool bNumber; | 850 bool bNumber; |
851 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); | 851 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); |
852 if (!bNumber) | 852 if (!bNumber) |
853 return FALSE; | 853 return FALSE; |
854 | 854 |
855 FX_DWORD objnum = FXSYS_atoui(wordObjNum); | 855 uint32_t objnum = FXSYS_atoui(wordObjNum); |
856 if (m_pLinearized) { | 856 if (m_pLinearized) { |
857 m_pLinearized->Release(); | 857 m_pLinearized->Release(); |
858 m_pLinearized = nullptr; | 858 m_pLinearized = nullptr; |
859 } | 859 } |
860 | 860 |
861 m_pLinearized = | 861 m_pLinearized = |
862 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 862 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); |
863 if (!m_pLinearized) | 863 if (!m_pLinearized) |
864 return FALSE; | 864 return FALSE; |
865 | 865 |
(...skipping 10 matching lines...) Expand all Loading... |
876 | 876 |
877 if (CPDF_Number* pNo = ToNumber(pDict->GetElement("P"))) | 877 if (CPDF_Number* pNo = ToNumber(pDict->GetElement("P"))) |
878 m_dwFirstPageNo = pNo->GetInteger(); | 878 m_dwFirstPageNo = pNo->GetInteger(); |
879 | 879 |
880 return TRUE; | 880 return TRUE; |
881 } | 881 } |
882 return FALSE; | 882 return FALSE; |
883 } | 883 } |
884 | 884 |
885 FX_BOOL CPDF_DataAvail::CheckEnd(IPDF_DataAvail::DownloadHints* pHints) { | 885 FX_BOOL CPDF_DataAvail::CheckEnd(IPDF_DataAvail::DownloadHints* pHints) { |
886 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 886 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
887 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 887 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); |
888 | 888 |
889 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 889 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
890 uint8_t buffer[1024]; | 890 uint8_t buffer[1024]; |
891 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 891 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
892 | 892 |
893 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); | 893 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); |
894 m_syntaxParser.InitParser(file.get(), 0); | 894 m_syntaxParser.InitParser(file.get(), 0); |
895 m_syntaxParser.RestorePos(dwSize - 1); | 895 m_syntaxParser.RestorePos(dwSize - 1); |
896 | 896 |
897 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { | 897 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { |
(...skipping 23 matching lines...) Expand all Loading... |
921 } | 921 } |
922 | 922 |
923 pHints->AddSegment(req_pos, dwSize); | 923 pHints->AddSegment(req_pos, dwSize); |
924 return FALSE; | 924 return FALSE; |
925 } | 925 } |
926 | 926 |
927 int32_t CPDF_DataAvail::CheckCrossRefStream( | 927 int32_t CPDF_DataAvail::CheckCrossRefStream( |
928 IPDF_DataAvail::DownloadHints* pHints, | 928 IPDF_DataAvail::DownloadHints* pHints, |
929 FX_FILESIZE& xref_offset) { | 929 FX_FILESIZE& xref_offset) { |
930 xref_offset = 0; | 930 xref_offset = 0; |
931 FX_DWORD req_size = | 931 uint32_t req_size = |
932 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 932 (uint32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
933 | 933 |
934 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 934 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
935 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 935 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
936 CFX_BinaryBuf buf(iSize); | 936 CFX_BinaryBuf buf(iSize); |
937 uint8_t* pBuf = buf.GetBuffer(); | 937 uint8_t* pBuf = buf.GetBuffer(); |
938 | 938 |
939 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 939 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
940 | 940 |
941 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 941 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); |
942 m_parser.m_pSyntax->InitParser(file.get(), 0); | 942 m_parser.m_pSyntax->InitParser(file.get(), 0); |
943 | 943 |
944 bool bNumber; | 944 bool bNumber; |
945 CFX_ByteString objnum = m_parser.m_pSyntax->GetNextWord(&bNumber); | 945 CFX_ByteString objnum = m_parser.m_pSyntax->GetNextWord(&bNumber); |
946 if (!bNumber) | 946 if (!bNumber) |
947 return -1; | 947 return -1; |
948 | 948 |
949 FX_DWORD objNum = FXSYS_atoui(objnum); | 949 uint32_t objNum = FXSYS_atoui(objnum); |
950 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); | 950 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); |
951 if (!pObj) { | 951 if (!pObj) { |
952 m_Pos += m_parser.m_pSyntax->SavePos(); | 952 m_Pos += m_parser.m_pSyntax->SavePos(); |
953 return 0; | 953 return 0; |
954 } | 954 } |
955 | 955 |
956 CPDF_Dictionary* pDict = pObj->GetDict(); | 956 CPDF_Dictionary* pDict = pObj->GetDict(); |
957 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); | 957 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); |
958 if (pName) { | 958 if (pName) { |
959 if (pName->GetString() == "XRef") { | 959 if (pName->GetString() == "XRef") { |
(...skipping 30 matching lines...) Expand all Loading... |
990 | 990 |
991 while (1) { | 991 while (1) { |
992 if (!GetNextChar(ch)) | 992 if (!GetNextChar(ch)) |
993 return FALSE; | 993 return FALSE; |
994 if (PDFCharIsLineEnding(ch)) | 994 if (PDFCharIsLineEnding(ch)) |
995 break; | 995 break; |
996 } | 996 } |
997 } | 997 } |
998 | 998 |
999 uint8_t buffer[256]; | 999 uint8_t buffer[256]; |
1000 FX_DWORD index = 0; | 1000 uint32_t index = 0; |
1001 if (PDFCharIsDelimiter(ch)) { | 1001 if (PDFCharIsDelimiter(ch)) { |
1002 buffer[index++] = ch; | 1002 buffer[index++] = ch; |
1003 if (ch == '/') { | 1003 if (ch == '/') { |
1004 while (1) { | 1004 while (1) { |
1005 if (!GetNextChar(ch)) | 1005 if (!GetNextChar(ch)) |
1006 return FALSE; | 1006 return FALSE; |
1007 | 1007 |
1008 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { | 1008 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { |
1009 m_Pos--; | 1009 m_Pos--; |
1010 CFX_ByteString ret(buffer, index); | 1010 CFX_ByteString ret(buffer, index); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 } | 1056 } |
1057 | 1057 |
1058 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t& ch) { | 1058 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t& ch) { |
1059 FX_FILESIZE pos = m_Pos; | 1059 FX_FILESIZE pos = m_Pos; |
1060 if (pos >= m_dwFileLen) | 1060 if (pos >= m_dwFileLen) |
1061 return FALSE; | 1061 return FALSE; |
1062 | 1062 |
1063 if (m_bufferOffset >= pos || | 1063 if (m_bufferOffset >= pos || |
1064 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { | 1064 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { |
1065 FX_FILESIZE read_pos = pos; | 1065 FX_FILESIZE read_pos = pos; |
1066 FX_DWORD read_size = 512; | 1066 uint32_t read_size = 512; |
1067 if ((FX_FILESIZE)read_size > m_dwFileLen) | 1067 if ((FX_FILESIZE)read_size > m_dwFileLen) |
1068 read_size = (FX_DWORD)m_dwFileLen; | 1068 read_size = (uint32_t)m_dwFileLen; |
1069 | 1069 |
1070 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) | 1070 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) |
1071 read_pos = m_dwFileLen - read_size; | 1071 read_pos = m_dwFileLen - read_size; |
1072 | 1072 |
1073 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) | 1073 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) |
1074 return FALSE; | 1074 return FALSE; |
1075 | 1075 |
1076 m_bufferOffset = read_pos; | 1076 m_bufferOffset = read_pos; |
1077 m_bufferSize = read_size; | 1077 m_bufferSize = read_size; |
1078 } | 1078 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 if (!pTrailer->IsDictionary()) | 1203 if (!pTrailer->IsDictionary()) |
1204 return FALSE; | 1204 return FALSE; |
1205 | 1205 |
1206 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); | 1206 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); |
1207 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); | 1207 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); |
1208 if (ToReference(pEncrypt)) { | 1208 if (ToReference(pEncrypt)) { |
1209 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1209 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1210 return TRUE; | 1210 return TRUE; |
1211 } | 1211 } |
1212 | 1212 |
1213 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, "Prev"); | 1213 uint32_t xrefpos = GetDirectInteger(pTrailerDict, "Prev"); |
1214 if (xrefpos) { | 1214 if (xrefpos) { |
1215 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, "XRefStm"); | 1215 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, "XRefStm"); |
1216 if (m_dwPrevXRefOffset) { | 1216 if (m_dwPrevXRefOffset) { |
1217 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1217 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1218 } else { | 1218 } else { |
1219 m_dwPrevXRefOffset = xrefpos; | 1219 m_dwPrevXRefOffset = xrefpos; |
1220 if (m_dwPrevXRefOffset >= m_dwFileLen) { | 1220 if (m_dwPrevXRefOffset >= m_dwFileLen) { |
1221 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 1221 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
1222 } else { | 1222 } else { |
1223 SetStartOffset(m_dwPrevXRefOffset); | 1223 SetStartOffset(m_dwPrevXRefOffset); |
(...skipping 28 matching lines...) Expand all Loading... |
1252 m_bPagesTreeLoad = TRUE; | 1252 m_bPagesTreeLoad = TRUE; |
1253 m_bPagesLoad = TRUE; | 1253 m_bPagesLoad = TRUE; |
1254 m_bCurPageDictLoadOK = TRUE; | 1254 m_bCurPageDictLoadOK = TRUE; |
1255 m_docStatus = PDF_DATAAVAIL_PAGE; | 1255 m_docStatus = PDF_DATAAVAIL_PAGE; |
1256 return TRUE; | 1256 return TRUE; |
1257 } | 1257 } |
1258 } | 1258 } |
1259 } | 1259 } |
1260 | 1260 |
1261 FX_BOOL CPDF_DataAvail::CheckArrayPageNode( | 1261 FX_BOOL CPDF_DataAvail::CheckArrayPageNode( |
1262 FX_DWORD dwPageNo, | 1262 uint32_t dwPageNo, |
1263 CPDF_DataAvail::PageNode* pPageNode, | 1263 CPDF_DataAvail::PageNode* pPageNode, |
1264 IPDF_DataAvail::DownloadHints* pHints) { | 1264 IPDF_DataAvail::DownloadHints* pHints) { |
1265 FX_BOOL bExist = FALSE; | 1265 FX_BOOL bExist = FALSE; |
1266 CPDF_Object* pPages = GetObject(dwPageNo, pHints, &bExist); | 1266 CPDF_Object* pPages = GetObject(dwPageNo, pHints, &bExist); |
1267 if (!bExist) { | 1267 if (!bExist) { |
1268 m_docStatus = PDF_DATAAVAIL_ERROR; | 1268 m_docStatus = PDF_DATAAVAIL_ERROR; |
1269 return FALSE; | 1269 return FALSE; |
1270 } | 1270 } |
1271 | 1271 |
1272 if (!pPages) { | 1272 if (!pPages) { |
1273 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 1273 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
1274 m_docStatus = PDF_DATAAVAIL_ERROR; | 1274 m_docStatus = PDF_DATAAVAIL_ERROR; |
1275 return FALSE; | 1275 return FALSE; |
1276 } | 1276 } |
1277 return FALSE; | 1277 return FALSE; |
1278 } | 1278 } |
1279 | 1279 |
1280 CPDF_Array* pArray = pPages->AsArray(); | 1280 CPDF_Array* pArray = pPages->AsArray(); |
1281 if (!pArray) { | 1281 if (!pArray) { |
1282 pPages->Release(); | 1282 pPages->Release(); |
1283 m_docStatus = PDF_DATAAVAIL_ERROR; | 1283 m_docStatus = PDF_DATAAVAIL_ERROR; |
1284 return FALSE; | 1284 return FALSE; |
1285 } | 1285 } |
1286 | 1286 |
1287 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1287 pPageNode->m_type = PDF_PAGENODE_PAGES; |
1288 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { | 1288 for (uint32_t i = 0; i < pArray->GetCount(); ++i) { |
1289 CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); | 1289 CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); |
1290 if (!pKid) | 1290 if (!pKid) |
1291 continue; | 1291 continue; |
1292 | 1292 |
1293 PageNode* pNode = new PageNode(); | 1293 PageNode* pNode = new PageNode(); |
1294 pPageNode->m_childNode.Add(pNode); | 1294 pPageNode->m_childNode.Add(pNode); |
1295 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1295 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
1296 } | 1296 } |
1297 pPages->Release(); | 1297 pPages->Release(); |
1298 return TRUE; | 1298 return TRUE; |
1299 } | 1299 } |
1300 | 1300 |
1301 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode( | 1301 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode( |
1302 FX_DWORD dwPageNo, | 1302 uint32_t dwPageNo, |
1303 CPDF_DataAvail::PageNode* pPageNode, | 1303 CPDF_DataAvail::PageNode* pPageNode, |
1304 IPDF_DataAvail::DownloadHints* pHints) { | 1304 IPDF_DataAvail::DownloadHints* pHints) { |
1305 FX_BOOL bExist = FALSE; | 1305 FX_BOOL bExist = FALSE; |
1306 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); | 1306 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); |
1307 if (!bExist) { | 1307 if (!bExist) { |
1308 m_docStatus = PDF_DATAAVAIL_ERROR; | 1308 m_docStatus = PDF_DATAAVAIL_ERROR; |
1309 return FALSE; | 1309 return FALSE; |
1310 } | 1310 } |
1311 | 1311 |
1312 if (!pPage) { | 1312 if (!pPage) { |
(...skipping 28 matching lines...) Expand all Loading... |
1341 | 1341 |
1342 switch (pKids->GetType()) { | 1342 switch (pKids->GetType()) { |
1343 case CPDF_Object::REFERENCE: { | 1343 case CPDF_Object::REFERENCE: { |
1344 CPDF_Reference* pKid = pKids->AsReference(); | 1344 CPDF_Reference* pKid = pKids->AsReference(); |
1345 PageNode* pNode = new PageNode(); | 1345 PageNode* pNode = new PageNode(); |
1346 pPageNode->m_childNode.Add(pNode); | 1346 pPageNode->m_childNode.Add(pNode); |
1347 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1347 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
1348 } break; | 1348 } break; |
1349 case CPDF_Object::ARRAY: { | 1349 case CPDF_Object::ARRAY: { |
1350 CPDF_Array* pKidsArray = pKids->AsArray(); | 1350 CPDF_Array* pKidsArray = pKids->AsArray(); |
1351 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 1351 for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) { |
1352 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); | 1352 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); |
1353 if (!pKid) | 1353 if (!pKid) |
1354 continue; | 1354 continue; |
1355 | 1355 |
1356 PageNode* pNode = new PageNode(); | 1356 PageNode* pNode = new PageNode(); |
1357 pPageNode->m_childNode.Add(pNode); | 1357 pPageNode->m_childNode.Add(pNode); |
1358 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1358 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
1359 } | 1359 } |
1360 } break; | 1360 } break; |
1361 default: | 1361 default: |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 m_bAnnotsLoad = FALSE; | 1616 m_bAnnotsLoad = FALSE; |
1617 m_bNeedDownLoadResource = FALSE; | 1617 m_bNeedDownLoadResource = FALSE; |
1618 m_objs_array.RemoveAll(); | 1618 m_objs_array.RemoveAll(); |
1619 m_ObjectSet.clear(); | 1619 m_ObjectSet.clear(); |
1620 } | 1620 } |
1621 | 1621 |
1622 if (pdfium::ContainsKey(m_pagesLoadState, iPage)) | 1622 if (pdfium::ContainsKey(m_pagesLoadState, iPage)) |
1623 return DataAvailable; | 1623 return DataAvailable; |
1624 | 1624 |
1625 if (m_bLinearized) { | 1625 if (m_bLinearized) { |
1626 if ((FX_DWORD)iPage == m_dwFirstPageNo) { | 1626 if ((uint32_t)iPage == m_dwFirstPageNo) { |
1627 DocAvailStatus nRet = CheckLinearizedFirstPage(iPage, pHints); | 1627 DocAvailStatus nRet = CheckLinearizedFirstPage(iPage, pHints); |
1628 if (nRet == DataAvailable) | 1628 if (nRet == DataAvailable) |
1629 m_pagesLoadState.insert(iPage); | 1629 m_pagesLoadState.insert(iPage); |
1630 return nRet; | 1630 return nRet; |
1631 } | 1631 } |
1632 | 1632 |
1633 DocAvailStatus nResult = CheckLinearizedData(pHints); | 1633 DocAvailStatus nResult = CheckLinearizedData(pHints); |
1634 if (nResult != DataAvailable) | 1634 if (nResult != DataAvailable) |
1635 return nResult; | 1635 return nResult; |
1636 | 1636 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 | 1746 |
1747 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 1747 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; |
1748 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1748 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); |
1749 m_objs_array.RemoveAll(); | 1749 m_objs_array.RemoveAll(); |
1750 if (!bRet) | 1750 if (!bRet) |
1751 m_objs_array.Append(new_objs_array); | 1751 m_objs_array.Append(new_objs_array); |
1752 return bRet; | 1752 return bRet; |
1753 } | 1753 } |
1754 | 1754 |
1755 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, | 1755 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, |
1756 FX_DWORD* pSize) { | 1756 uint32_t* pSize) { |
1757 if (pPos) | 1757 if (pPos) |
1758 *pPos = m_dwLastXRefOffset; | 1758 *pPos = m_dwLastXRefOffset; |
1759 if (pSize) | 1759 if (pSize) |
1760 *pSize = (FX_DWORD)(m_dwFileLen - m_dwLastXRefOffset); | 1760 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); |
1761 } | 1761 } |
1762 | 1762 |
1763 int CPDF_DataAvail::GetPageCount() const { | 1763 int CPDF_DataAvail::GetPageCount() const { |
1764 if (m_pLinearized) { | 1764 if (m_pLinearized) { |
1765 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1765 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
1766 CPDF_Object* pObj = pDict ? pDict->GetElementValue("N") : nullptr; | 1766 CPDF_Object* pObj = pDict ? pDict->GetElementValue("N") : nullptr; |
1767 return pObj ? pObj->GetInteger() : 0; | 1767 return pObj ? pObj->GetInteger() : 0; |
1768 } | 1768 } |
1769 return m_pDocument ? m_pDocument->GetPageCount() : 0; | 1769 return m_pDocument ? m_pDocument->GetPageCount() : 0; |
1770 } | 1770 } |
1771 | 1771 |
1772 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { | 1772 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { |
1773 if (!m_pDocument || index < 0 || index >= GetPageCount()) | 1773 if (!m_pDocument || index < 0 || index >= GetPageCount()) |
1774 return nullptr; | 1774 return nullptr; |
1775 | 1775 |
1776 if (m_pLinearized) { | 1776 if (m_pLinearized) { |
1777 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1777 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
1778 CPDF_Object* pObj = pDict ? pDict->GetElementValue("P") : nullptr; | 1778 CPDF_Object* pObj = pDict ? pDict->GetElementValue("P") : nullptr; |
1779 | 1779 |
1780 int pageNum = pObj ? pObj->GetInteger() : 0; | 1780 int pageNum = pObj ? pObj->GetInteger() : 0; |
1781 if (m_pHintTables && index != pageNum) { | 1781 if (m_pHintTables && index != pageNum) { |
1782 FX_FILESIZE szPageStartPos = 0; | 1782 FX_FILESIZE szPageStartPos = 0; |
1783 FX_FILESIZE szPageLength = 0; | 1783 FX_FILESIZE szPageLength = 0; |
1784 FX_DWORD dwObjNum = 0; | 1784 uint32_t dwObjNum = 0; |
1785 FX_BOOL bPagePosGot = m_pHintTables->GetPagePos(index, szPageStartPos, | 1785 FX_BOOL bPagePosGot = m_pHintTables->GetPagePos(index, szPageStartPos, |
1786 szPageLength, dwObjNum); | 1786 szPageLength, dwObjNum); |
1787 if (!bPagePosGot) | 1787 if (!bPagePosGot) |
1788 return nullptr; | 1788 return nullptr; |
1789 | 1789 |
1790 m_syntaxParser.InitParser(m_pFileRead, (FX_DWORD)szPageStartPos); | 1790 m_syntaxParser.InitParser(m_pFileRead, (uint32_t)szPageStartPos); |
1791 CPDF_Object* pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument); | 1791 CPDF_Object* pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument); |
1792 if (!pPageDict) | 1792 if (!pPageDict) |
1793 return nullptr; | 1793 return nullptr; |
1794 | 1794 |
1795 if (!m_pDocument->InsertIndirectObject(dwObjNum, pPageDict)) | 1795 if (!m_pDocument->InsertIndirectObject(dwObjNum, pPageDict)) |
1796 return nullptr; | 1796 return nullptr; |
1797 return pPageDict->GetDict(); | 1797 return pPageDict->GetDict(); |
1798 } | 1798 } |
1799 } | 1799 } |
1800 return m_pDocument->GetPage(index); | 1800 return m_pDocument->GetPage(index); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 return FormAvailable; | 1835 return FormAvailable; |
1836 } | 1836 } |
1837 | 1837 |
1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
1839 | 1839 |
1840 CPDF_DataAvail::PageNode::~PageNode() { | 1840 CPDF_DataAvail::PageNode::~PageNode() { |
1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
1842 delete m_childNode[i]; | 1842 delete m_childNode[i]; |
1843 m_childNode.RemoveAll(); | 1843 m_childNode.RemoveAll(); |
1844 } | 1844 } |
OLD | NEW |