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/fpdfapi/fpdf_serial.h" | 7 #include "../../../include/fpdfapi/fpdf_serial.h" |
8 #include "editint.h" | 8 #include "editint.h" |
9 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) | 9 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) |
10 #define PDF_XREFSTREAM_MAXSIZE 10000 | 10 #define PDF_XREFSTREAM_MAXSIZE 10000 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 void CPDF_FlateEncoder::CloneDict() | 327 void CPDF_FlateEncoder::CloneDict() |
328 { | 328 { |
329 if (!m_bCloned) { | 329 if (!m_bCloned) { |
330 m_pDict = (CPDF_Dictionary*)m_pDict->Clone(); | 330 m_pDict = (CPDF_Dictionary*)m_pDict->Clone(); |
331 m_bCloned = TRUE; | 331 m_bCloned = TRUE; |
332 } | 332 } |
333 } | 333 } |
334 FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode
) | 334 FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode
) |
335 { | 335 { |
336 m_Acc.LoadAllData(pStream, TRUE); | 336 m_Acc.LoadAllData(pStream, TRUE); |
337 if (pStream->GetDict()->KeyExist("Filter") || !bFlateEncode) { | 337 if ((pStream && pStream->GetDict() && pStream->GetDict()->KeyExist("Filter")
) || !bFlateEncode) { |
338 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { | 338 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { |
339 CPDF_StreamAcc destAcc; | 339 CPDF_StreamAcc destAcc; |
340 destAcc.LoadAllData(pStream); | 340 destAcc.LoadAllData(pStream); |
341 m_dwSize = destAcc.GetSize(); | 341 m_dwSize = destAcc.GetSize(); |
342 m_pData = (FX_LPBYTE)destAcc.DetachData(); | 342 m_pData = (FX_LPBYTE)destAcc.DetachData(); |
343 m_pDict = (CPDF_Dictionary*)pStream->GetDict()->Clone(); | 343 m_pDict = (CPDF_Dictionary*)pStream->GetDict()->Clone(); |
344 m_pDict->RemoveAt(FX_BSTRC("Filter")); | 344 m_pDict->RemoveAt(FX_BSTRC("Filter")); |
345 m_bNewData = TRUE; | 345 m_bNewData = TRUE; |
346 m_bCloned = TRUE; | 346 m_bCloned = TRUE; |
347 } else { | 347 } else { |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 FX_INT32 CPDF_Creator::WriteDoc_Stage1(IFX_Pause *pPause) | 1475 FX_INT32 CPDF_Creator::WriteDoc_Stage1(IFX_Pause *pPause) |
1476 { | 1476 { |
1477 FXSYS_assert(m_iStage > -1 || m_iStage < 20); | 1477 FXSYS_assert(m_iStage > -1 || m_iStage < 20); |
1478 if (m_iStage == 0) { | 1478 if (m_iStage == 0) { |
1479 if (m_pParser == NULL) { | 1479 if (m_pParser == NULL) { |
1480 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1480 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1481 } | 1481 } |
1482 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { | 1482 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { |
1483 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1483 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1484 } | 1484 } |
1485 m_pMetadata = m_pDocument->GetRoot()->GetElementValue(FX_BSTRC("Metadata
")); | 1485 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
| 1486 m_pMetadata = pDict ? pDict->GetElementValue(FX_BSTRC("Metadata")) : NUL
L; |
1486 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { | 1487 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { |
1487 m_pXRefStream = FX_NEW CPDF_XRefStream; | 1488 m_pXRefStream = FX_NEW CPDF_XRefStream; |
1488 m_pXRefStream->Start(); | 1489 m_pXRefStream->Start(); |
1489 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { | 1490 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { |
1490 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); | 1491 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); |
1491 m_pXRefStream->m_PrevOffset = prev; | 1492 m_pXRefStream->m_PrevOffset = prev; |
1492 } | 1493 } |
1493 } | 1494 } |
1494 m_iStage = 10; | 1495 m_iStage = 10; |
1495 } | 1496 } |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 } | 2026 } |
2026 return Continue(NULL) > -1; | 2027 return Continue(NULL) > -1; |
2027 } | 2028 } |
2028 void CPDF_Creator::InitID(FX_BOOL bDefault ) | 2029 void CPDF_Creator::InitID(FX_BOOL bDefault ) |
2029 { | 2030 { |
2030 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; | 2031 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; |
2031 FX_BOOL bNewId = !m_pIDArray; | 2032 FX_BOOL bNewId = !m_pIDArray; |
2032 if (!m_pIDArray) { | 2033 if (!m_pIDArray) { |
2033 FX_LPDWORD pBuffer = NULL; | 2034 FX_LPDWORD pBuffer = NULL; |
2034 m_pIDArray = CPDF_Array::Create(); | 2035 m_pIDArray = CPDF_Array::Create(); |
2035 CPDF_Object* pID1 = pOldIDArray->GetElement(0); | 2036 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; |
2036 if (pID1) { | 2037 if (pID1) { |
2037 m_pIDArray->Add(pID1->Clone()); | 2038 m_pIDArray->Add(pID1->Clone()); |
2038 } else { | 2039 } else { |
2039 pBuffer = FX_Alloc(FX_DWORD, 4); | 2040 pBuffer = FX_Alloc(FX_DWORD, 4); |
2040 PDF_GenerateFileID((FX_DWORD)(FX_UINTPTR)this, m_dwLastObjNum, pBuff
er); | 2041 PDF_GenerateFileID((FX_DWORD)(FX_UINTPTR)this, m_dwLastObjNum, pBuff
er); |
2041 CFX_ByteStringC bsBuffer((FX_LPCBYTE)pBuffer, 4 * sizeof(FX_DWORD)); | 2042 CFX_ByteStringC bsBuffer((FX_LPCBYTE)pBuffer, 4 * sizeof(FX_DWORD)); |
2042 m_pIDArray->Add(CPDF_String::Create(bsBuffer, TRUE), m_pDocument); | 2043 m_pIDArray->Add(CPDF_String::Create(bsBuffer, TRUE), m_pDocument); |
2043 } | 2044 } |
2044 if (pBuffer) { | 2045 if (pBuffer) { |
2045 FX_Free(pBuffer); | 2046 FX_Free(pBuffer); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2129 m_bNewCrypto = FALSE; | 2130 m_bNewCrypto = FALSE; |
2130 if (!m_bStandardSecurity) { | 2131 if (!m_bStandardSecurity) { |
2131 return; | 2132 return; |
2132 } | 2133 } |
2133 if (m_pEncryptDict) { | 2134 if (m_pEncryptDict) { |
2134 m_pEncryptDict->Release(); | 2135 m_pEncryptDict->Release(); |
2135 m_pEncryptDict = NULL; | 2136 m_pEncryptDict = NULL; |
2136 } | 2137 } |
2137 m_bStandardSecurity = FALSE; | 2138 m_bStandardSecurity = FALSE; |
2138 } | 2139 } |
OLD | NEW |