Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 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 | CPDFSDK_CustomAccess::CPDFSDK_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
| 10 | : m_FileAccess(*pFileAccess) {} |
| 11 | |
| 12 | FX_FILESIZE CPDFSDK_CustomAccess::GetSize() { |
| 13 | return m_FileAccess.m_FileLen; |
| 14 | } |
| 15 | |
| 16 | bool CPDFSDK_CustomAccess::ReadBlock(void* buffer, |
| 17 | FX_FILESIZE offset, |
| 18 | size_t size) { |
| 19 | if (offset < 0) |
| 20 | return false; |
| 21 | |
| 22 | FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); |
| 23 | newPos += offset; |
| 24 | if (!newPos.IsValid() || |
| 25 | newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { |
| 26 | return false; |
| 27 | } |
| 28 | return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, |
| 29 | static_cast<uint8_t*>(buffer), size); |
| 30 | } |