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 "third_party/base/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::base::IsValueInRangeForNumericType<FX_FILESIZE>(buffer.size()))
27 return false;
28
29 FX_SAFE_FILESIZE new_pos = buffer.size();
30 new_pos += offset;
31 return new_pos.IsValid() && new_pos.ValueOrDie() <= GetSize() &&
32 m_FileAccess.m_GetBlock(
33 m_FileAccess.m_Param,
34 pdfium::base::checked_cast<unsigned long>(offset), buffer.data(),
35 pdfium::base::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
#define FX_FILESIZE
Definition fx_types.h:19