| 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 #ifndef _FXCRT_EXTENSION_IMP_ | 7 #ifndef _FXCRT_EXTENSION_IMP_ |
| 8 #define _FXCRT_EXTENSION_IMP_ | 8 #define _FXCRT_EXTENSION_IMP_ |
| 9 | 9 |
| 10 class IFXCRT_FileAccess | 10 class IFXCRT_FileAccess |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_
FILESIZE size) | 67 virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_
FILESIZE size) |
| 68 { | 68 { |
| 69 if (offset < 0 || size < 0) { | 69 if (offset < 0 || size < 0) { |
| 70 return FALSE; | 70 return FALSE; |
| 71 } | 71 } |
| 72 | 72 |
| 73 FX_SAFE_FILESIZE pos = size; | 73 FX_SAFE_FILESIZE pos = size; |
| 74 pos += offset; | 74 pos += offset; |
| 75 | 75 |
| 76 if (!pos.IsValid() || pos.ValueOrDie() >= m_pFile->GetSize()) { | 76 if (!pos.IsValid() || pos.ValueOrDie() > m_pFile->GetSize()) { |
| 77 return FALSE; | 77 return FALSE; |
| 78 } | 78 } |
| 79 | 79 |
| 80 m_nOffset = offset, m_nSize = size; | 80 m_nOffset = offset, m_nSize = size; |
| 81 m_bUseRange = TRUE; | 81 m_bUseRange = TRUE; |
| 82 m_pFile->SetPosition(m_nOffset); | 82 m_pFile->SetPosition(m_nOffset); |
| 83 return TRUE; | 83 return TRUE; |
| 84 } | 84 } |
| 85 virtual void ClearRange() | 85 virtual void ClearRange() |
| 86 { | 86 { |
| 87 m_bUseRange = FALSE; | 87 m_bUseRange = FALSE; |
| 88 } | 88 } |
| 89 virtual FX_BOOL ReadBlock(void* buffer, FX_FILES
IZE offset, size_t size) | 89 virtual FX_BOOL ReadBlock(void* buffer, FX_FILES
IZE offset, size_t size) |
| 90 { | 90 { |
| 91 if (m_bUseRange && offset < 0) { | 91 if (m_bUseRange && offset < 0) { |
| 92 return FALSE; | 92 return FALSE; |
| 93 } | 93 } |
| 94 FX_SAFE_FILESIZE pos = offset; | 94 FX_SAFE_FILESIZE pos = offset; |
| 95 | 95 |
| 96 if (m_bUseRange) { | 96 if (m_bUseRange) { |
| 97 pos += m_nOffset; | 97 pos += m_nOffset; |
| 98 if (!pos.IsValid() || pos.ValueOrDie() >= (size_t)GetSize()) { | 98 if (!pos.IsValid() || pos.ValueOrDie() > (size_t)GetSize()) { |
| 99 return FALSE; | 99 return FALSE; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 return (FX_BOOL)m_pFile->ReadPos(buffer, size, pos.ValueOrDie()); | 102 return (FX_BOOL)m_pFile->ReadPos(buffer, size, pos.ValueOrDie()); |
| 103 } | 103 } |
| 104 virtual size_t ReadBlock(void* buffer, size_t s
ize) | 104 virtual size_t ReadBlock(void* buffer, size_t s
ize) |
| 105 { | 105 { |
| 106 if (m_bUseRange) { | 106 if (m_bUseRange) { |
| 107 FX_FILESIZE availSize = m_nOffset + m_nSize - m_pFile->GetPosition()
; | 107 FX_FILESIZE availSize = m_nOffset + m_nSize - m_pFile->GetPosition()
; |
| 108 if ((size_t)availSize < size) { | 108 if ((size_t)availSize < size) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 return pos; | 194 return pos; |
| 195 } | 195 } |
| 196 virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_
FILESIZE size) | 196 virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_
FILESIZE size) |
| 197 { | 197 { |
| 198 if (offset < 0 || size < 0) { | 198 if (offset < 0 || size < 0) { |
| 199 return FALSE; | 199 return FALSE; |
| 200 } | 200 } |
| 201 FX_SAFE_FILESIZE range = size; | 201 FX_SAFE_FILESIZE range = size; |
| 202 range += offset; | 202 range += offset; |
| 203 if (!range.IsValid() || range.ValueOrDie() >= m_nCurSize) { | 203 if (!range.IsValid() || range.ValueOrDie() > m_nCurSize) { |
| 204 return FALSE; | 204 return FALSE; |
| 205 } | 205 } |
| 206 | 206 |
| 207 m_nOffset = (size_t)offset, m_nSize = (size_t)size; | 207 m_nOffset = (size_t)offset, m_nSize = (size_t)size; |
| 208 m_bUseRange = TRUE; | 208 m_bUseRange = TRUE; |
| 209 m_nCurPos = m_nOffset; | 209 m_nCurPos = m_nOffset; |
| 210 return TRUE; | 210 return TRUE; |
| 211 } | 211 } |
| 212 virtual void ClearRange() | 212 virtual void ClearRange() |
| 213 { | 213 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 225 } | 225 } |
| 226 | 226 |
| 227 if (!safeOffset.IsValid()) { | 227 if (!safeOffset.IsValid()) { |
| 228 return FALSE; | 228 return FALSE; |
| 229 } | 229 } |
| 230 | 230 |
| 231 offset = safeOffset.ValueOrDie(); | 231 offset = safeOffset.ValueOrDie(); |
| 232 | 232 |
| 233 FX_SAFE_SIZE_T newPos = size; | 233 FX_SAFE_SIZE_T newPos = size; |
| 234 newPos += offset; | 234 newPos += offset; |
| 235 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || newPos.ValueOr
Die() >= m_nCurSize) { | 235 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || newPos.ValueOr
Die() > m_nCurSize) { |
| 236 return FALSE; | 236 return FALSE; |
| 237 } | 237 } |
| 238 | 238 |
| 239 m_nCurPos = newPos.ValueOrDie(); | 239 m_nCurPos = newPos.ValueOrDie(); |
| 240 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { | 240 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { |
| 241 FXSYS_memcpy32(buffer, (FX_LPBYTE)m_Blocks[0] + (size_t)offset, size
); | 241 FXSYS_memcpy32(buffer, (FX_LPBYTE)m_Blocks[0] + (size_t)offset, size
); |
| 242 return TRUE; | 242 return TRUE; |
| 243 } | 243 } |
| 244 size_t nStartBlock = (size_t)offset / m_nGrowSize; | 244 size_t nStartBlock = (size_t)offset / m_nGrowSize; |
| 245 offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); | 245 offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 FX_DWORD mt[MT_N]; | 433 FX_DWORD mt[MT_N]; |
| 434 } FX_MTRANDOMCONTEXT, * FX_LPMTRANDOMCONTEXT; | 434 } FX_MTRANDOMCONTEXT, * FX_LPMTRANDOMCONTEXT; |
| 435 typedef FX_MTRANDOMCONTEXT const * FX_LPCMTRANDOMCONTEXT; | 435 typedef FX_MTRANDOMCONTEXT const * FX_LPCMTRANDOMCONTEXT; |
| 436 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 436 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 437 FX_BOOL FX_GenerateCryptoRandom(FX_LPDWORD pBuffer, FX_INT32 iCount); | 437 FX_BOOL FX_GenerateCryptoRandom(FX_LPDWORD pBuffer, FX_INT32 iCount); |
| 438 #endif | 438 #endif |
| 439 #ifdef __cplusplus | 439 #ifdef __cplusplus |
| 440 } | 440 } |
| 441 #endif | 441 #endif |
| 442 #endif | 442 #endif |
| OLD | NEW |