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 | 7 |
8 #include "../../core/include/fxcrt/fx_safe_types.h" | 8 #include "../../core/include/fxcrt/fx_safe_types.h" |
9 #include "../../public/fpdf_ext.h" | 9 #include "../../public/fpdf_ext.h" |
10 #include "../../public/fpdf_formfill.h" | 10 #include "../../public/fpdf_formfill.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 return m_pFS->Flush(m_pFS->clientData) == 0; | 98 return m_pFS->Flush(m_pFS->clientData) == 0; |
99 } | 99 } |
100 | 100 |
101 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) | 101 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
102 { | 102 { |
103 m_FileAccess = *pFileAccess; | 103 m_FileAccess = *pFileAccess; |
104 m_BufferOffset = (FX_DWORD)-1; | 104 m_BufferOffset = (FX_DWORD)-1; |
105 } | 105 } |
106 | 106 |
107 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch) | 107 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) |
108 { | 108 { |
109 if (pos >= m_FileAccess.m_FileLen) return FALSE; | 109 if (pos >= m_FileAccess.m_FileLen) return FALSE; |
110 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_B
ufferOffset + 512) { | 110 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_B
ufferOffset + 512) { |
111 // Need to read from file access | 111 // Need to read from file access |
112 m_BufferOffset = pos; | 112 m_BufferOffset = pos; |
113 int size = 512; | 113 int size = 512; |
114 if (pos + 512 > m_FileAccess.m_FileLen) | 114 if (pos + 512 > m_FileAccess.m_FileLen) |
115 size = m_FileAccess.m_FileLen - pos; | 115 size = m_FileAccess.m_FileLen - pos; |
116 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffse
t, m_Buffer, size)) | 116 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffse
t, m_Buffer, size)) |
117 return FALSE; | 117 return FALSE; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 { | 295 { |
296 return document && (static_cast<CPDFXFA_Document *>(document))->LoadXFAD
oc(); | 296 return document && (static_cast<CPDFXFA_Document *>(document))->LoadXFAD
oc(); |
297 } | 297 } |
298 | 298 |
299 | 299 |
300 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); | 300 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); |
301 | 301 |
302 class CMemFile final : public IFX_FileRead | 302 class CMemFile final : public IFX_FileRead |
303 { | 303 { |
304 public: | 304 public: |
305 » CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} | 305 » CMemFile(uint8_t* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} |
306 | 306 |
307 virtual void Release() {delete this;} | 307 virtual void Release() {delete this;} |
308 virtual FX_FILESIZE GetSize() {return m_size;} | 308 virtual FX_FILESIZE GetSize() {return m_size;} |
309 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size) | 309 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size) |
310 { | 310 { |
311 if (offset < 0) { | 311 if (offset < 0) { |
312 return FALSE; | 312 return FALSE; |
313 } | 313 } |
314 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, si
ze_t>(size); | 314 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, si
ze_t>(size); |
315 newPos += offset; | 315 newPos += offset; |
316 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) { | 316 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) { |
317 return FALSE; | 317 return FALSE; |
318 } | 318 } |
319 FXSYS_memcpy(buffer, m_pBuf+offset, size); | 319 FXSYS_memcpy(buffer, m_pBuf+offset, size); |
320 return TRUE; | 320 return TRUE; |
321 } | 321 } |
322 private: | 322 private: |
323 » FX_BYTE* m_pBuf; | 323 » uint8_t* m_pBuf; |
324 FX_FILESIZE m_size; | 324 FX_FILESIZE m_size; |
325 }; | 325 }; |
326 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
ize, FPDF_BYTESTRING password) | 326 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
ize, FPDF_BYTESTRING password) |
327 { | 327 { |
328 CPDF_Parser* pParser = FX_NEW CPDF_Parser; | 328 CPDF_Parser* pParser = FX_NEW CPDF_Parser; |
329 pParser->SetPassword(password); | 329 pParser->SetPassword(password); |
330 » CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size); | 330 » CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); |
331 FX_DWORD err_code = pParser->StartParse(pMemFile); | 331 FX_DWORD err_code = pParser->StartParse(pMemFile); |
332 if (err_code) { | 332 if (err_code) { |
333 delete pParser; | 333 delete pParser; |
334 ProcessParseError(err_code); | 334 ProcessParseError(err_code); |
335 return NULL; | 335 return NULL; |
336 } | 336 } |
337 CPDF_Document * pDoc = NULL; | 337 CPDF_Document * pDoc = NULL; |
338 pDoc = pParser?pParser->GetDocument():NULL; | 338 pDoc = pParser?pParser->GetDocument():NULL; |
339 CheckUnSupportError(pDoc, err_code); | 339 CheckUnSupportError(pDoc, err_code); |
340 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 340 CPDF_Document* pPDFDoc = pParser->GetDocument(); |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 if (!buffer) { | 1043 if (!buffer) { |
1044 *buflen = len; | 1044 *buflen = len; |
1045 } else if (*buflen >= len) { | 1045 } else if (*buflen >= len) { |
1046 memcpy(buffer, utf16Name.c_str(), len); | 1046 memcpy(buffer, utf16Name.c_str(), len); |
1047 *buflen = len; | 1047 *buflen = len; |
1048 } else { | 1048 } else { |
1049 *buflen = -1; | 1049 *buflen = -1; |
1050 } | 1050 } |
1051 return (FPDF_DEST)pDestObj; | 1051 return (FPDF_DEST)pDestObj; |
1052 } | 1052 } |
OLD | NEW |