Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdfsdk_customaccess.cpp
Go to the documentation of this file.
1// Copyright 2018 The PDFium Authors
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#include "core/fxcrt/numerics/safe_conversions.h"
11
12CPDFSDK_CustomAccess::CPDFSDK_CustomAccess(FPDF_FILEACCESS* pFileAccess)
13 : m_FileAccess(*pFileAccess) {}
14
15CPDFSDK_CustomAccess::~CPDFSDK_CustomAccess() = default;
16
17FX_FILESIZE CPDFSDK_CustomAccess::GetSize() {
18 return m_FileAccess.m_FileLen;
19}
20
21bool CPDFSDK_CustomAccess::ReadBlockAtOffset(pdfium::span<uint8_t> buffer,
22 FX_FILESIZE offset) {
23 if (buffer.empty() || offset < 0)
24 return false;
25
26 if (!pdfium::IsValueInRangeForNumericType<FX_FILESIZE>(buffer.size())) {
27 return false;
28 }
29
30 FX_SAFE_FILESIZE new_pos = buffer.size();
31 new_pos += offset;
32 return new_pos.IsValid() && new_pos.ValueOrDie() <= GetSize() &&
33 m_FileAccess.m_GetBlock(
34 m_FileAccess.m_Param, pdfium::checked_cast<unsigned long>(offset),
35 buffer.data(), pdfium::checked_cast<unsigned long>(buffer.size()));
36}
bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset) override
FX_FILESIZE GetSize() override
~CPDFSDK_CustomAccess() override
pdfium::CheckedNumeric< FX_FILESIZE > FX_SAFE_FILESIZE
#define FX_FILESIZE
Definition fx_types.h:19