| 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 "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../include/fpdfview.h" | 8 #include "../include/fpdfview.h" |
| 9 #include "../include/fsdk_rendercontext.h" | 9 #include "../include/fsdk_rendercontext.h" |
| 10 #include "../include/fpdf_progressive.h" | 10 #include "../include/fpdf_progressive.h" |
| 11 #include "../include/fpdf_ext.h" | 11 #include "../include/fpdf_ext.h" |
| 12 | 12 #include "../../third_party/numerics/safe_conversions_impl.h" |
| 13 | 13 |
| 14 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) | 14 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
| 15 { | 15 { |
| 16 m_FileAccess = *pFileAccess; | 16 m_FileAccess = *pFileAccess; |
| 17 m_BufferOffset = (FX_DWORD)-1; | 17 m_BufferOffset = (FX_DWORD)-1; |
| 18 } | 18 } |
| 19 | 19 |
| 20 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch) | 20 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch) |
| 21 { | 21 { |
| 22 if (pos >= m_FileAccess.m_FileLen) return FALSE; | 22 if (pos >= m_FileAccess.m_FileLen) return FALSE; |
| 23 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_B
ufferOffset + 512) { | 23 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_B
ufferOffset + 512) { |
| 24 // Need to read from file access | 24 // Need to read from file access |
| 25 m_BufferOffset = pos; | 25 m_BufferOffset = pos; |
| 26 int size = 512; | 26 int size = 512; |
| 27 if (pos + 512 > m_FileAccess.m_FileLen) | 27 if (pos + 512 > m_FileAccess.m_FileLen) |
| 28 size = m_FileAccess.m_FileLen - pos; | 28 size = m_FileAccess.m_FileLen - pos; |
| 29 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffse
t, m_Buffer, size)) | 29 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffse
t, m_Buffer, size)) |
| 30 return FALSE; | 30 return FALSE; |
| 31 } | 31 } |
| 32 ch = m_Buffer[pos - m_BufferOffset]; | 32 ch = m_Buffer[pos - m_BufferOffset]; |
| 33 return TRUE; | 33 return TRUE; |
| 34 } | 34 } |
| 35 | 35 |
| 36 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size) | 36 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size) |
| 37 { | 37 { |
| 38 » if (pos + size > m_FileAccess.m_FileLen) return FALSE; | 38 FX_SAFE_DWORD newPos = size; |
| 39 newPos += pos; |
| 40 » if (!newPos.IsValid() || newPos.ValueOrDie() >= m_FileAccess.m_FileLen)
{ |
| 41 return FALSE; |
| 42 } |
| 43 |
| 39 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | 44 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); |
| 40 } | 45 } |
| 41 | 46 |
| 42 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si
ze) | 47 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si
ze) |
| 43 { | 48 { |
| 44 » //» m_FileAccess = *pFileAccess; | 49 if (offset < 0) { |
| 45 » //» m_BufferOffset = (FX_DWORD)-1; | 50 return FALSE; |
| 46 » if (offset + size > m_FileAccess.m_FileLen) return FALSE; | 51 } |
| 52 FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size); |
| 53 newPos += offset; |
| 54 » if (!newPos.IsValid() || newPos.ValueOrDie() >= m_FileAccess.m_FileLen)
{ |
| 55 return FALSE; |
| 56 } |
| 57 |
| 47 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(FX_LPBYTE)
buffer, size); | 58 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(FX_LPBYTE)
buffer, size); |
| 48 | |
| 49 // return FALSE; | |
| 50 } | 59 } |
| 51 | 60 |
| 52 //0 bit: FPDF_POLICY_MACHINETIME_ACCESS | 61 //0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
| 53 static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF; | 62 static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF; |
| 54 | 63 |
| 55 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) | 64 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) |
| 56 { | 65 { |
| 57 switch(policy) | 66 switch(policy) |
| 58 { | 67 { |
| 59 case FPDF_POLICY_MACHINETIME_ACCESS: | 68 case FPDF_POLICY_MACHINETIME_ACCESS: |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 294 |
| 286 class CMemFile FX_FINAL: public IFX_FileRead, public CFX_Object | 295 class CMemFile FX_FINAL: public IFX_FileRead, public CFX_Object |
| 287 { | 296 { |
| 288 public: | 297 public: |
| 289 CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} | 298 CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} |
| 290 | 299 |
| 291 virtual void Release() {delete this;} | 300 virtual void Release() {delete this;} |
| 292 virtual FX_FILESIZE GetSize() {return m_size;} | 301 virtual FX_FILESIZE GetSize() {return m_size;} |
| 293 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size) | 302 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size) |
| 294 { | 303 { |
| 295 » » if(offset+size > (FX_DWORD)m_size) return FALSE; | 304 if (offset < 0) { |
| 305 return FALSE; |
| 306 } |
| 307 |
| 308 FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t
>(size); |
| 309 newPos += offset; |
| 310 if (!newPos.IsValid() || newPos.ValueOrDie() >= (FX_DWORD)m_size
) return FALSE; |
| 296 FXSYS_memcpy(buffer, m_pBuf+offset, size); | 311 FXSYS_memcpy(buffer, m_pBuf+offset, size); |
| 312 |
| 297 return TRUE; | 313 return TRUE; |
| 298 } | 314 } |
| 299 private: | 315 private: |
| 300 FX_BYTE* m_pBuf; | 316 FX_BYTE* m_pBuf; |
| 301 FX_FILESIZE m_size; | 317 FX_FILESIZE m_size; |
| 302 }; | 318 }; |
| 303 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
ize, FPDF_BYTESTRING password) | 319 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
ize, FPDF_BYTESTRING password) |
| 304 { | 320 { |
| 305 CPDF_Parser* pParser = FX_NEW CPDF_Parser; | 321 CPDF_Parser* pParser = FX_NEW CPDF_Parser; |
| 306 pParser->SetPassword(password); | 322 pParser->SetPassword(password); |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 { | 910 { |
| 895 if (document == NULL) | 911 if (document == NULL) |
| 896 return NULL; | 912 return NULL; |
| 897 if (name == NULL || name[0] == 0) | 913 if (name == NULL || name[0] == 0) |
| 898 return NULL; | 914 return NULL; |
| 899 | 915 |
| 900 CPDF_Document* pDoc = (CPDF_Document*)document; | 916 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 901 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); | 917 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
| 902 return name_tree.LookupNamedDest(pDoc, name); | 918 return name_tree.LookupNamedDest(pDoc, name); |
| 903 } | 919 } |
| OLD | NEW |