| 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 "../../core/include/fxcrt/fx_safe_types.h" | 7 #include "../../core/include/fxcrt/fx_safe_types.h" |
| 8 #include "../../public/fpdf_ext.h" | 8 #include "../../public/fpdf_ext.h" |
| 9 #include "../../public/fpdf_progressive.h" | 9 #include "../../public/fpdf_progressive.h" |
| 10 #include "../../public/fpdfview.h" | 10 #include "../../public/fpdfview.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return NULL; | 195 return NULL; |
| 196 } | 196 } |
| 197 return pParser->GetDocument(); | 197 return pParser->GetDocument(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); | 200 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); |
| 201 | 201 |
| 202 class CMemFile final: public IFX_FileRead | 202 class CMemFile final: public IFX_FileRead |
| 203 { | 203 { |
| 204 public: | 204 public: |
| 205 » CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} | 205 » CMemFile(uint8_t* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} |
| 206 | 206 |
| 207 virtual void Release() {delete this;} | 207 virtual void Release() {delete this;} |
| 208 virtual FX_FILESIZE GetSize() {return m_size;} | 208 virtual FX_FILESIZE GetSize() {return m_size;} |
| 209 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size) | 209 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size) |
| 210 { | 210 { |
| 211 if (offset < 0) { | 211 if (offset < 0) { |
| 212 return FALSE; | 212 return FALSE; |
| 213 } | 213 } |
| 214 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, si
ze_t>(size); | 214 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, si
ze_t>(size); |
| 215 newPos += offset; | 215 newPos += offset; |
| 216 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) { | 216 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) { |
| 217 return FALSE; | 217 return FALSE; |
| 218 } | 218 } |
| 219 FXSYS_memcpy(buffer, m_pBuf+offset, size); | 219 FXSYS_memcpy(buffer, m_pBuf+offset, size); |
| 220 return TRUE; | 220 return TRUE; |
| 221 } | 221 } |
| 222 private: | 222 private: |
| 223 » FX_BYTE* m_pBuf; | 223 » uint8_t* m_pBuf; |
| 224 FX_FILESIZE m_size; | 224 FX_FILESIZE m_size; |
| 225 }; | 225 }; |
| 226 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
ize, FPDF_BYTESTRING password) | 226 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
ize, FPDF_BYTESTRING password) |
| 227 { | 227 { |
| 228 CPDF_Parser* pParser = new CPDF_Parser; | 228 CPDF_Parser* pParser = new CPDF_Parser; |
| 229 pParser->SetPassword(password); | 229 pParser->SetPassword(password); |
| 230 » CMemFile* pMemFile = new CMemFile((FX_BYTE*)data_buf, size); | 230 » CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); |
| 231 FX_DWORD err_code = pParser->StartParse(pMemFile); | 231 FX_DWORD err_code = pParser->StartParse(pMemFile); |
| 232 if (err_code) { | 232 if (err_code) { |
| 233 delete pParser; | 233 delete pParser; |
| 234 ProcessParseError(err_code); | 234 ProcessParseError(err_code); |
| 235 return NULL; | 235 return NULL; |
| 236 } | 236 } |
| 237 CPDF_Document * pDoc = NULL; | 237 CPDF_Document * pDoc = NULL; |
| 238 pDoc = pParser?pParser->GetDocument():NULL; | 238 pDoc = pParser?pParser->GetDocument():NULL; |
| 239 CheckUnSupportError(pDoc, err_code); | 239 CheckUnSupportError(pDoc, err_code); |
| 240 return pParser->GetDocument(); | 240 return pParser->GetDocument(); |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 if (!buffer) { | 867 if (!buffer) { |
| 868 *buflen = len; | 868 *buflen = len; |
| 869 } else if (*buflen >= len) { | 869 } else if (*buflen >= len) { |
| 870 memcpy(buffer, utf16Name.c_str(), len); | 870 memcpy(buffer, utf16Name.c_str(), len); |
| 871 *buflen = len; | 871 *buflen = len; |
| 872 } else { | 872 } else { |
| 873 *buflen = -1; | 873 *buflen = -1; |
| 874 } | 874 } |
| 875 return (FPDF_DEST)pDestObj; | 875 return (FPDF_DEST)pDestObj; |
| 876 } | 876 } |
| OLD | NEW |