| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 FX_BOOL CFPDF_FileStream::IsEOF() { | 113 FX_BOOL CFPDF_FileStream::IsEOF() { |
| 114 return m_nCurPos >= GetSize(); | 114 return m_nCurPos >= GetSize(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 FX_FILESIZE CFPDF_FileStream::GetPosition() { | 117 FX_FILESIZE CFPDF_FileStream::GetPosition() { |
| 118 return m_nCurPos; | 118 return m_nCurPos; |
| 119 } | 119 } |
| 120 | 120 |
| 121 FX_BOOL CFPDF_FileStream::ReadBlock(void* buffer, | 121 size_t CFPDF_FileStream::ReadBlock(void* buffer, |
| 122 FX_FILESIZE offset, | 122 FX_FILESIZE offset, |
| 123 size_t size) { | 123 size_t size) { |
| 124 if (!buffer || !size || !m_pFS->ReadBlock) | 124 if (!buffer || !size || !m_pFS->ReadBlock) |
| 125 return FALSE; | 125 return 0; |
| 126 | 126 |
| 127 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, | 127 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, |
| 128 (FPDF_DWORD)size) == 0) { | 128 (FPDF_DWORD)size) == 0) { |
| 129 m_nCurPos = offset + size; | 129 m_nCurPos = offset + size; |
| 130 return TRUE; | 130 return size; |
| 131 } | 131 } |
| 132 return FALSE; | 132 return 0; |
| 133 } | 133 } |
| 134 | 134 |
| 135 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) { | 135 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) { |
| 136 if (!buffer || !size || !m_pFS->ReadBlock) | 136 if (!buffer || !size || !m_pFS->ReadBlock) |
| 137 return 0; | 137 return 0; |
| 138 | 138 |
| 139 FX_FILESIZE nSize = GetSize(); | 139 FX_FILESIZE nSize = GetSize(); |
| 140 if (m_nCurPos >= nSize) | 140 if (m_nCurPos >= nSize) |
| 141 return 0; | 141 return 0; |
| 142 FX_FILESIZE dwAvail = nSize - m_nCurPos; | 142 FX_FILESIZE dwAvail = nSize - m_nCurPos; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 168 FX_BOOL CFPDF_FileStream::Flush() { | 168 FX_BOOL CFPDF_FileStream::Flush() { |
| 169 if (!m_pFS || !m_pFS->Flush) | 169 if (!m_pFS || !m_pFS->Flush) |
| 170 return TRUE; | 170 return TRUE; |
| 171 | 171 |
| 172 return m_pFS->Flush(m_pFS->clientData) == 0; | 172 return m_pFS->Flush(m_pFS->clientData) == 0; |
| 173 } | 173 } |
| 174 #endif // PDF_ENABLE_XFA | 174 #endif // PDF_ENABLE_XFA |
| 175 | 175 |
| 176 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 176 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { |
| 177 m_FileAccess = *pFileAccess; | 177 m_FileAccess = *pFileAccess; |
| 178 m_nCurPos = 0; |
| 178 #ifdef PDF_ENABLE_XFA | 179 #ifdef PDF_ENABLE_XFA |
| 179 m_BufferOffset = (uint32_t)-1; | 180 m_BufferOffset = (uint32_t)-1; |
| 180 #endif // PDF_ENABLE_XFA | 181 #endif // PDF_ENABLE_XFA |
| 181 } | 182 } |
| 182 | 183 |
| 183 #ifdef PDF_ENABLE_XFA | 184 #ifdef PDF_ENABLE_XFA |
| 184 CFX_ByteString CPDF_CustomAccess::GetFullPath() { | 185 CFX_ByteString CPDF_CustomAccess::GetFullPath() { |
| 185 return ""; | 186 return ""; |
| 186 } | 187 } |
| 187 | 188 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 213 #endif // PDF_ENABLE_XFA | 214 #endif // PDF_ENABLE_XFA |
| 214 | 215 |
| 215 FX_FILESIZE CPDF_CustomAccess::GetSize() { | 216 FX_FILESIZE CPDF_CustomAccess::GetSize() { |
| 216 return m_FileAccess.m_FileLen; | 217 return m_FileAccess.m_FileLen; |
| 217 } | 218 } |
| 218 | 219 |
| 219 void CPDF_CustomAccess::Release() { | 220 void CPDF_CustomAccess::Release() { |
| 220 delete this; | 221 delete this; |
| 221 } | 222 } |
| 222 | 223 |
| 223 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 224 FX_BOOL CPDF_CustomAccess::IsEOF() { |
| 224 FX_FILESIZE offset, | 225 return m_nCurPos >= static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen); |
| 225 size_t size) { | 226 } |
| 227 |
| 228 size_t CPDF_CustomAccess::ReadBlock(void* buffer, |
| 229 FX_FILESIZE offset, |
| 230 size_t size) { |
| 226 if (offset < 0) { | 231 if (offset < 0) { |
| 227 return FALSE; | 232 return 0; |
| 228 } | 233 } |
| 229 FX_SAFE_FILESIZE newPos = | 234 FX_SAFE_FILESIZE newPos = |
| 230 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 235 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
| 231 newPos += offset; | 236 newPos += offset; |
| 232 if (!newPos.IsValid() || | 237 if (!newPos.IsValid() || |
| 233 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { | 238 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { |
| 234 return FALSE; | 239 return 0; |
| 235 } | 240 } |
| 236 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, | 241 m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, size); |
| 237 size); | 242 m_nCurPos = newPos.ValueOrDie(); |
| 243 return size; |
| 238 } | 244 } |
| 239 | 245 |
| 240 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS | 246 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
| 241 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; | 247 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; |
| 242 | 248 |
| 243 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { | 249 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { |
| 244 switch (policy) { | 250 switch (policy) { |
| 245 case FPDF_POLICY_MACHINETIME_ACCESS: { | 251 case FPDF_POLICY_MACHINETIME_ACCESS: { |
| 246 if (enable) | 252 if (enable) |
| 247 foxit_sandbox_policy |= 0x01; | 253 foxit_sandbox_policy |= 0x01; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 return TRUE; | 416 return TRUE; |
| 411 } | 417 } |
| 412 | 418 |
| 413 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { | 419 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { |
| 414 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); | 420 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); |
| 415 } | 421 } |
| 416 #endif // PDF_ENABLE_XFA | 422 #endif // PDF_ENABLE_XFA |
| 417 | 423 |
| 418 class CMemFile final : public IFX_FileRead { | 424 class CMemFile final : public IFX_FileRead { |
| 419 public: | 425 public: |
| 420 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} | 426 CMemFile(uint8_t* pBuf, FX_FILESIZE size) |
| 427 : m_pBuf(pBuf), m_size(size), m_nCurPos(0) {} |
| 421 | 428 |
| 422 void Release() override { delete this; } | 429 void Release() override { delete this; } |
| 430 FX_BOOL IsEOF() override { return m_nCurPos >= m_size; } |
| 423 FX_FILESIZE GetSize() override { return m_size; } | 431 FX_FILESIZE GetSize() override { return m_size; } |
| 424 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 432 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
| 425 if (offset < 0) { | 433 if (offset < 0) { |
| 426 return FALSE; | 434 return 0; |
| 427 } | 435 } |
| 428 FX_SAFE_FILESIZE newPos = | 436 FX_SAFE_FILESIZE newPos = |
| 429 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 437 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
| 430 newPos += offset; | 438 newPos += offset; |
| 431 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { | 439 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { |
| 432 return FALSE; | 440 return 0; |
| 433 } | 441 } |
| 434 FXSYS_memcpy(buffer, m_pBuf + offset, size); | 442 FXSYS_memcpy(buffer, m_pBuf + offset, size); |
| 435 return TRUE; | 443 m_nCurPos = offset + size; |
| 444 return size; |
| 436 } | 445 } |
| 437 | 446 |
| 438 private: | 447 private: |
| 439 ~CMemFile() override {} | 448 ~CMemFile() override {} |
| 440 | 449 |
| 441 uint8_t* const m_pBuf; | 450 uint8_t* const m_pBuf; |
| 442 const FX_FILESIZE m_size; | 451 const FX_FILESIZE m_size; |
| 452 FX_FILESIZE m_nCurPos; |
| 443 }; | 453 }; |
| 444 | 454 |
| 445 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, | 455 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, |
| 446 int size, | 456 int size, |
| 447 FPDF_BYTESTRING password) { | 457 FPDF_BYTESTRING password) { |
| 448 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); | 458 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); |
| 449 std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 459 std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); |
| 450 pParser->SetPassword(password); | 460 pParser->SetPassword(password); |
| 451 | 461 |
| 452 std::unique_ptr<CPDF_Document> pDocument( | 462 std::unique_ptr<CPDF_Document> pDocument( |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 if (!buffer) { | 1134 if (!buffer) { |
| 1125 *buflen = len; | 1135 *buflen = len; |
| 1126 } else if (*buflen >= len) { | 1136 } else if (*buflen >= len) { |
| 1127 memcpy(buffer, utf16Name.c_str(), len); | 1137 memcpy(buffer, utf16Name.c_str(), len); |
| 1128 *buflen = len; | 1138 *buflen = len; |
| 1129 } else { | 1139 } else { |
| 1130 *buflen = -1; | 1140 *buflen = -1; |
| 1131 } | 1141 } |
| 1132 return (FPDF_DEST)pDestObj; | 1142 return (FPDF_DEST)pDestObj; |
| 1133 } | 1143 } |
| OLD | NEW |