OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "third_party/base/stl_util.h" | 24 #include "third_party/base/stl_util.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // A limit on the size of the xref table. Theoretical limits are higher, but | 28 // A limit on the size of the xref table. Theoretical limits are higher, but |
29 // this may be large enough in practice. | 29 // this may be large enough in practice. |
30 const int32_t kMaxXRefSize = 1048576; | 30 const int32_t kMaxXRefSize = 1048576; |
31 | 31 |
32 // A limit on the maximum object number in the xref table. Theoretical limits | 32 // A limit on the maximum object number in the xref table. Theoretical limits |
33 // are higher, but this may be large enough in practice. | 33 // are higher, but this may be large enough in practice. |
34 const FX_DWORD kMaxObjectNumber = 1048576; | 34 const uint32_t kMaxObjectNumber = 1048576; |
35 | 35 |
36 FX_DWORD GetVarInt(const uint8_t* p, int32_t n) { | 36 uint32_t GetVarInt(const uint8_t* p, int32_t n) { |
37 FX_DWORD result = 0; | 37 uint32_t result = 0; |
38 for (int32_t i = 0; i < n; ++i) | 38 for (int32_t i = 0; i < n; ++i) |
39 result = result * 256 + p[i]; | 39 result = result * 256 + p[i]; |
40 return result; | 40 return result; |
41 } | 41 } |
42 | 42 |
43 int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) { | 43 int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) { |
44 return pObjStream->GetDict()->GetIntegerBy("N"); | 44 return pObjStream->GetDict()->GetIntegerBy("N"); |
45 } | 45 } |
46 | 46 |
47 int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) { | 47 int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) { |
(...skipping 12 matching lines...) Expand all Loading... |
60 m_pLinearized(nullptr), | 60 m_pLinearized(nullptr), |
61 m_dwFirstPageNo(0), | 61 m_dwFirstPageNo(0), |
62 m_dwXrefStartObjNum(0) { | 62 m_dwXrefStartObjNum(0) { |
63 m_pSyntax.reset(new CPDF_SyntaxParser); | 63 m_pSyntax.reset(new CPDF_SyntaxParser); |
64 } | 64 } |
65 | 65 |
66 CPDF_Parser::~CPDF_Parser() { | 66 CPDF_Parser::~CPDF_Parser() { |
67 CloseParser(); | 67 CloseParser(); |
68 } | 68 } |
69 | 69 |
70 FX_DWORD CPDF_Parser::GetLastObjNum() const { | 70 uint32_t CPDF_Parser::GetLastObjNum() const { |
71 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; | 71 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; |
72 } | 72 } |
73 | 73 |
74 bool CPDF_Parser::IsValidObjectNumber(FX_DWORD objnum) const { | 74 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const { |
75 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; | 75 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; |
76 } | 76 } |
77 | 77 |
78 FX_FILESIZE CPDF_Parser::GetObjectPositionOrZero(FX_DWORD objnum) const { | 78 FX_FILESIZE CPDF_Parser::GetObjectPositionOrZero(uint32_t objnum) const { |
79 auto it = m_ObjectInfo.find(objnum); | 79 auto it = m_ObjectInfo.find(objnum); |
80 return it != m_ObjectInfo.end() ? it->second.pos : 0; | 80 return it != m_ObjectInfo.end() ? it->second.pos : 0; |
81 } | 81 } |
82 | 82 |
83 uint8_t CPDF_Parser::GetObjectType(FX_DWORD objnum) const { | 83 uint8_t CPDF_Parser::GetObjectType(uint32_t objnum) const { |
84 ASSERT(IsValidObjectNumber(objnum)); | 84 ASSERT(IsValidObjectNumber(objnum)); |
85 auto it = m_ObjectInfo.find(objnum); | 85 auto it = m_ObjectInfo.find(objnum); |
86 return it != m_ObjectInfo.end() ? it->second.type : 0; | 86 return it != m_ObjectInfo.end() ? it->second.type : 0; |
87 } | 87 } |
88 | 88 |
89 uint16_t CPDF_Parser::GetObjectGenNum(FX_DWORD objnum) const { | 89 uint16_t CPDF_Parser::GetObjectGenNum(uint32_t objnum) const { |
90 ASSERT(IsValidObjectNumber(objnum)); | 90 ASSERT(IsValidObjectNumber(objnum)); |
91 auto it = m_ObjectInfo.find(objnum); | 91 auto it = m_ObjectInfo.find(objnum); |
92 return it != m_ObjectInfo.end() ? it->second.gennum : 0; | 92 return it != m_ObjectInfo.end() ? it->second.gennum : 0; |
93 } | 93 } |
94 | 94 |
95 bool CPDF_Parser::IsObjectFreeOrNull(FX_DWORD objnum) const { | 95 bool CPDF_Parser::IsObjectFreeOrNull(uint32_t objnum) const { |
96 uint8_t type = GetObjectType(objnum); | 96 uint8_t type = GetObjectType(objnum); |
97 return type == 0 || type == 255; | 97 return type == 0 || type == 255; |
98 } | 98 } |
99 | 99 |
100 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { | 100 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { |
101 m_pEncryptDict = pDict; | 101 m_pEncryptDict = pDict; |
102 } | 102 } |
103 | 103 |
104 IPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() { | 104 IPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() { |
105 return m_pSyntax->m_pCryptoHandler.get(); | 105 return m_pSyntax->m_pCryptoHandler.get(); |
106 } | 106 } |
107 | 107 |
108 IFX_FileRead* CPDF_Parser::GetFileAccess() const { | 108 IFX_FileRead* CPDF_Parser::GetFileAccess() const { |
109 return m_pSyntax->m_pFileAccess; | 109 return m_pSyntax->m_pFileAccess; |
110 } | 110 } |
111 | 111 |
112 void CPDF_Parser::ShrinkObjectMap(FX_DWORD objnum) { | 112 void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { |
113 if (objnum == 0) { | 113 if (objnum == 0) { |
114 m_ObjectInfo.clear(); | 114 m_ObjectInfo.clear(); |
115 return; | 115 return; |
116 } | 116 } |
117 | 117 |
118 auto it = m_ObjectInfo.lower_bound(objnum); | 118 auto it = m_ObjectInfo.lower_bound(objnum); |
119 while (it != m_ObjectInfo.end()) { | 119 while (it != m_ObjectInfo.end()) { |
120 auto saved_it = it++; | 120 auto saved_it = it++; |
121 m_ObjectInfo.erase(saved_it); | 121 m_ObjectInfo.erase(saved_it); |
122 } | 122 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 m_pSyntax->SetEncrypt(std::move(pCryptoHandler)); | 295 m_pSyntax->SetEncrypt(std::move(pCryptoHandler)); |
296 } | 296 } |
297 return SUCCESS; | 297 return SUCCESS; |
298 } | 298 } |
299 | 299 |
300 void CPDF_Parser::ReleaseEncryptHandler() { | 300 void CPDF_Parser::ReleaseEncryptHandler() { |
301 m_pSyntax->m_pCryptoHandler.reset(); | 301 m_pSyntax->m_pCryptoHandler.reset(); |
302 m_pSecurityHandler.reset(); | 302 m_pSecurityHandler.reset(); |
303 } | 303 } |
304 | 304 |
305 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) const { | 305 FX_FILESIZE CPDF_Parser::GetObjectOffset(uint32_t objnum) const { |
306 if (!IsValidObjectNumber(objnum)) | 306 if (!IsValidObjectNumber(objnum)) |
307 return 0; | 307 return 0; |
308 | 308 |
309 if (GetObjectType(objnum) == 1) | 309 if (GetObjectType(objnum) == 1) |
310 return GetObjectPositionOrZero(objnum); | 310 return GetObjectPositionOrZero(objnum); |
311 | 311 |
312 if (GetObjectType(objnum) == 2) { | 312 if (GetObjectType(objnum) == 2) { |
313 FX_FILESIZE pos = GetObjectPositionOrZero(objnum); | 313 FX_FILESIZE pos = GetObjectPositionOrZero(objnum); |
314 return GetObjectPositionOrZero(pos); | 314 return GetObjectPositionOrZero(pos); |
315 } | 315 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 364 } |
365 | 365 |
366 for (size_t i = 0; i < CrossRefList.size(); ++i) { | 366 for (size_t i = 0; i < CrossRefList.size(); ++i) { |
367 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) | 367 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) |
368 return FALSE; | 368 return FALSE; |
369 } | 369 } |
370 return TRUE; | 370 return TRUE; |
371 } | 371 } |
372 | 372 |
373 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, | 373 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, |
374 FX_DWORD dwObjCount) { | 374 uint32_t dwObjCount) { |
375 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) | 375 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) |
376 return FALSE; | 376 return FALSE; |
377 | 377 |
378 m_pTrailer = LoadTrailerV4(); | 378 m_pTrailer = LoadTrailerV4(); |
379 if (!m_pTrailer) | 379 if (!m_pTrailer) |
380 return FALSE; | 380 return FALSE; |
381 | 381 |
382 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); | 382 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); |
383 if (xrefsize == 0) | 383 if (xrefsize == 0) |
384 return FALSE; | 384 return FALSE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 417 } |
418 | 418 |
419 for (size_t i = 1; i < CrossRefList.size(); ++i) { | 419 for (size_t i = 1; i < CrossRefList.size(); ++i) { |
420 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) | 420 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) |
421 return FALSE; | 421 return FALSE; |
422 } | 422 } |
423 return TRUE; | 423 return TRUE; |
424 } | 424 } |
425 | 425 |
426 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, | 426 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, |
427 FX_DWORD dwObjCount) { | 427 uint32_t dwObjCount) { |
428 FX_FILESIZE dwStartPos = pos - m_pSyntax->m_HeaderOffset; | 428 FX_FILESIZE dwStartPos = pos - m_pSyntax->m_HeaderOffset; |
429 | 429 |
430 m_pSyntax->RestorePos(dwStartPos); | 430 m_pSyntax->RestorePos(dwStartPos); |
431 m_SortedOffset.insert(pos); | 431 m_SortedOffset.insert(pos); |
432 | 432 |
433 FX_DWORD start_objnum = 0; | 433 uint32_t start_objnum = 0; |
434 FX_DWORD count = dwObjCount; | 434 uint32_t count = dwObjCount; |
435 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 435 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
436 | 436 |
437 const int32_t recordsize = 20; | 437 const int32_t recordsize = 20; |
438 std::vector<char> buf(1024 * recordsize + 1); | 438 std::vector<char> buf(1024 * recordsize + 1); |
439 buf[1024 * recordsize] = '\0'; | 439 buf[1024 * recordsize] = '\0'; |
440 | 440 |
441 int32_t nBlocks = count / 1024 + 1; | 441 int32_t nBlocks = count / 1024 + 1; |
442 for (int32_t block = 0; block < nBlocks; block++) { | 442 for (int32_t block = 0; block < nBlocks; block++) { |
443 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 443 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
444 FX_DWORD dwReadSize = block_size * recordsize; | 444 uint32_t dwReadSize = block_size * recordsize; |
445 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_pSyntax->m_FileLen) | 445 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_pSyntax->m_FileLen) |
446 return FALSE; | 446 return FALSE; |
447 | 447 |
448 if (!m_pSyntax->ReadBlock(reinterpret_cast<uint8_t*>(buf.data()), | 448 if (!m_pSyntax->ReadBlock(reinterpret_cast<uint8_t*>(buf.data()), |
449 dwReadSize)) { | 449 dwReadSize)) { |
450 return FALSE; | 450 return FALSE; |
451 } | 451 } |
452 | 452 |
453 for (int32_t i = 0; i < block_size; i++) { | 453 for (int32_t i = 0; i < block_size; i++) { |
454 FX_DWORD objnum = start_objnum + block * 1024 + i; | 454 uint32_t objnum = start_objnum + block * 1024 + i; |
455 char* pEntry = &buf[i * recordsize]; | 455 char* pEntry = &buf[i * recordsize]; |
456 if (pEntry[17] == 'f') { | 456 if (pEntry[17] == 'f') { |
457 m_ObjectInfo[objnum].pos = 0; | 457 m_ObjectInfo[objnum].pos = 0; |
458 m_ObjectInfo[objnum].type = 0; | 458 m_ObjectInfo[objnum].type = 0; |
459 } else { | 459 } else { |
460 int32_t offset = FXSYS_atoi(pEntry); | 460 int32_t offset = FXSYS_atoi(pEntry); |
461 if (offset == 0) { | 461 if (offset == 0) { |
462 for (int32_t c = 0; c < 10; c++) { | 462 for (int32_t c = 0; c < 10; c++) { |
463 if (!std::isdigit(pEntry[c])) | 463 if (!std::isdigit(pEntry[c])) |
464 return FALSE; | 464 return FALSE; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 bool bIsNumber; | 498 bool bIsNumber; |
499 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 499 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
500 if (word.IsEmpty()) | 500 if (word.IsEmpty()) |
501 return false; | 501 return false; |
502 | 502 |
503 if (!bIsNumber) { | 503 if (!bIsNumber) { |
504 m_pSyntax->RestorePos(SavedPos); | 504 m_pSyntax->RestorePos(SavedPos); |
505 break; | 505 break; |
506 } | 506 } |
507 | 507 |
508 FX_DWORD start_objnum = FXSYS_atoui(word); | 508 uint32_t start_objnum = FXSYS_atoui(word); |
509 if (start_objnum >= kMaxObjectNumber) | 509 if (start_objnum >= kMaxObjectNumber) |
510 return false; | 510 return false; |
511 | 511 |
512 FX_DWORD count = m_pSyntax->GetDirectNum(); | 512 uint32_t count = m_pSyntax->GetDirectNum(); |
513 m_pSyntax->ToNextWord(); | 513 m_pSyntax->ToNextWord(); |
514 SavedPos = m_pSyntax->SavePos(); | 514 SavedPos = m_pSyntax->SavePos(); |
515 const int32_t recordsize = 20; | 515 const int32_t recordsize = 20; |
516 | 516 |
517 m_dwXrefStartObjNum = start_objnum; | 517 m_dwXrefStartObjNum = start_objnum; |
518 if (!bSkip) { | 518 if (!bSkip) { |
519 std::vector<char> buf(1024 * recordsize + 1); | 519 std::vector<char> buf(1024 * recordsize + 1); |
520 buf[1024 * recordsize] = '\0'; | 520 buf[1024 * recordsize] = '\0'; |
521 | 521 |
522 int32_t nBlocks = count / 1024 + 1; | 522 int32_t nBlocks = count / 1024 + 1; |
523 for (int32_t block = 0; block < nBlocks; block++) { | 523 for (int32_t block = 0; block < nBlocks; block++) { |
524 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 524 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
525 m_pSyntax->ReadBlock(reinterpret_cast<uint8_t*>(buf.data()), | 525 m_pSyntax->ReadBlock(reinterpret_cast<uint8_t*>(buf.data()), |
526 block_size * recordsize); | 526 block_size * recordsize); |
527 | 527 |
528 for (int32_t i = 0; i < block_size; i++) { | 528 for (int32_t i = 0; i < block_size; i++) { |
529 FX_DWORD objnum = start_objnum + block * 1024 + i; | 529 uint32_t objnum = start_objnum + block * 1024 + i; |
530 char* pEntry = &buf[i * recordsize]; | 530 char* pEntry = &buf[i * recordsize]; |
531 if (pEntry[17] == 'f') { | 531 if (pEntry[17] == 'f') { |
532 m_ObjectInfo[objnum].pos = 0; | 532 m_ObjectInfo[objnum].pos = 0; |
533 m_ObjectInfo[objnum].type = 0; | 533 m_ObjectInfo[objnum].type = 0; |
534 } else { | 534 } else { |
535 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 535 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
536 if (offset == 0) { | 536 if (offset == 0) { |
537 for (int32_t c = 0; c < 10; c++) { | 537 for (int32_t c = 0; c < 10; c++) { |
538 if (!std::isdigit(pEntry[c])) | 538 if (!std::isdigit(pEntry[c])) |
539 return false; | 539 return false; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 m_ObjectInfo.clear(); | 582 m_ObjectInfo.clear(); |
583 m_SortedOffset.clear(); | 583 m_SortedOffset.clear(); |
584 if (m_pTrailer) { | 584 if (m_pTrailer) { |
585 m_pTrailer->Release(); | 585 m_pTrailer->Release(); |
586 m_pTrailer = nullptr; | 586 m_pTrailer = nullptr; |
587 } | 587 } |
588 | 588 |
589 ParserState state = ParserState::kDefault; | 589 ParserState state = ParserState::kDefault; |
590 | 590 |
591 int32_t inside_index = 0; | 591 int32_t inside_index = 0; |
592 FX_DWORD objnum = 0; | 592 uint32_t objnum = 0; |
593 FX_DWORD gennum = 0; | 593 uint32_t gennum = 0; |
594 int32_t depth = 0; | 594 int32_t depth = 0; |
595 | 595 |
596 const FX_DWORD kBufferSize = 4096; | 596 const uint32_t kBufferSize = 4096; |
597 std::vector<uint8_t> buffer(kBufferSize); | 597 std::vector<uint8_t> buffer(kBufferSize); |
598 | 598 |
599 FX_FILESIZE pos = m_pSyntax->m_HeaderOffset; | 599 FX_FILESIZE pos = m_pSyntax->m_HeaderOffset; |
600 FX_FILESIZE start_pos = 0; | 600 FX_FILESIZE start_pos = 0; |
601 FX_FILESIZE start_pos1 = 0; | 601 FX_FILESIZE start_pos1 = 0; |
602 FX_FILESIZE last_obj = -1; | 602 FX_FILESIZE last_obj = -1; |
603 FX_FILESIZE last_xref = -1; | 603 FX_FILESIZE last_xref = -1; |
604 FX_FILESIZE last_trailer = -1; | 604 FX_FILESIZE last_trailer = -1; |
605 | 605 |
606 while (pos < m_pSyntax->m_FileLen) { | 606 while (pos < m_pSyntax->m_FileLen) { |
607 const FX_FILESIZE saved_pos = pos; | 607 const FX_FILESIZE saved_pos = pos; |
608 bool bOverFlow = false; | 608 bool bOverFlow = false; |
609 FX_DWORD size = | 609 uint32_t size = |
610 std::min((FX_DWORD)(m_pSyntax->m_FileLen - pos), kBufferSize); | 610 std::min((uint32_t)(m_pSyntax->m_FileLen - pos), kBufferSize); |
611 if (!m_pSyntax->m_pFileAccess->ReadBlock(buffer.data(), pos, size)) | 611 if (!m_pSyntax->m_pFileAccess->ReadBlock(buffer.data(), pos, size)) |
612 break; | 612 break; |
613 | 613 |
614 for (FX_DWORD i = 0; i < size; i++) { | 614 for (uint32_t i = 0; i < size; i++) { |
615 uint8_t byte = buffer[i]; | 615 uint8_t byte = buffer[i]; |
616 switch (state) { | 616 switch (state) { |
617 case ParserState::kDefault: | 617 case ParserState::kDefault: |
618 if (PDFCharIsWhitespace(byte)) { | 618 if (PDFCharIsWhitespace(byte)) { |
619 state = ParserState::kWhitespace; | 619 state = ParserState::kWhitespace; |
620 } else if (std::isdigit(byte)) { | 620 } else if (std::isdigit(byte)) { |
621 --i; | 621 --i; |
622 state = ParserState::kWhitespace; | 622 state = ParserState::kWhitespace; |
623 } else if (byte == '%') { | 623 } else if (byte == '%') { |
624 inside_index = 0; | 624 inside_index = 0; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 | 756 |
757 FX_FILESIZE offset = 0; | 757 FX_FILESIZE offset = 0; |
758 m_pSyntax->RestorePos(obj_pos); | 758 m_pSyntax->RestorePos(obj_pos); |
759 offset = m_pSyntax->FindTag("obj", 0); | 759 offset = m_pSyntax->FindTag("obj", 0); |
760 if (offset == -1) | 760 if (offset == -1) |
761 offset = 0; | 761 offset = 0; |
762 else | 762 else |
763 offset += 3; | 763 offset += 3; |
764 | 764 |
765 FX_FILESIZE nLen = obj_end - obj_pos - offset; | 765 FX_FILESIZE nLen = obj_end - obj_pos - offset; |
766 if ((FX_DWORD)nLen > size - i) { | 766 if ((uint32_t)nLen > size - i) { |
767 pos = obj_end + m_pSyntax->m_HeaderOffset; | 767 pos = obj_end + m_pSyntax->m_HeaderOffset; |
768 bOverFlow = true; | 768 bOverFlow = true; |
769 } else { | 769 } else { |
770 i += (FX_DWORD)nLen; | 770 i += (uint32_t)nLen; |
771 } | 771 } |
772 | 772 |
773 if (!m_ObjectInfo.empty() && IsValidObjectNumber(objnum) && | 773 if (!m_ObjectInfo.empty() && IsValidObjectNumber(objnum) && |
774 m_ObjectInfo[objnum].pos) { | 774 m_ObjectInfo[objnum].pos) { |
775 if (pObject) { | 775 if (pObject) { |
776 FX_DWORD oldgen = GetObjectGenNum(objnum); | 776 uint32_t oldgen = GetObjectGenNum(objnum); |
777 m_ObjectInfo[objnum].pos = obj_pos; | 777 m_ObjectInfo[objnum].pos = obj_pos; |
778 m_ObjectInfo[objnum].gennum = gennum; | 778 m_ObjectInfo[objnum].gennum = gennum; |
779 if (oldgen != gennum) | 779 if (oldgen != gennum) |
780 m_bVersionUpdated = true; | 780 m_bVersionUpdated = true; |
781 } | 781 } |
782 } else { | 782 } else { |
783 m_ObjectInfo[objnum].pos = obj_pos; | 783 m_ObjectInfo[objnum].pos = obj_pos; |
784 m_ObjectInfo[objnum].type = 1; | 784 m_ObjectInfo[objnum].type = 1; |
785 m_ObjectInfo[objnum].gennum = gennum; | 785 m_ObjectInfo[objnum].gennum = gennum; |
786 } | 786 } |
(...skipping 25 matching lines...) Expand all Loading... |
812 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 812 CPDF_Object* pRoot = pTrailer->GetElement("Root"); |
813 CPDF_Reference* pRef = ToReference(pRoot); | 813 CPDF_Reference* pRef = ToReference(pRoot); |
814 if (!pRoot || | 814 if (!pRoot || |
815 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 815 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
816 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 816 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
817 auto it = pTrailer->begin(); | 817 auto it = pTrailer->begin(); |
818 while (it != pTrailer->end()) { | 818 while (it != pTrailer->end()) { |
819 const CFX_ByteString& key = it->first; | 819 const CFX_ByteString& key = it->first; |
820 CPDF_Object* pElement = it->second; | 820 CPDF_Object* pElement = it->second; |
821 ++it; | 821 ++it; |
822 FX_DWORD dwObjNum = | 822 uint32_t dwObjNum = |
823 pElement ? pElement->GetObjNum() : 0; | 823 pElement ? pElement->GetObjNum() : 0; |
824 if (dwObjNum) { | 824 if (dwObjNum) { |
825 m_pTrailer->SetAtReference(key, m_pDocument, | 825 m_pTrailer->SetAtReference(key, m_pDocument, |
826 dwObjNum); | 826 dwObjNum); |
827 } else { | 827 } else { |
828 m_pTrailer->SetAt(key, pElement->Clone()); | 828 m_pTrailer->SetAt(key, pElement->Clone()); |
829 } | 829 } |
830 } | 830 } |
831 } | 831 } |
832 pObj->Release(); | 832 pObj->Release(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 ShrinkObjectMap(size); | 980 ShrinkObjectMap(size); |
981 for (auto& it : m_ObjectInfo) | 981 for (auto& it : m_ObjectInfo) |
982 it.second.type = 0; | 982 it.second.type = 0; |
983 } else { | 983 } else { |
984 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); | 984 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); |
985 } | 985 } |
986 | 986 |
987 std::vector<std::pair<int32_t, int32_t>> arrIndex; | 987 std::vector<std::pair<int32_t, int32_t>> arrIndex; |
988 CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index"); | 988 CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index"); |
989 if (pArray) { | 989 if (pArray) { |
990 FX_DWORD nPairSize = pArray->GetCount() / 2; | 990 uint32_t nPairSize = pArray->GetCount() / 2; |
991 for (FX_DWORD i = 0; i < nPairSize; i++) { | 991 for (uint32_t i = 0; i < nPairSize; i++) { |
992 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); | 992 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); |
993 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); | 993 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); |
994 | 994 |
995 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { | 995 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { |
996 int nStartNum = pStartNumObj->GetInteger(); | 996 int nStartNum = pStartNumObj->GetInteger(); |
997 int nCount = pCountObj->GetInteger(); | 997 int nCount = pCountObj->GetInteger(); |
998 if (nStartNum >= 0 && nCount > 0) | 998 if (nStartNum >= 0 && nCount > 0) |
999 arrIndex.push_back(std::make_pair(nStartNum, nCount)); | 999 arrIndex.push_back(std::make_pair(nStartNum, nCount)); |
1000 } | 1000 } |
1001 } | 1001 } |
1002 } | 1002 } |
1003 | 1003 |
1004 if (arrIndex.size() == 0) | 1004 if (arrIndex.size() == 0) |
1005 arrIndex.push_back(std::make_pair(0, size)); | 1005 arrIndex.push_back(std::make_pair(0, size)); |
1006 | 1006 |
1007 pArray = pStream->GetDict()->GetArrayBy("W"); | 1007 pArray = pStream->GetDict()->GetArrayBy("W"); |
1008 if (!pArray) { | 1008 if (!pArray) { |
1009 pStream->Release(); | 1009 pStream->Release(); |
1010 return FALSE; | 1010 return FALSE; |
1011 } | 1011 } |
1012 | 1012 |
1013 CFX_ArrayTemplate<FX_DWORD> WidthArray; | 1013 CFX_ArrayTemplate<uint32_t> WidthArray; |
1014 FX_SAFE_DWORD dwAccWidth = 0; | 1014 FX_SAFE_DWORD dwAccWidth = 0; |
1015 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 1015 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
1016 WidthArray.Add(pArray->GetIntegerAt(i)); | 1016 WidthArray.Add(pArray->GetIntegerAt(i)); |
1017 dwAccWidth += WidthArray[i]; | 1017 dwAccWidth += WidthArray[i]; |
1018 } | 1018 } |
1019 | 1019 |
1020 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { | 1020 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { |
1021 pStream->Release(); | 1021 pStream->Release(); |
1022 return FALSE; | 1022 return FALSE; |
1023 } | 1023 } |
1024 | 1024 |
1025 FX_DWORD totalWidth = dwAccWidth.ValueOrDie(); | 1025 uint32_t totalWidth = dwAccWidth.ValueOrDie(); |
1026 CPDF_StreamAcc acc; | 1026 CPDF_StreamAcc acc; |
1027 acc.LoadAllData(pStream); | 1027 acc.LoadAllData(pStream); |
1028 | 1028 |
1029 const uint8_t* pData = acc.GetData(); | 1029 const uint8_t* pData = acc.GetData(); |
1030 FX_DWORD dwTotalSize = acc.GetSize(); | 1030 uint32_t dwTotalSize = acc.GetSize(); |
1031 FX_DWORD segindex = 0; | 1031 uint32_t segindex = 0; |
1032 for (FX_DWORD i = 0; i < arrIndex.size(); i++) { | 1032 for (uint32_t i = 0; i < arrIndex.size(); i++) { |
1033 int32_t startnum = arrIndex[i].first; | 1033 int32_t startnum = arrIndex[i].first; |
1034 if (startnum < 0) | 1034 if (startnum < 0) |
1035 continue; | 1035 continue; |
1036 | 1036 |
1037 m_dwXrefStartObjNum = | 1037 m_dwXrefStartObjNum = |
1038 pdfium::base::checked_cast<FX_DWORD, int32_t>(startnum); | 1038 pdfium::base::checked_cast<uint32_t, int32_t>(startnum); |
1039 FX_DWORD count = | 1039 uint32_t count = |
1040 pdfium::base::checked_cast<FX_DWORD, int32_t>(arrIndex[i].second); | 1040 pdfium::base::checked_cast<uint32_t, int32_t>(arrIndex[i].second); |
1041 FX_SAFE_DWORD dwCaculatedSize = segindex; | 1041 FX_SAFE_DWORD dwCaculatedSize = segindex; |
1042 dwCaculatedSize += count; | 1042 dwCaculatedSize += count; |
1043 dwCaculatedSize *= totalWidth; | 1043 dwCaculatedSize *= totalWidth; |
1044 if (!dwCaculatedSize.IsValid() || | 1044 if (!dwCaculatedSize.IsValid() || |
1045 dwCaculatedSize.ValueOrDie() > dwTotalSize) { | 1045 dwCaculatedSize.ValueOrDie() > dwTotalSize) { |
1046 continue; | 1046 continue; |
1047 } | 1047 } |
1048 | 1048 |
1049 const uint8_t* segstart = pData + segindex * totalWidth; | 1049 const uint8_t* segstart = pData + segindex * totalWidth; |
1050 FX_SAFE_DWORD dwMaxObjNum = startnum; | 1050 FX_SAFE_DWORD dwMaxObjNum = startnum; |
1051 dwMaxObjNum += count; | 1051 dwMaxObjNum += count; |
1052 FX_DWORD dwV5Size = m_ObjectInfo.empty() ? 0 : GetLastObjNum() + 1; | 1052 uint32_t dwV5Size = m_ObjectInfo.empty() ? 0 : GetLastObjNum() + 1; |
1053 if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) | 1053 if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) |
1054 continue; | 1054 continue; |
1055 | 1055 |
1056 for (FX_DWORD j = 0; j < count; j++) { | 1056 for (uint32_t j = 0; j < count; j++) { |
1057 int32_t type = 1; | 1057 int32_t type = 1; |
1058 const uint8_t* entrystart = segstart + j * totalWidth; | 1058 const uint8_t* entrystart = segstart + j * totalWidth; |
1059 if (WidthArray[0]) | 1059 if (WidthArray[0]) |
1060 type = GetVarInt(entrystart, WidthArray[0]); | 1060 type = GetVarInt(entrystart, WidthArray[0]); |
1061 | 1061 |
1062 if (GetObjectType(startnum + j) == 255) { | 1062 if (GetObjectType(startnum + j) == 255) { |
1063 FX_FILESIZE offset = | 1063 FX_FILESIZE offset = |
1064 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); | 1064 GetVarInt(entrystart + WidthArray[0], WidthArray[1]); |
1065 m_ObjectInfo[startnum + j].pos = offset; | 1065 m_ObjectInfo[startnum + j].pos = offset; |
1066 m_SortedOffset.insert(offset); | 1066 m_SortedOffset.insert(offset); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 if (!pID) | 1099 if (!pID) |
1100 return nullptr; | 1100 return nullptr; |
1101 | 1101 |
1102 if (CPDF_Reference* pRef = pID->AsReference()) { | 1102 if (CPDF_Reference* pRef = pID->AsReference()) { |
1103 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); | 1103 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); |
1104 m_pTrailer->SetAt("ID", pID); | 1104 m_pTrailer->SetAt("ID", pID); |
1105 } | 1105 } |
1106 return ToArray(pID); | 1106 return ToArray(pID); |
1107 } | 1107 } |
1108 | 1108 |
1109 FX_DWORD CPDF_Parser::GetRootObjNum() { | 1109 uint32_t CPDF_Parser::GetRootObjNum() { |
1110 CPDF_Reference* pRef = | 1110 CPDF_Reference* pRef = |
1111 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); | 1111 ToReference(m_pTrailer ? m_pTrailer->GetElement("Root") : nullptr); |
1112 return pRef ? pRef->GetRefObjNum() : 0; | 1112 return pRef ? pRef->GetRefObjNum() : 0; |
1113 } | 1113 } |
1114 | 1114 |
1115 FX_DWORD CPDF_Parser::GetInfoObjNum() { | 1115 uint32_t CPDF_Parser::GetInfoObjNum() { |
1116 CPDF_Reference* pRef = | 1116 CPDF_Reference* pRef = |
1117 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); | 1117 ToReference(m_pTrailer ? m_pTrailer->GetElement("Info") : nullptr); |
1118 return pRef ? pRef->GetRefObjNum() : 0; | 1118 return pRef ? pRef->GetRefObjNum() : 0; |
1119 } | 1119 } |
1120 | 1120 |
1121 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { | 1121 FX_BOOL CPDF_Parser::IsFormStream(uint32_t objnum, FX_BOOL& bForm) { |
1122 bForm = FALSE; | 1122 bForm = FALSE; |
1123 if (!IsValidObjectNumber(objnum)) | 1123 if (!IsValidObjectNumber(objnum)) |
1124 return TRUE; | 1124 return TRUE; |
1125 | 1125 |
1126 if (GetObjectType(objnum) == 0) | 1126 if (GetObjectType(objnum) == 0) |
1127 return TRUE; | 1127 return TRUE; |
1128 | 1128 |
1129 if (GetObjectType(objnum) == 2) | 1129 if (GetObjectType(objnum) == 2) |
1130 return TRUE; | 1130 return TRUE; |
1131 | 1131 |
(...skipping 11 matching lines...) Expand all Loading... |
1143 | 1143 |
1144 const char kFormStream[] = "/Form\0stream"; | 1144 const char kFormStream[] = "/Form\0stream"; |
1145 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); | 1145 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); |
1146 bForm = m_pSyntax->SearchMultiWord(kFormStreamStr, TRUE, size) == 0; | 1146 bForm = m_pSyntax->SearchMultiWord(kFormStreamStr, TRUE, size) == 0; |
1147 m_pSyntax->RestorePos(SavedPos); | 1147 m_pSyntax->RestorePos(SavedPos); |
1148 return TRUE; | 1148 return TRUE; |
1149 } | 1149 } |
1150 | 1150 |
1151 CPDF_Object* CPDF_Parser::ParseIndirectObject( | 1151 CPDF_Object* CPDF_Parser::ParseIndirectObject( |
1152 CPDF_IndirectObjectHolder* pObjList, | 1152 CPDF_IndirectObjectHolder* pObjList, |
1153 FX_DWORD objnum) { | 1153 uint32_t objnum) { |
1154 if (!IsValidObjectNumber(objnum)) | 1154 if (!IsValidObjectNumber(objnum)) |
1155 return nullptr; | 1155 return nullptr; |
1156 | 1156 |
1157 // Prevent circular parsing the same object. | 1157 // Prevent circular parsing the same object. |
1158 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) | 1158 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) |
1159 return nullptr; | 1159 return nullptr; |
1160 | 1160 |
1161 pdfium::ScopedSetInsertion<FX_DWORD> local_insert(&m_ParsingObjNums, objnum); | 1161 pdfium::ScopedSetInsertion<uint32_t> local_insert(&m_ParsingObjNums, objnum); |
1162 if (GetObjectType(objnum) == 1 || GetObjectType(objnum) == 255) { | 1162 if (GetObjectType(objnum) == 1 || GetObjectType(objnum) == 255) { |
1163 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1163 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
1164 if (pos <= 0) | 1164 if (pos <= 0) |
1165 return nullptr; | 1165 return nullptr; |
1166 return ParseIndirectObjectAt(pObjList, pos, objnum); | 1166 return ParseIndirectObjectAt(pObjList, pos, objnum); |
1167 } | 1167 } |
1168 if (GetObjectType(objnum) != 2) | 1168 if (GetObjectType(objnum) != 2) |
1169 return nullptr; | 1169 return nullptr; |
1170 | 1170 |
1171 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); | 1171 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
1172 if (!pObjStream) | 1172 if (!pObjStream) |
1173 return nullptr; | 1173 return nullptr; |
1174 | 1174 |
1175 ScopedFileStream file(FX_CreateMemoryStream( | 1175 ScopedFileStream file(FX_CreateMemoryStream( |
1176 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1176 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); |
1177 CPDF_SyntaxParser syntax; | 1177 CPDF_SyntaxParser syntax; |
1178 syntax.InitParser(file.get(), 0); | 1178 syntax.InitParser(file.get(), 0); |
1179 const int32_t offset = GetStreamFirst(pObjStream); | 1179 const int32_t offset = GetStreamFirst(pObjStream); |
1180 | 1180 |
1181 // Read object numbers from |pObjStream| into a cache. | 1181 // Read object numbers from |pObjStream| into a cache. |
1182 if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) { | 1182 if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) { |
1183 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { | 1183 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { |
1184 FX_DWORD thisnum = syntax.GetDirectNum(); | 1184 uint32_t thisnum = syntax.GetDirectNum(); |
1185 FX_DWORD thisoff = syntax.GetDirectNum(); | 1185 uint32_t thisoff = syntax.GetDirectNum(); |
1186 m_ObjCache[pObjStream][thisnum] = thisoff; | 1186 m_ObjCache[pObjStream][thisnum] = thisoff; |
1187 } | 1187 } |
1188 } | 1188 } |
1189 | 1189 |
1190 const auto it = m_ObjCache[pObjStream].find(objnum); | 1190 const auto it = m_ObjCache[pObjStream].find(objnum); |
1191 if (it == m_ObjCache[pObjStream].end()) | 1191 if (it == m_ObjCache[pObjStream].end()) |
1192 return nullptr; | 1192 return nullptr; |
1193 | 1193 |
1194 syntax.RestorePos(offset + it->second); | 1194 syntax.RestorePos(offset + it->second); |
1195 return syntax.GetObject(pObjList, 0, 0, true); | 1195 return syntax.GetObject(pObjList, 0, 0, true); |
1196 } | 1196 } |
1197 | 1197 |
1198 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { | 1198 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(uint32_t objnum) { |
1199 auto it = m_ObjectStreamMap.find(objnum); | 1199 auto it = m_ObjectStreamMap.find(objnum); |
1200 if (it != m_ObjectStreamMap.end()) | 1200 if (it != m_ObjectStreamMap.end()) |
1201 return it->second.get(); | 1201 return it->second.get(); |
1202 | 1202 |
1203 if (!m_pDocument) | 1203 if (!m_pDocument) |
1204 return nullptr; | 1204 return nullptr; |
1205 | 1205 |
1206 const CPDF_Stream* pStream = ToStream(m_pDocument->GetIndirectObject(objnum)); | 1206 const CPDF_Stream* pStream = ToStream(m_pDocument->GetIndirectObject(objnum)); |
1207 if (!pStream) | 1207 if (!pStream) |
1208 return nullptr; | 1208 return nullptr; |
1209 | 1209 |
1210 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; | 1210 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; |
1211 pStreamAcc->LoadAllData(pStream); | 1211 pStreamAcc->LoadAllData(pStream); |
1212 m_ObjectStreamMap[objnum].reset(pStreamAcc); | 1212 m_ObjectStreamMap[objnum].reset(pStreamAcc); |
1213 return pStreamAcc; | 1213 return pStreamAcc; |
1214 } | 1214 } |
1215 | 1215 |
1216 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) const { | 1216 FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const { |
1217 if (!IsValidObjectNumber(objnum)) | 1217 if (!IsValidObjectNumber(objnum)) |
1218 return 0; | 1218 return 0; |
1219 | 1219 |
1220 if (GetObjectType(objnum) == 2) | 1220 if (GetObjectType(objnum) == 2) |
1221 objnum = GetObjectPositionOrZero(objnum); | 1221 objnum = GetObjectPositionOrZero(objnum); |
1222 | 1222 |
1223 if (GetObjectType(objnum) != 1 && GetObjectType(objnum) != 255) | 1223 if (GetObjectType(objnum) != 1 && GetObjectType(objnum) != 255) |
1224 return 0; | 1224 return 0; |
1225 | 1225 |
1226 FX_FILESIZE offset = GetObjectPositionOrZero(objnum); | 1226 FX_FILESIZE offset = GetObjectPositionOrZero(objnum); |
1227 if (offset == 0) | 1227 if (offset == 0) |
1228 return 0; | 1228 return 0; |
1229 | 1229 |
1230 auto it = m_SortedOffset.find(offset); | 1230 auto it = m_SortedOffset.find(offset); |
1231 if (it == m_SortedOffset.end() || ++it == m_SortedOffset.end()) | 1231 if (it == m_SortedOffset.end() || ++it == m_SortedOffset.end()) |
1232 return 0; | 1232 return 0; |
1233 | 1233 |
1234 return *it - offset; | 1234 return *it - offset; |
1235 } | 1235 } |
1236 | 1236 |
1237 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, | 1237 void CPDF_Parser::GetIndirectBinary(uint32_t objnum, |
1238 uint8_t*& pBuffer, | 1238 uint8_t*& pBuffer, |
1239 FX_DWORD& size) { | 1239 uint32_t& size) { |
1240 pBuffer = nullptr; | 1240 pBuffer = nullptr; |
1241 size = 0; | 1241 size = 0; |
1242 if (!IsValidObjectNumber(objnum)) | 1242 if (!IsValidObjectNumber(objnum)) |
1243 return; | 1243 return; |
1244 | 1244 |
1245 if (GetObjectType(objnum) == 2) { | 1245 if (GetObjectType(objnum) == 2) { |
1246 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); | 1246 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
1247 if (!pObjStream) | 1247 if (!pObjStream) |
1248 return; | 1248 return; |
1249 | 1249 |
1250 int32_t offset = GetStreamFirst(pObjStream); | 1250 int32_t offset = GetStreamFirst(pObjStream); |
1251 const uint8_t* pData = pObjStream->GetData(); | 1251 const uint8_t* pData = pObjStream->GetData(); |
1252 FX_DWORD totalsize = pObjStream->GetSize(); | 1252 uint32_t totalsize = pObjStream->GetSize(); |
1253 ScopedFileStream file( | 1253 ScopedFileStream file( |
1254 FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, FALSE)); | 1254 FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, FALSE)); |
1255 | 1255 |
1256 CPDF_SyntaxParser syntax; | 1256 CPDF_SyntaxParser syntax; |
1257 syntax.InitParser(file.get(), 0); | 1257 syntax.InitParser(file.get(), 0); |
1258 for (int i = GetStreamNCount(pObjStream); i > 0; --i) { | 1258 for (int i = GetStreamNCount(pObjStream); i > 0; --i) { |
1259 FX_DWORD thisnum = syntax.GetDirectNum(); | 1259 uint32_t thisnum = syntax.GetDirectNum(); |
1260 FX_DWORD thisoff = syntax.GetDirectNum(); | 1260 uint32_t thisoff = syntax.GetDirectNum(); |
1261 if (thisnum != objnum) | 1261 if (thisnum != objnum) |
1262 continue; | 1262 continue; |
1263 | 1263 |
1264 if (i == 1) { | 1264 if (i == 1) { |
1265 size = totalsize - (thisoff + offset); | 1265 size = totalsize - (thisoff + offset); |
1266 } else { | 1266 } else { |
1267 syntax.GetDirectNum(); // Skip nextnum. | 1267 syntax.GetDirectNum(); // Skip nextnum. |
1268 FX_DWORD nextoff = syntax.GetDirectNum(); | 1268 uint32_t nextoff = syntax.GetDirectNum(); |
1269 size = nextoff - thisoff; | 1269 size = nextoff - thisoff; |
1270 } | 1270 } |
1271 | 1271 |
1272 pBuffer = FX_Alloc(uint8_t, size); | 1272 pBuffer = FX_Alloc(uint8_t, size); |
1273 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); | 1273 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); |
1274 return; | 1274 return; |
1275 } | 1275 } |
1276 return; | 1276 return; |
1277 } | 1277 } |
1278 | 1278 |
1279 if (GetObjectType(objnum) != 1) | 1279 if (GetObjectType(objnum) != 1) |
1280 return; | 1280 return; |
1281 | 1281 |
1282 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1282 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
1283 if (pos == 0) | 1283 if (pos == 0) |
1284 return; | 1284 return; |
1285 | 1285 |
1286 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1286 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
1287 m_pSyntax->RestorePos(pos); | 1287 m_pSyntax->RestorePos(pos); |
1288 | 1288 |
1289 bool bIsNumber; | 1289 bool bIsNumber; |
1290 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1290 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
1291 if (!bIsNumber) { | 1291 if (!bIsNumber) { |
1292 m_pSyntax->RestorePos(SavedPos); | 1292 m_pSyntax->RestorePos(SavedPos); |
1293 return; | 1293 return; |
1294 } | 1294 } |
1295 | 1295 |
1296 FX_DWORD parser_objnum = FXSYS_atoui(word); | 1296 uint32_t parser_objnum = FXSYS_atoui(word); |
1297 if (parser_objnum && parser_objnum != objnum) { | 1297 if (parser_objnum && parser_objnum != objnum) { |
1298 m_pSyntax->RestorePos(SavedPos); | 1298 m_pSyntax->RestorePos(SavedPos); |
1299 return; | 1299 return; |
1300 } | 1300 } |
1301 | 1301 |
1302 word = m_pSyntax->GetNextWord(&bIsNumber); | 1302 word = m_pSyntax->GetNextWord(&bIsNumber); |
1303 if (!bIsNumber) { | 1303 if (!bIsNumber) { |
1304 m_pSyntax->RestorePos(SavedPos); | 1304 m_pSyntax->RestorePos(SavedPos); |
1305 return; | 1305 return; |
1306 } | 1306 } |
(...skipping 29 matching lines...) Expand all Loading... |
1336 while (1) { | 1336 while (1) { |
1337 if (m_pSyntax->GetKeyword() == "endobj") | 1337 if (m_pSyntax->GetKeyword() == "endobj") |
1338 break; | 1338 break; |
1339 | 1339 |
1340 if (m_pSyntax->SavePos() == m_pSyntax->m_FileLen) | 1340 if (m_pSyntax->SavePos() == m_pSyntax->m_FileLen) |
1341 break; | 1341 break; |
1342 } | 1342 } |
1343 nextoff = m_pSyntax->SavePos(); | 1343 nextoff = m_pSyntax->SavePos(); |
1344 } | 1344 } |
1345 | 1345 |
1346 size = (FX_DWORD)(nextoff - pos); | 1346 size = (uint32_t)(nextoff - pos); |
1347 pBuffer = FX_Alloc(uint8_t, size); | 1347 pBuffer = FX_Alloc(uint8_t, size); |
1348 m_pSyntax->RestorePos(pos); | 1348 m_pSyntax->RestorePos(pos); |
1349 m_pSyntax->ReadBlock(pBuffer, size); | 1349 m_pSyntax->ReadBlock(pBuffer, size); |
1350 m_pSyntax->RestorePos(SavedPos); | 1350 m_pSyntax->RestorePos(SavedPos); |
1351 } | 1351 } |
1352 | 1352 |
1353 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt( | 1353 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt( |
1354 CPDF_IndirectObjectHolder* pObjList, | 1354 CPDF_IndirectObjectHolder* pObjList, |
1355 FX_FILESIZE pos, | 1355 FX_FILESIZE pos, |
1356 FX_DWORD objnum) { | 1356 uint32_t objnum) { |
1357 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1357 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
1358 m_pSyntax->RestorePos(pos); | 1358 m_pSyntax->RestorePos(pos); |
1359 bool bIsNumber; | 1359 bool bIsNumber; |
1360 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1360 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
1361 if (!bIsNumber) { | 1361 if (!bIsNumber) { |
1362 m_pSyntax->RestorePos(SavedPos); | 1362 m_pSyntax->RestorePos(SavedPos); |
1363 return nullptr; | 1363 return nullptr; |
1364 } | 1364 } |
1365 | 1365 |
1366 FX_FILESIZE objOffset = m_pSyntax->SavePos(); | 1366 FX_FILESIZE objOffset = m_pSyntax->SavePos(); |
1367 objOffset -= word.GetLength(); | 1367 objOffset -= word.GetLength(); |
1368 FX_DWORD parser_objnum = FXSYS_atoui(word); | 1368 uint32_t parser_objnum = FXSYS_atoui(word); |
1369 if (objnum && parser_objnum != objnum) { | 1369 if (objnum && parser_objnum != objnum) { |
1370 m_pSyntax->RestorePos(SavedPos); | 1370 m_pSyntax->RestorePos(SavedPos); |
1371 return nullptr; | 1371 return nullptr; |
1372 } | 1372 } |
1373 | 1373 |
1374 word = m_pSyntax->GetNextWord(&bIsNumber); | 1374 word = m_pSyntax->GetNextWord(&bIsNumber); |
1375 if (!bIsNumber) { | 1375 if (!bIsNumber) { |
1376 m_pSyntax->RestorePos(SavedPos); | 1376 m_pSyntax->RestorePos(SavedPos); |
1377 return nullptr; | 1377 return nullptr; |
1378 } | 1378 } |
1379 | 1379 |
1380 FX_DWORD parser_gennum = FXSYS_atoui(word); | 1380 uint32_t parser_gennum = FXSYS_atoui(word); |
1381 if (m_pSyntax->GetKeyword() != "obj") { | 1381 if (m_pSyntax->GetKeyword() != "obj") { |
1382 m_pSyntax->RestorePos(SavedPos); | 1382 m_pSyntax->RestorePos(SavedPos); |
1383 return nullptr; | 1383 return nullptr; |
1384 } | 1384 } |
1385 | 1385 |
1386 CPDF_Object* pObj = | 1386 CPDF_Object* pObj = |
1387 m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true); | 1387 m_pSyntax->GetObject(pObjList, objnum, parser_gennum, true); |
1388 m_pSyntax->SavePos(); | 1388 m_pSyntax->SavePos(); |
1389 | 1389 |
1390 CFX_ByteString bsWord = m_pSyntax->GetKeyword(); | 1390 CFX_ByteString bsWord = m_pSyntax->GetKeyword(); |
1391 if (bsWord == "endobj") | 1391 if (bsWord == "endobj") |
1392 m_pSyntax->SavePos(); | 1392 m_pSyntax->SavePos(); |
1393 | 1393 |
1394 m_pSyntax->RestorePos(SavedPos); | 1394 m_pSyntax->RestorePos(SavedPos); |
1395 if (pObj) { | 1395 if (pObj) { |
1396 if (!objnum) | 1396 if (!objnum) |
1397 pObj->m_ObjNum = parser_objnum; | 1397 pObj->m_ObjNum = parser_objnum; |
1398 pObj->m_GenNum = parser_gennum; | 1398 pObj->m_GenNum = parser_gennum; |
1399 } | 1399 } |
1400 return pObj; | 1400 return pObj; |
1401 } | 1401 } |
1402 | 1402 |
1403 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 1403 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( |
1404 CPDF_IndirectObjectHolder* pObjList, | 1404 CPDF_IndirectObjectHolder* pObjList, |
1405 FX_FILESIZE pos, | 1405 FX_FILESIZE pos, |
1406 FX_DWORD objnum, | 1406 uint32_t objnum, |
1407 FX_FILESIZE* pResultPos) { | 1407 FX_FILESIZE* pResultPos) { |
1408 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1408 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
1409 m_pSyntax->RestorePos(pos); | 1409 m_pSyntax->RestorePos(pos); |
1410 | 1410 |
1411 bool bIsNumber; | 1411 bool bIsNumber; |
1412 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1412 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
1413 if (!bIsNumber) { | 1413 if (!bIsNumber) { |
1414 m_pSyntax->RestorePos(SavedPos); | 1414 m_pSyntax->RestorePos(SavedPos); |
1415 return nullptr; | 1415 return nullptr; |
1416 } | 1416 } |
1417 | 1417 |
1418 FX_DWORD parser_objnum = FXSYS_atoui(word); | 1418 uint32_t parser_objnum = FXSYS_atoui(word); |
1419 if (objnum && parser_objnum != objnum) { | 1419 if (objnum && parser_objnum != objnum) { |
1420 m_pSyntax->RestorePos(SavedPos); | 1420 m_pSyntax->RestorePos(SavedPos); |
1421 return nullptr; | 1421 return nullptr; |
1422 } | 1422 } |
1423 | 1423 |
1424 word = m_pSyntax->GetNextWord(&bIsNumber); | 1424 word = m_pSyntax->GetNextWord(&bIsNumber); |
1425 if (!bIsNumber) { | 1425 if (!bIsNumber) { |
1426 m_pSyntax->RestorePos(SavedPos); | 1426 m_pSyntax->RestorePos(SavedPos); |
1427 return nullptr; | 1427 return nullptr; |
1428 } | 1428 } |
1429 | 1429 |
1430 FX_DWORD gennum = FXSYS_atoui(word); | 1430 uint32_t gennum = FXSYS_atoui(word); |
1431 if (m_pSyntax->GetKeyword() != "obj") { | 1431 if (m_pSyntax->GetKeyword() != "obj") { |
1432 m_pSyntax->RestorePos(SavedPos); | 1432 m_pSyntax->RestorePos(SavedPos); |
1433 return nullptr; | 1433 return nullptr; |
1434 } | 1434 } |
1435 | 1435 |
1436 CPDF_Object* pObj = m_pSyntax->GetObjectByStrict(pObjList, objnum, gennum); | 1436 CPDF_Object* pObj = m_pSyntax->GetObjectByStrict(pObjList, objnum, gennum); |
1437 if (pResultPos) | 1437 if (pResultPos) |
1438 *pResultPos = m_pSyntax->m_Pos; | 1438 *pResultPos = m_pSyntax->m_Pos; |
1439 | 1439 |
1440 m_pSyntax->RestorePos(SavedPos); | 1440 m_pSyntax->RestorePos(SavedPos); |
1441 return pObj; | 1441 return pObj; |
1442 } | 1442 } |
1443 | 1443 |
1444 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { | 1444 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { |
1445 if (m_pSyntax->GetKeyword() != "trailer") | 1445 if (m_pSyntax->GetKeyword() != "trailer") |
1446 return nullptr; | 1446 return nullptr; |
1447 | 1447 |
1448 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 1448 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
1449 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); | 1449 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); |
1450 if (!ToDictionary(pObj.get())) | 1450 if (!ToDictionary(pObj.get())) |
1451 return nullptr; | 1451 return nullptr; |
1452 return pObj.release()->AsDictionary(); | 1452 return pObj.release()->AsDictionary(); |
1453 } | 1453 } |
1454 | 1454 |
1455 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { | 1455 uint32_t CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { |
1456 if (!m_pSecurityHandler) | 1456 if (!m_pSecurityHandler) |
1457 return (FX_DWORD)-1; | 1457 return (uint32_t)-1; |
1458 | 1458 |
1459 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); | 1459 uint32_t dwPermission = m_pSecurityHandler->GetPermissions(); |
1460 if (m_pEncryptDict && m_pEncryptDict->GetStringBy("Filter") == "Standard") { | 1460 if (m_pEncryptDict && m_pEncryptDict->GetStringBy("Filter") == "Standard") { |
1461 dwPermission &= 0xFFFFFFFC; | 1461 dwPermission &= 0xFFFFFFFC; |
1462 dwPermission |= 0xFFFFF0C0; | 1462 dwPermission |= 0xFFFFF0C0; |
1463 if (bCheckRevision && m_pEncryptDict->GetIntegerBy("R") == 2) | 1463 if (bCheckRevision && m_pEncryptDict->GetIntegerBy("R") == 2) |
1464 dwPermission &= 0xFFFFF0FF; | 1464 dwPermission &= 0xFFFFF0FF; |
1465 } | 1465 } |
1466 return dwPermission; | 1466 return dwPermission; |
1467 } | 1467 } |
1468 | 1468 |
1469 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, | 1469 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, |
1470 FX_DWORD offset) { | 1470 uint32_t offset) { |
1471 m_pSyntax->InitParser(pFileAccess, offset); | 1471 m_pSyntax->InitParser(pFileAccess, offset); |
1472 m_pSyntax->RestorePos(m_pSyntax->m_HeaderOffset + 9); | 1472 m_pSyntax->RestorePos(m_pSyntax->m_HeaderOffset + 9); |
1473 | 1473 |
1474 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1474 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
1475 bool bIsNumber; | 1475 bool bIsNumber; |
1476 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1476 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
1477 if (!bIsNumber) | 1477 if (!bIsNumber) |
1478 return FALSE; | 1478 return FALSE; |
1479 | 1479 |
1480 FX_DWORD objnum = FXSYS_atoui(word); | 1480 uint32_t objnum = FXSYS_atoui(word); |
1481 word = m_pSyntax->GetNextWord(&bIsNumber); | 1481 word = m_pSyntax->GetNextWord(&bIsNumber); |
1482 if (!bIsNumber) | 1482 if (!bIsNumber) |
1483 return FALSE; | 1483 return FALSE; |
1484 | 1484 |
1485 FX_DWORD gennum = FXSYS_atoui(word); | 1485 uint32_t gennum = FXSYS_atoui(word); |
1486 if (m_pSyntax->GetKeyword() != "obj") { | 1486 if (m_pSyntax->GetKeyword() != "obj") { |
1487 m_pSyntax->RestorePos(SavedPos); | 1487 m_pSyntax->RestorePos(SavedPos); |
1488 return FALSE; | 1488 return FALSE; |
1489 } | 1489 } |
1490 | 1490 |
1491 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); | 1491 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); |
1492 if (!m_pLinearized) | 1492 if (!m_pLinearized) |
1493 return FALSE; | 1493 return FALSE; |
1494 | 1494 |
1495 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1495 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 // Check for circular references. | 1610 // Check for circular references. |
1611 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) | 1611 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) |
1612 return FALSE; | 1612 return FALSE; |
1613 } | 1613 } |
1614 m_ObjectStreamMap.clear(); | 1614 m_ObjectStreamMap.clear(); |
1615 m_bXRefStream = TRUE; | 1615 m_bXRefStream = TRUE; |
1616 return TRUE; | 1616 return TRUE; |
1617 } | 1617 } |
1618 | 1618 |
1619 CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { | 1619 CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { |
1620 FX_DWORD dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; | 1620 uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; |
1621 m_pSyntax->m_MetadataObjnum = 0; | 1621 m_pSyntax->m_MetadataObjnum = 0; |
1622 if (m_pTrailer) { | 1622 if (m_pTrailer) { |
1623 m_pTrailer->Release(); | 1623 m_pTrailer->Release(); |
1624 m_pTrailer = nullptr; | 1624 m_pTrailer = nullptr; |
1625 } | 1625 } |
1626 | 1626 |
1627 m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); | 1627 m_pSyntax->RestorePos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); |
1628 uint8_t ch = 0; | 1628 uint8_t ch = 0; |
1629 FX_DWORD dwCount = 0; | 1629 uint32_t dwCount = 0; |
1630 m_pSyntax->GetNextChar(ch); | 1630 m_pSyntax->GetNextChar(ch); |
1631 while (PDFCharIsWhitespace(ch)) { | 1631 while (PDFCharIsWhitespace(ch)) { |
1632 ++dwCount; | 1632 ++dwCount; |
1633 if (m_pSyntax->m_FileLen >= | 1633 if (m_pSyntax->m_FileLen >= |
1634 (FX_FILESIZE)(m_pSyntax->SavePos() + m_pSyntax->m_HeaderOffset)) { | 1634 (FX_FILESIZE)(m_pSyntax->SavePos() + m_pSyntax->m_HeaderOffset)) { |
1635 break; | 1635 break; |
1636 } | 1636 } |
1637 m_pSyntax->GetNextChar(ch); | 1637 m_pSyntax->GetNextChar(ch); |
1638 } | 1638 } |
1639 m_LastXRefOffset += dwCount; | 1639 m_LastXRefOffset += dwCount; |
1640 m_ObjectStreamMap.clear(); | 1640 m_ObjectStreamMap.clear(); |
1641 m_ObjCache.clear(); | 1641 m_ObjCache.clear(); |
1642 | 1642 |
1643 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1643 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1644 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1644 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1645 m_LastXRefOffset = 0; | 1645 m_LastXRefOffset = 0; |
1646 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1646 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1647 return FORMAT_ERROR; | 1647 return FORMAT_ERROR; |
1648 } | 1648 } |
1649 | 1649 |
1650 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1650 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1651 return SUCCESS; | 1651 return SUCCESS; |
1652 } | 1652 } |
OLD | NEW |