OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" | 7 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 bool CPDF_SyntaxParser::ReadChar(FX_FILESIZE read_pos, uint32_t read_size) { | 58 bool CPDF_SyntaxParser::ReadChar(FX_FILESIZE read_pos, uint32_t read_size) { |
59 if (static_cast<FX_FILESIZE>(read_pos + read_size) > m_FileLen) { | 59 if (static_cast<FX_FILESIZE>(read_pos + read_size) > m_FileLen) { |
60 if (m_FileLen < static_cast<FX_FILESIZE>(read_size)) { | 60 if (m_FileLen < static_cast<FX_FILESIZE>(read_size)) { |
61 read_pos = 0; | 61 read_pos = 0; |
62 read_size = static_cast<uint32_t>(m_FileLen); | 62 read_size = static_cast<uint32_t>(m_FileLen); |
63 } else { | 63 } else { |
64 read_pos = m_FileLen - read_size; | 64 read_pos = m_FileLen - read_size; |
65 } | 65 } |
66 } | 66 } |
67 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) | 67 if (m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size) != read_size && |
68 !m_pFileAccess->IsEOF()) | |
68 return false; | 69 return false; |
69 | 70 |
70 m_BufOffset = read_pos; | 71 m_BufOffset = read_pos; |
71 return true; | 72 return true; |
72 } | 73 } |
73 | 74 |
74 bool CPDF_SyntaxParser::GetNextChar(uint8_t& ch) { | 75 bool CPDF_SyntaxParser::GetNextChar(uint8_t& ch) { |
75 FX_FILESIZE pos = m_Pos + m_HeaderOffset; | 76 FX_FILESIZE pos = m_Pos + m_HeaderOffset; |
76 if (pos >= m_FileLen) | 77 if (pos >= m_FileLen) |
77 return false; | 78 return false; |
(...skipping 23 matching lines...) Expand all Loading... | |
101 read_pos = pos - m_BufSize + 1; | 102 read_pos = pos - m_BufSize + 1; |
102 uint32_t read_size = m_BufSize; | 103 uint32_t read_size = m_BufSize; |
103 if (!ReadChar(read_pos, read_size)) | 104 if (!ReadChar(read_pos, read_size)) |
104 return false; | 105 return false; |
105 } | 106 } |
106 ch = m_pFileBuf[pos - m_BufOffset]; | 107 ch = m_pFileBuf[pos - m_BufOffset]; |
107 return true; | 108 return true; |
108 } | 109 } |
109 | 110 |
110 bool CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, uint32_t size) { | 111 bool CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, uint32_t size) { |
111 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) | 112 if (m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size) != size && |
113 !m_pFileAccess->IsEOF()) | |
112 return false; | 114 return false; |
113 m_Pos += size; | 115 m_Pos += size; |
Tom Sepez
2016/11/14 20:27:40
and here.
| |
114 return true; | 116 return true; |
115 } | 117 } |
116 | 118 |
117 void CPDF_SyntaxParser::GetNextWordInternal(bool* bIsNumber) { | 119 void CPDF_SyntaxParser::GetNextWordInternal(bool* bIsNumber) { |
118 m_WordSize = 0; | 120 m_WordSize = 0; |
119 if (bIsNumber) | 121 if (bIsNumber) |
120 *bIsNumber = true; | 122 *bIsNumber = true; |
121 | 123 |
122 uint8_t ch; | 124 uint8_t ch; |
123 if (!GetNextChar(ch)) | 125 if (!GetNextChar(ch)) |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 } | 915 } |
914 | 916 |
915 void CPDF_SyntaxParser::SetEncrypt( | 917 void CPDF_SyntaxParser::SetEncrypt( |
916 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { | 918 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { |
917 m_pCryptoHandler = std::move(pCryptoHandler); | 919 m_pCryptoHandler = std::move(pCryptoHandler); |
918 } | 920 } |
919 | 921 |
920 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { | 922 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) { |
921 return m_pPool ? m_pPool->Intern(str) : str; | 923 return m_pPool ? m_pPool->Intern(str) : str; |
922 } | 924 } |
OLD | NEW |