| 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 "core/fpdfapi/edit/editint.h" | 7 #include "core/fpdfapi/edit/editint.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 return -1; | 1472 return -1; |
| 1473 } | 1473 } |
| 1474 m_Offset += len; | 1474 m_Offset += len; |
| 1475 if ((len = m_File.AppendString("\r\n%\xA1\xB3\xC5\xD7\r\n")) < 0) { | 1475 if ((len = m_File.AppendString("\r\n%\xA1\xB3\xC5\xD7\r\n")) < 0) { |
| 1476 return -1; | 1476 return -1; |
| 1477 } | 1477 } |
| 1478 m_Offset += len; | 1478 m_Offset += len; |
| 1479 InitOldObjNumOffsets(); | 1479 InitOldObjNumOffsets(); |
| 1480 m_iStage = 20; | 1480 m_iStage = 20; |
| 1481 } else { | 1481 } else { |
| 1482 IFX_SeekableReadStream* pSrcFile = m_pParser->GetFileAccess(); | 1482 CFX_RetainPtr<IFX_SeekableReadStream> pSrcFile = |
| 1483 m_pParser->GetFileAccess(); |
| 1483 m_Offset = pSrcFile->GetSize(); | 1484 m_Offset = pSrcFile->GetSize(); |
| 1484 m_Pos = (void*)(uintptr_t)m_Offset; | 1485 m_Pos = (void*)(uintptr_t)m_Offset; |
| 1485 m_iStage = 15; | 1486 m_iStage = 15; |
| 1486 } | 1487 } |
| 1487 } | 1488 } |
| 1488 if (m_iStage == 15) { | 1489 if (m_iStage == 15) { |
| 1489 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && m_Pos) { | 1490 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && m_Pos) { |
| 1490 IFX_SeekableReadStream* pSrcFile = m_pParser->GetFileAccess(); | 1491 CFX_RetainPtr<IFX_SeekableReadStream> pSrcFile = |
| 1491 uint8_t buffer[4096]; | 1492 m_pParser->GetFileAccess(); |
| 1493 uint8_t buffer[4096]; // TODO(tsepez): don't stack allocate. |
| 1492 uint32_t src_size = (uint32_t)(uintptr_t)m_Pos; | 1494 uint32_t src_size = (uint32_t)(uintptr_t)m_Pos; |
| 1493 while (src_size) { | 1495 while (src_size) { |
| 1494 uint32_t block_size = src_size > 4096 ? 4096 : src_size; | 1496 uint32_t block_size = src_size > 4096 ? 4096 : src_size; |
| 1495 if (!pSrcFile->ReadBlock(buffer, m_Offset - src_size, block_size)) { | 1497 if (!pSrcFile->ReadBlock(buffer, m_Offset - src_size, block_size)) { |
| 1496 return -1; | 1498 return -1; |
| 1497 } | 1499 } |
| 1498 if (m_File.AppendBlock(buffer, block_size) < 0) { | 1500 if (m_File.AppendBlock(buffer, block_size) < 0) { |
| 1499 return -1; | 1501 return -1; |
| 1500 } | 1502 } |
| 1501 src_size -= block_size; | 1503 src_size -= block_size; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 return m_iStage = 100; | 1899 return m_iStage = 100; |
| 1898 } | 1900 } |
| 1899 | 1901 |
| 1900 void CPDF_Creator::Clear() { | 1902 void CPDF_Creator::Clear() { |
| 1901 m_pXRefStream.reset(); | 1903 m_pXRefStream.reset(); |
| 1902 m_File.Clear(); | 1904 m_File.Clear(); |
| 1903 m_NewObjNumArray.RemoveAll(); | 1905 m_NewObjNumArray.RemoveAll(); |
| 1904 m_pIDArray.reset(); | 1906 m_pIDArray.reset(); |
| 1905 } | 1907 } |
| 1906 | 1908 |
| 1907 bool CPDF_Creator::Create(IFX_WriteStream* pFile, uint32_t flags) { | 1909 bool CPDF_Creator::Create(const CFX_RetainPtr<IFX_WriteStream>& pFile, |
| 1910 uint32_t flags) { |
| 1908 m_File.AttachFile(pFile); | 1911 m_File.AttachFile(pFile); |
| 1909 return Create(flags); | 1912 return Create(flags); |
| 1910 } | 1913 } |
| 1911 | 1914 |
| 1912 bool CPDF_Creator::Create(uint32_t flags) { | 1915 bool CPDF_Creator::Create(uint32_t flags) { |
| 1913 m_dwFlags = flags; | 1916 m_dwFlags = flags; |
| 1914 m_iStage = 0; | 1917 m_iStage = 0; |
| 1915 m_Offset = 0; | 1918 m_Offset = 0; |
| 1916 m_dwLastObjNum = m_pDocument->GetLastObjNum(); | 1919 m_dwLastObjNum = m_pDocument->GetLastObjNum(); |
| 1917 m_ObjectOffset.Clear(); | 1920 m_ObjectOffset.Clear(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 m_pCryptoHandler = nullptr; | 2012 m_pCryptoHandler = nullptr; |
| 2010 } | 2013 } |
| 2011 void CPDF_Creator::ResetStandardSecurity() { | 2014 void CPDF_Creator::ResetStandardSecurity() { |
| 2012 if (!m_bLocalCryptoHandler) | 2015 if (!m_bLocalCryptoHandler) |
| 2013 return; | 2016 return; |
| 2014 | 2017 |
| 2015 delete m_pCryptoHandler; | 2018 delete m_pCryptoHandler; |
| 2016 m_pCryptoHandler = nullptr; | 2019 m_pCryptoHandler = nullptr; |
| 2017 m_bLocalCryptoHandler = false; | 2020 m_bLocalCryptoHandler = false; |
| 2018 } | 2021 } |
| OLD | NEW |