Chromium Code Reviews| 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 #include "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../include/fpdfview.h" | 8 #include "../include/fpdfview.h" |
| 9 #include "../include/fsdk_rendercontext.h" | 9 #include "../include/fsdk_rendercontext.h" |
| 10 #include "../include/fpdf_progressive.h" | 10 #include "../include/fpdf_progressive.h" |
| 11 #include "../include/fpdf_ext.h" | 11 #include "../include/fpdf_ext.h" |
| 12 #include "../../third_party/numerics/safe_conversions_impl.h" | 12 #include "../../third_party/numerics/safe_conversions_impl.h" |
| 13 | 13 |
| 14 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) | 14 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
|
jun_fang
2014/08/08 22:16:41
Need to check whether pFileAccess is valid(not NUL
Tom Sepez
2014/08/08 22:21:36
Nah, the existing code seems to work.
| |
| 15 { | 15 { |
| 16 m_FileAccess = *pFileAccess; | 16 m_FileAccess = *pFileAccess; |
| 17 m_BufferOffset = (FX_DWORD)-1; | |
| 18 } | |
| 19 | |
| 20 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch) | |
| 21 { | |
| 22 if (pos >= m_FileAccess.m_FileLen) return FALSE; | |
| 23 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_B ufferOffset + 512) { | |
| 24 // Need to read from file access | |
| 25 m_BufferOffset = pos; | |
| 26 int size = 512; | |
| 27 if (pos + 512 > m_FileAccess.m_FileLen) | |
| 28 size = m_FileAccess.m_FileLen - pos; | |
| 29 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffse t, m_Buffer, size)) | |
| 30 return FALSE; | |
| 31 } | |
| 32 ch = m_Buffer[pos - m_BufferOffset]; | |
| 33 return TRUE; | |
| 34 } | |
| 35 | |
| 36 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size) | |
| 37 { | |
| 38 FX_SAFE_DWORD newPos = size; | |
| 39 newPos += pos; | |
| 40 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { | |
| 41 return FALSE; | |
| 42 } | |
| 43 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | |
| 44 } | 17 } |
| 45 | 18 |
| 46 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si ze) | 19 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si ze) |
| 47 { | 20 { |
| 48 if (offset < 0) { | 21 if (offset < 0) { |
| 49 return FALSE; | 22 return FALSE; |
| 50 } | 23 } |
| 51 FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size); | 24 FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size); |
| 52 newPos += offset; | 25 newPos += offset; |
| 53 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { | 26 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 { | 881 { |
| 909 if (document == NULL) | 882 if (document == NULL) |
| 910 return NULL; | 883 return NULL; |
| 911 if (name == NULL || name[0] == 0) | 884 if (name == NULL || name[0] == 0) |
| 912 return NULL; | 885 return NULL; |
| 913 | 886 |
| 914 CPDF_Document* pDoc = (CPDF_Document*)document; | 887 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 915 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); | 888 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
| 916 return name_tree.LookupNamedDest(pDoc, name); | 889 return name_tree.LookupNamedDest(pDoc, name); |
| 917 } | 890 } |
| OLD | NEW |