OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 m_pFS->Release(m_pFS->clientData); | 105 m_pFS->Release(m_pFS->clientData); |
106 delete this; | 106 delete this; |
107 } | 107 } |
108 | 108 |
109 FX_FILESIZE CFPDF_FileStream::GetSize() { | 109 FX_FILESIZE CFPDF_FileStream::GetSize() { |
110 if (m_pFS && m_pFS->GetSize) | 110 if (m_pFS && m_pFS->GetSize) |
111 return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData); | 111 return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData); |
112 return 0; | 112 return 0; |
113 } | 113 } |
114 | 114 |
115 FX_BOOL CFPDF_FileStream::IsEOF() { | 115 bool CFPDF_FileStream::IsEOF() { |
116 return m_nCurPos >= GetSize(); | 116 return m_nCurPos >= GetSize(); |
117 } | 117 } |
118 | 118 |
119 FX_FILESIZE CFPDF_FileStream::GetPosition() { | 119 FX_FILESIZE CFPDF_FileStream::GetPosition() { |
120 return m_nCurPos; | 120 return m_nCurPos; |
121 } | 121 } |
122 | 122 |
123 FX_BOOL CFPDF_FileStream::ReadBlock(void* buffer, | 123 bool CFPDF_FileStream::ReadBlock(void* buffer, |
124 FX_FILESIZE offset, | 124 FX_FILESIZE offset, |
125 size_t size) { | 125 size_t size) { |
126 if (!buffer || !size || !m_pFS->ReadBlock) | 126 if (!buffer || !size || !m_pFS->ReadBlock) |
127 return FALSE; | 127 return false; |
128 | 128 |
129 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, | 129 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, |
130 (FPDF_DWORD)size) == 0) { | 130 (FPDF_DWORD)size) == 0) { |
131 m_nCurPos = offset + size; | 131 m_nCurPos = offset + size; |
132 return TRUE; | 132 return true; |
133 } | 133 } |
134 return FALSE; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) { | 137 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) { |
138 if (!buffer || !size || !m_pFS->ReadBlock) | 138 if (!buffer || !size || !m_pFS->ReadBlock) |
139 return 0; | 139 return 0; |
140 | 140 |
141 FX_FILESIZE nSize = GetSize(); | 141 FX_FILESIZE nSize = GetSize(); |
142 if (m_nCurPos >= nSize) | 142 if (m_nCurPos >= nSize) |
143 return 0; | 143 return 0; |
144 FX_FILESIZE dwAvail = nSize - m_nCurPos; | 144 FX_FILESIZE dwAvail = nSize - m_nCurPos; |
145 if (dwAvail < (FX_FILESIZE)size) | 145 if (dwAvail < (FX_FILESIZE)size) |
146 size = (size_t)dwAvail; | 146 size = (size_t)dwAvail; |
147 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer, | 147 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer, |
148 (FPDF_DWORD)size) == 0) { | 148 (FPDF_DWORD)size) == 0) { |
149 m_nCurPos += size; | 149 m_nCurPos += size; |
150 return size; | 150 return size; |
151 } | 151 } |
152 | 152 |
153 return 0; | 153 return 0; |
154 } | 154 } |
155 | 155 |
156 FX_BOOL CFPDF_FileStream::WriteBlock(const void* buffer, | 156 bool CFPDF_FileStream::WriteBlock(const void* buffer, |
157 FX_FILESIZE offset, | 157 FX_FILESIZE offset, |
158 size_t size) { | 158 size_t size) { |
159 if (!m_pFS || !m_pFS->WriteBlock) | 159 if (!m_pFS || !m_pFS->WriteBlock) |
160 return FALSE; | 160 return false; |
161 | 161 |
162 if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, | 162 if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, |
163 (FPDF_DWORD)size) == 0) { | 163 (FPDF_DWORD)size) == 0) { |
164 m_nCurPos = offset + size; | 164 m_nCurPos = offset + size; |
165 return TRUE; | 165 return true; |
166 } | 166 } |
167 return FALSE; | 167 return false; |
168 } | 168 } |
169 | 169 |
170 FX_BOOL CFPDF_FileStream::Flush() { | 170 bool CFPDF_FileStream::Flush() { |
171 if (!m_pFS || !m_pFS->Flush) | 171 if (!m_pFS || !m_pFS->Flush) |
172 return TRUE; | 172 return true; |
173 | 173 |
174 return m_pFS->Flush(m_pFS->clientData) == 0; | 174 return m_pFS->Flush(m_pFS->clientData) == 0; |
175 } | 175 } |
176 #endif // PDF_ENABLE_XFA | 176 #endif // PDF_ENABLE_XFA |
177 | 177 |
178 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) | 178 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
179 : m_FileAccess(*pFileAccess) {} | 179 : m_FileAccess(*pFileAccess) {} |
180 | 180 |
181 FX_FILESIZE CPDF_CustomAccess::GetSize() { | 181 FX_FILESIZE CPDF_CustomAccess::GetSize() { |
182 return m_FileAccess.m_FileLen; | 182 return m_FileAccess.m_FileLen; |
183 } | 183 } |
184 | 184 |
185 void CPDF_CustomAccess::Release() { | 185 void CPDF_CustomAccess::Release() { |
186 delete this; | 186 delete this; |
187 } | 187 } |
188 | 188 |
189 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 189 bool CPDF_CustomAccess::ReadBlock(void* buffer, |
190 FX_FILESIZE offset, | 190 FX_FILESIZE offset, |
191 size_t size) { | 191 size_t size) { |
192 if (offset < 0) { | 192 if (offset < 0) |
193 return FALSE; | 193 return false; |
194 } | 194 |
195 FX_SAFE_FILESIZE newPos = | 195 FX_SAFE_FILESIZE newPos = |
196 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 196 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
197 newPos += offset; | 197 newPos += offset; |
198 if (!newPos.IsValid() || | 198 if (!newPos.IsValid() || |
199 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { | 199 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { |
200 return FALSE; | 200 return false; |
201 } | 201 } |
202 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, | 202 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, |
203 size); | 203 reinterpret_cast<uint8_t*>(buffer), size); |
204 } | 204 } |
205 | 205 |
206 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS | 206 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
207 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; | 207 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; |
208 | 208 |
209 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { | 209 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { |
210 switch (policy) { | 210 switch (policy) { |
211 case FPDF_POLICY_MACHINETIME_ACCESS: { | 211 case FPDF_POLICY_MACHINETIME_ACCESS: { |
212 if (enable) | 212 if (enable) |
213 foxit_sandbox_policy |= 0x01; | 213 foxit_sandbox_policy |= 0x01; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); | 381 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); |
382 } | 382 } |
383 #endif // PDF_ENABLE_XFA | 383 #endif // PDF_ENABLE_XFA |
384 | 384 |
385 class CMemFile final : public IFX_SeekableReadStream { | 385 class CMemFile final : public IFX_SeekableReadStream { |
386 public: | 386 public: |
387 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} | 387 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} |
388 | 388 |
389 void Release() override { delete this; } | 389 void Release() override { delete this; } |
390 FX_FILESIZE GetSize() override { return m_size; } | 390 FX_FILESIZE GetSize() override { return m_size; } |
391 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 391 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
392 if (offset < 0) { | 392 if (offset < 0) { |
393 return FALSE; | 393 return false; |
394 } | 394 } |
395 FX_SAFE_FILESIZE newPos = | 395 FX_SAFE_FILESIZE newPos = |
396 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 396 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
397 newPos += offset; | 397 newPos += offset; |
398 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { | 398 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { |
399 return FALSE; | 399 return false; |
400 } | 400 } |
401 FXSYS_memcpy(buffer, m_pBuf + offset, size); | 401 FXSYS_memcpy(buffer, m_pBuf + offset, size); |
402 return TRUE; | 402 return true; |
403 } | 403 } |
404 | 404 |
405 private: | 405 private: |
406 ~CMemFile() override {} | 406 ~CMemFile() override {} |
407 | 407 |
408 uint8_t* const m_pBuf; | 408 uint8_t* const m_pBuf; |
409 const FX_FILESIZE m_size; | 409 const FX_FILESIZE m_size; |
410 }; | 410 }; |
411 | 411 |
412 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, | 412 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 if (!buffer) { | 1095 if (!buffer) { |
1096 *buflen = len; | 1096 *buflen = len; |
1097 } else if (*buflen >= len) { | 1097 } else if (*buflen >= len) { |
1098 memcpy(buffer, utf16Name.c_str(), len); | 1098 memcpy(buffer, utf16Name.c_str(), len); |
1099 *buflen = len; | 1099 *buflen = len; |
1100 } else { | 1100 } else { |
1101 *buflen = -1; | 1101 *buflen = -1; |
1102 } | 1102 } |
1103 return (FPDF_DEST)pDestObj; | 1103 return (FPDF_DEST)pDestObj; |
1104 } | 1104 } |
OLD | NEW |