| 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 "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (!m_pFS || !m_pFS->Flush) | 146 if (!m_pFS || !m_pFS->Flush) |
| 147 return TRUE; | 147 return TRUE; |
| 148 | 148 |
| 149 return m_pFS->Flush(m_pFS->clientData) == 0; | 149 return m_pFS->Flush(m_pFS->clientData) == 0; |
| 150 } | 150 } |
| 151 #endif // PDF_ENABLE_XFA | 151 #endif // PDF_ENABLE_XFA |
| 152 | 152 |
| 153 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 153 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { |
| 154 m_FileAccess = *pFileAccess; | 154 m_FileAccess = *pFileAccess; |
| 155 #ifdef PDF_ENABLE_XFA | 155 #ifdef PDF_ENABLE_XFA |
| 156 m_BufferOffset = (FX_DWORD)-1; | 156 m_BufferOffset = (uint32_t)-1; |
| 157 #endif // PDF_ENABLE_XFA | 157 #endif // PDF_ENABLE_XFA |
| 158 } | 158 } |
| 159 | 159 |
| 160 #ifdef PDF_ENABLE_XFA | 160 #ifdef PDF_ENABLE_XFA |
| 161 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { | 161 FX_BOOL CPDF_CustomAccess::GetByte(uint32_t pos, uint8_t& ch) { |
| 162 if (pos >= m_FileAccess.m_FileLen) | 162 if (pos >= m_FileAccess.m_FileLen) |
| 163 return FALSE; | 163 return FALSE; |
| 164 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || | 164 if (m_BufferOffset == (uint32_t)-1 || pos < m_BufferOffset || |
| 165 pos >= m_BufferOffset + 512) { | 165 pos >= m_BufferOffset + 512) { |
| 166 // Need to read from file access | 166 // Need to read from file access |
| 167 m_BufferOffset = pos; | 167 m_BufferOffset = pos; |
| 168 int size = 512; | 168 int size = 512; |
| 169 if (pos + 512 > m_FileAccess.m_FileLen) | 169 if (pos + 512 > m_FileAccess.m_FileLen) |
| 170 size = m_FileAccess.m_FileLen - pos; | 170 size = m_FileAccess.m_FileLen - pos; |
| 171 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, | 171 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, |
| 172 size)) | 172 size)) |
| 173 return FALSE; | 173 return FALSE; |
| 174 } | 174 } |
| 175 ch = m_Buffer[pos - m_BufferOffset]; | 175 ch = m_Buffer[pos - m_BufferOffset]; |
| 176 return TRUE; | 176 return TRUE; |
| 177 } | 177 } |
| 178 | 178 |
| 179 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, | 179 FX_BOOL CPDF_CustomAccess::GetBlock(uint32_t pos, |
| 180 uint8_t* pBuf, | 180 uint8_t* pBuf, |
| 181 FX_DWORD size) { | 181 uint32_t size) { |
| 182 if (pos + size > m_FileAccess.m_FileLen) | 182 if (pos + size > m_FileAccess.m_FileLen) |
| 183 return FALSE; | 183 return FALSE; |
| 184 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | 184 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); |
| 185 } | 185 } |
| 186 #endif // PDF_ENABLE_XFA | 186 #endif // PDF_ENABLE_XFA |
| 187 | 187 |
| 188 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 188 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, |
| 189 FX_FILESIZE offset, | 189 FX_FILESIZE offset, |
| 190 size_t size) { | 190 size_t size) { |
| 191 if (offset < 0) { | 191 if (offset < 0) { |
| 192 return FALSE; | 192 return FALSE; |
| 193 } | 193 } |
| 194 FX_SAFE_FILESIZE newPos = | 194 FX_SAFE_FILESIZE newPos = |
| 195 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 195 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
| 196 newPos += offset; | 196 newPos += offset; |
| 197 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { | 197 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { |
| 198 return FALSE; | 198 return FALSE; |
| 199 } | 199 } |
| 200 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, | 200 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, |
| 201 size); | 201 size); |
| 202 } | 202 } |
| 203 | 203 |
| 204 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS | 204 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
| 205 static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF; | 205 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; |
| 206 | 206 |
| 207 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { | 207 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { |
| 208 switch (policy) { | 208 switch (policy) { |
| 209 case FPDF_POLICY_MACHINETIME_ACCESS: { | 209 case FPDF_POLICY_MACHINETIME_ACCESS: { |
| 210 if (enable) | 210 if (enable) |
| 211 foxit_sandbox_policy |= 0x01; | 211 foxit_sandbox_policy |= 0x01; |
| 212 else | 212 else |
| 213 foxit_sandbox_policy &= 0xFFFFFFFE; | 213 foxit_sandbox_policy &= 0xFFFFFFFE; |
| 214 } break; | 214 } break; |
| 215 default: | 215 default: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 void SetLastError(int err) { | 275 void SetLastError(int err) { |
| 276 g_LastError = err; | 276 g_LastError = err; |
| 277 } | 277 } |
| 278 | 278 |
| 279 int GetLastError() { | 279 int GetLastError() { |
| 280 return g_LastError; | 280 return g_LastError; |
| 281 } | 281 } |
| 282 #endif // _WIN32 | 282 #endif // _WIN32 |
| 283 | 283 |
| 284 void ProcessParseError(CPDF_Parser::Error err) { | 284 void ProcessParseError(CPDF_Parser::Error err) { |
| 285 FX_DWORD err_code = FPDF_ERR_SUCCESS; | 285 uint32_t err_code = FPDF_ERR_SUCCESS; |
| 286 // Translate FPDFAPI error code to FPDFVIEW error code | 286 // Translate FPDFAPI error code to FPDFVIEW error code |
| 287 switch (err) { | 287 switch (err) { |
| 288 case CPDF_Parser::SUCCESS: | 288 case CPDF_Parser::SUCCESS: |
| 289 err_code = FPDF_ERR_SUCCESS; | 289 err_code = FPDF_ERR_SUCCESS; |
| 290 break; | 290 break; |
| 291 case CPDF_Parser::FILE_ERROR: | 291 case CPDF_Parser::FILE_ERROR: |
| 292 err_code = FPDF_ERR_FILE; | 292 err_code = FPDF_ERR_FILE; |
| 293 break; | 293 break; |
| 294 case CPDF_Parser::FORMAT_ERROR: | 294 case CPDF_Parser::FORMAT_ERROR: |
| 295 err_code = FPDF_ERR_FORMAT; | 295 err_code = FPDF_ERR_FORMAT; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 void Release() override { delete this; } | 384 void Release() override { delete this; } |
| 385 FX_FILESIZE GetSize() override { return m_size; } | 385 FX_FILESIZE GetSize() override { return m_size; } |
| 386 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 386 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
| 387 if (offset < 0) { | 387 if (offset < 0) { |
| 388 return FALSE; | 388 return FALSE; |
| 389 } | 389 } |
| 390 FX_SAFE_FILESIZE newPos = | 390 FX_SAFE_FILESIZE newPos = |
| 391 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 391 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
| 392 newPos += offset; | 392 newPos += offset; |
| 393 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) { | 393 if (!newPos.IsValid() || newPos.ValueOrDie() > (uint32_t)m_size) { |
| 394 return FALSE; | 394 return FALSE; |
| 395 } | 395 } |
| 396 FXSYS_memcpy(buffer, m_pBuf + offset, size); | 396 FXSYS_memcpy(buffer, m_pBuf + offset, size); |
| 397 return TRUE; | 397 return TRUE; |
| 398 } | 398 } |
| 399 | 399 |
| 400 private: | 400 private: |
| 401 ~CMemFile() override {} | 401 ~CMemFile() override {} |
| 402 | 402 |
| 403 uint8_t* const m_pBuf; | 403 uint8_t* const m_pBuf; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 return FALSE; | 451 return FALSE; |
| 452 | 452 |
| 453 CPDF_Parser* pParser = pDoc->GetParser(); | 453 CPDF_Parser* pParser = pDoc->GetParser(); |
| 454 if (!pParser) | 454 if (!pParser) |
| 455 return FALSE; | 455 return FALSE; |
| 456 | 456 |
| 457 *fileVersion = pParser->GetFileVersion(); | 457 *fileVersion = pParser->GetFileVersion(); |
| 458 return TRUE; | 458 return TRUE; |
| 459 } | 459 } |
| 460 | 460 |
| 461 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match | 461 // jabdelmalek: changed return type from uint32_t to build on Linux (and match |
| 462 // header). | 462 // header). |
| 463 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { | 463 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { |
| 464 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 464 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 465 if (!pDoc) | 465 if (!pDoc) |
| 466 #ifndef PDF_ENABLE_XFA | 466 #ifndef PDF_ENABLE_XFA |
| 467 return 0; | 467 return 0; |
| 468 #else // PDF_ENABLE_XFA | 468 #else // PDF_ENABLE_XFA |
| 469 return (FX_DWORD)-1; | 469 return (uint32_t)-1; |
| 470 #endif // PDF_ENABLE_XFA | 470 #endif // PDF_ENABLE_XFA |
| 471 | 471 |
| 472 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 472 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
| 473 return pDict ? pDict->GetIntegerBy("P") : (FX_DWORD)-1; | 473 return pDict ? pDict->GetIntegerBy("P") : (uint32_t)-1; |
| 474 } | 474 } |
| 475 | 475 |
| 476 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { | 476 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { |
| 477 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 477 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 478 if (!pDoc) | 478 if (!pDoc) |
| 479 return -1; | 479 return -1; |
| 480 | 480 |
| 481 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 481 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
| 482 return pDict ? pDict->GetIntegerBy("R") : -1; | 482 return pDict ? pDict->GetIntegerBy("R") : -1; |
| 483 } | 483 } |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 if (!buffer) { | 1158 if (!buffer) { |
| 1159 *buflen = len; | 1159 *buflen = len; |
| 1160 } else if (*buflen >= len) { | 1160 } else if (*buflen >= len) { |
| 1161 memcpy(buffer, utf16Name.c_str(), len); | 1161 memcpy(buffer, utf16Name.c_str(), len); |
| 1162 *buflen = len; | 1162 *buflen = len; |
| 1163 } else { | 1163 } else { |
| 1164 *buflen = -1; | 1164 *buflen = -1; |
| 1165 } | 1165 } |
| 1166 return (FPDF_DEST)pDestObj; | 1166 return (FPDF_DEST)pDestObj; |
| 1167 } | 1167 } |
| OLD | NEW |