• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fpdfsdk/cpdfsdk_customaccess.h"
8 
9 #include "core/fxcrt/fx_safe_types.h"
10 
CPDFSDK_CustomAccess(FPDF_FILEACCESS * pFileAccess)11 CPDFSDK_CustomAccess::CPDFSDK_CustomAccess(FPDF_FILEACCESS* pFileAccess)
12     : m_FileAccess(*pFileAccess) {}
13 
14 CPDFSDK_CustomAccess::~CPDFSDK_CustomAccess() = default;
15 
GetSize()16 FX_FILESIZE CPDFSDK_CustomAccess::GetSize() {
17   return m_FileAccess.m_FileLen;
18 }
19 
ReadBlockAtOffset(void * buffer,FX_FILESIZE offset,size_t size)20 bool CPDFSDK_CustomAccess::ReadBlockAtOffset(void* buffer,
21                                              FX_FILESIZE offset,
22                                              size_t size) {
23   if (!buffer || offset < 0 || !size)
24     return false;
25 
26   if (!pdfium::base::IsValueInRangeForNumericType<FX_FILESIZE>(size))
27     return false;
28 
29   FX_SAFE_FILESIZE new_pos = size;
30   new_pos += offset;
31   return new_pos.IsValid() && new_pos.ValueOrDie() <= GetSize() &&
32          m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,
33                                  static_cast<uint8_t*>(buffer), size);
34 }
35