| 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/cpdf_syntax_parser.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 pos += len; | 655 pos += len; |
| 656 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) | 656 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) |
| 657 m_Pos = pos.ValueOrDie(); | 657 m_Pos = pos.ValueOrDie(); |
| 658 | 658 |
| 659 m_Pos += ReadEOLMarkers(m_Pos); | 659 m_Pos += ReadEOLMarkers(m_Pos); |
| 660 FXSYS_memset(m_WordBuffer, 0, kEndStreamStr.GetLength() + 1); | 660 FXSYS_memset(m_WordBuffer, 0, kEndStreamStr.GetLength() + 1); |
| 661 GetNextWordInternal(nullptr); | 661 GetNextWordInternal(nullptr); |
| 662 // Earlier version of PDF specification doesn't require EOL marker before | 662 // Earlier version of PDF specification doesn't require EOL marker before |
| 663 // 'endstream' keyword. If keyword 'endstream' follows the bytes in | 663 // 'endstream' keyword. If keyword 'endstream' follows the bytes in |
| 664 // specified length, it signals the end of stream. | 664 // specified length, it signals the end of stream. |
| 665 if (FXSYS_memcmp(m_WordBuffer, kEndStreamStr.GetPtr(), | 665 if (FXSYS_memcmp(m_WordBuffer, kEndStreamStr.raw_str(), |
| 666 kEndStreamStr.GetLength()) == 0) { | 666 kEndStreamStr.GetLength()) == 0) { |
| 667 bSearchForKeyword = FALSE; | 667 bSearchForKeyword = FALSE; |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 | 670 |
| 671 if (bSearchForKeyword) { | 671 if (bSearchForKeyword) { |
| 672 // If len is not available, len needs to be calculated | 672 // If len is not available, len needs to be calculated |
| 673 // by searching the keywords "endstream" or "endobj". | 673 // by searching the keywords "endstream" or "endobj". |
| 674 m_Pos = streamStartPos; | 674 m_Pos = streamStartPos; |
| 675 FX_FILESIZE endStreamOffset = 0; | 675 FX_FILESIZE endStreamOffset = 0; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 767 |
| 768 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); | 768 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); |
| 769 streamStartPos = m_Pos; | 769 streamStartPos = m_Pos; |
| 770 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); | 770 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); |
| 771 | 771 |
| 772 GetNextWordInternal(nullptr); | 772 GetNextWordInternal(nullptr); |
| 773 | 773 |
| 774 int numMarkers = ReadEOLMarkers(m_Pos); | 774 int numMarkers = ReadEOLMarkers(m_Pos); |
| 775 if (m_WordSize == static_cast<unsigned int>(kEndObjStr.GetLength()) && | 775 if (m_WordSize == static_cast<unsigned int>(kEndObjStr.GetLength()) && |
| 776 numMarkers != 0 && | 776 numMarkers != 0 && |
| 777 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == | 777 FXSYS_memcmp(m_WordBuffer, kEndObjStr.raw_str(), |
| 778 0) { | 778 kEndObjStr.GetLength()) == 0) { |
| 779 m_Pos = streamStartPos; | 779 m_Pos = streamStartPos; |
| 780 } | 780 } |
| 781 return pStream; | 781 return pStream; |
| 782 } | 782 } |
| 783 | 783 |
| 784 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, | 784 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, |
| 785 uint32_t HeaderOffset) { | 785 uint32_t HeaderOffset) { |
| 786 FX_Free(m_pFileBuf); | 786 FX_Free(m_pFileBuf); |
| 787 | 787 |
| 788 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize); | 788 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 FX_FILESIZE limit) { | 842 FX_FILESIZE limit) { |
| 843 int32_t taglen = tag.GetLength(); | 843 int32_t taglen = tag.GetLength(); |
| 844 if (taglen == 0) | 844 if (taglen == 0) |
| 845 return FALSE; | 845 return FALSE; |
| 846 | 846 |
| 847 FX_FILESIZE pos = m_Pos; | 847 FX_FILESIZE pos = m_Pos; |
| 848 int32_t offset = 0; | 848 int32_t offset = 0; |
| 849 if (!bForward) | 849 if (!bForward) |
| 850 offset = taglen - 1; | 850 offset = taglen - 1; |
| 851 | 851 |
| 852 const uint8_t* tag_data = tag.GetPtr(); | 852 const uint8_t* tag_data = tag.raw_str(); |
| 853 uint8_t byte; | 853 uint8_t byte; |
| 854 while (1) { | 854 while (1) { |
| 855 if (bForward) { | 855 if (bForward) { |
| 856 if (limit && pos >= m_Pos + limit) | 856 if (limit && pos >= m_Pos + limit) |
| 857 return FALSE; | 857 return FALSE; |
| 858 | 858 |
| 859 if (!GetCharAt(pos, byte)) | 859 if (!GetCharAt(pos, byte)) |
| 860 return FALSE; | 860 return FALSE; |
| 861 | 861 |
| 862 } else { | 862 } else { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 } | 914 } |
| 915 | 915 |
| 916 std::vector<SearchTagRecord> patterns(ntags); | 916 std::vector<SearchTagRecord> patterns(ntags); |
| 917 uint32_t start = 0; | 917 uint32_t start = 0; |
| 918 uint32_t itag = 0; | 918 uint32_t itag = 0; |
| 919 uint32_t max_len = 0; | 919 uint32_t max_len = 0; |
| 920 for (int i = 0; i <= tags.GetLength(); ++i) { | 920 for (int i = 0; i <= tags.GetLength(); ++i) { |
| 921 if (tags[i] == 0) { | 921 if (tags[i] == 0) { |
| 922 uint32_t len = i - start; | 922 uint32_t len = i - start; |
| 923 max_len = std::max(len, max_len); | 923 max_len = std::max(len, max_len); |
| 924 patterns[itag].m_pTag = tags.GetCStr() + start; | 924 patterns[itag].m_pTag = tags.c_str() + start; |
| 925 patterns[itag].m_Len = len; | 925 patterns[itag].m_Len = len; |
| 926 patterns[itag].m_Offset = 0; | 926 patterns[itag].m_Offset = 0; |
| 927 start = i + 1; | 927 start = i + 1; |
| 928 ++itag; | 928 ++itag; |
| 929 } | 929 } |
| 930 } | 930 } |
| 931 | 931 |
| 932 const FX_FILESIZE pos_limit = m_Pos + limit; | 932 const FX_FILESIZE pos_limit = m_Pos + limit; |
| 933 for (FX_FILESIZE pos = m_Pos; !limit || pos < pos_limit; ++pos) { | 933 for (FX_FILESIZE pos = m_Pos; !limit || pos < pos_limit; ++pos) { |
| 934 uint8_t byte; | 934 uint8_t byte; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 if (limit && m_Pos == limit) | 981 if (limit && m_Pos == limit) |
| 982 return -1; | 982 return -1; |
| 983 } | 983 } |
| 984 return -1; | 984 return -1; |
| 985 } | 985 } |
| 986 | 986 |
| 987 void CPDF_SyntaxParser::SetEncrypt( | 987 void CPDF_SyntaxParser::SetEncrypt( |
| 988 std::unique_ptr<IPDF_CryptoHandler> pCryptoHandler) { | 988 std::unique_ptr<IPDF_CryptoHandler> pCryptoHandler) { |
| 989 m_pCryptoHandler = std::move(pCryptoHandler); | 989 m_pCryptoHandler = std::move(pCryptoHandler); |
| 990 } | 990 } |
| OLD | NEW |