| 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/fpdf_edit/editint.h" | 7 #include "core/fpdfapi/fpdf_edit/editint.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 default: | 183 default: |
| 184 ASSERT(FALSE); | 184 ASSERT(FALSE); |
| 185 break; | 185 break; |
| 186 } | 186 } |
| 187 return 1; | 187 return 1; |
| 188 } | 188 } |
| 189 | 189 |
| 190 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, | 190 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, |
| 191 CFX_FileBufferArchive* pFile, | 191 CFX_FileBufferArchive* pFile, |
| 192 CPDF_Array* pIDArray, | 192 CPDF_Array* pIDArray) { |
| 193 FX_BOOL bCompress) { | |
| 194 FX_FILESIZE offset = 0; | 193 FX_FILESIZE offset = 0; |
| 195 int32_t len = 0; | 194 int32_t len = 0; |
| 196 ASSERT(pDocument && pFile); | 195 CPDF_Parser* pParser = pDocument->GetParser(); |
| 197 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); | |
| 198 if (pParser) { | 196 if (pParser) { |
| 199 CPDF_Dictionary* p = pParser->GetTrailer(); | 197 CPDF_Dictionary* p = pParser->GetTrailer(); |
| 200 for (const auto& it : *p) { | 198 for (const auto& it : *p) { |
| 201 const CFX_ByteString& key = it.first; | 199 const CFX_ByteString& key = it.first; |
| 202 CPDF_Object* pValue = it.second; | 200 CPDF_Object* pValue = it.second; |
| 203 if (key == "Encrypt" || key == "Size" || key == "Filter" || | 201 if (key == "Encrypt" || key == "Size" || key == "Filter" || |
| 204 key == "Index" || key == "Length" || key == "Prev" || key == "W" || | 202 key == "Index" || key == "Length" || key == "Prev" || key == "W" || |
| 205 key == "XRefStm" || key == "Type" || key == "ID") { | 203 key == "XRefStm" || key == "Type" || key == "ID") { |
| 206 continue; | 204 continue; |
| 207 } | 205 } |
| 208 if (bCompress && key == "DecodeParms") { | 206 if (key == "DecodeParms") |
| 209 continue; | 207 continue; |
| 210 } | 208 |
| 211 if (pFile->AppendString(("/")) < 0) { | 209 if (pFile->AppendString(("/")) < 0) { |
| 212 return -1; | 210 return -1; |
| 213 } | 211 } |
| 214 if ((len = pFile->AppendString(PDF_NameEncode(key).AsStringC())) < 0) { | 212 if ((len = pFile->AppendString(PDF_NameEncode(key).AsStringC())) < 0) { |
| 215 return -1; | 213 return -1; |
| 216 } | 214 } |
| 217 offset += len + 1; | 215 offset += len + 1; |
| 218 if (pValue->GetObjNum()) { | 216 if (pValue->GetObjNum()) { |
| 219 if (pFile->AppendString(" ") < 0) { | 217 if (pFile->AppendString(" ") < 0) { |
| 220 return -1; | 218 return -1; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 return -1; | 568 return -1; |
| 571 } | 569 } |
| 572 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { | 570 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { |
| 573 return -1; | 571 return -1; |
| 574 } | 572 } |
| 575 if (pFile->AppendString("/Length ") < 0) { | 573 if (pFile->AppendString("/Length ") < 0) { |
| 576 return -1; | 574 return -1; |
| 577 } | 575 } |
| 578 offset += len + 15; | 576 offset += len + 15; |
| 579 | 577 |
| 580 if (!pCreator->m_bCompress && !pCreator->m_pCryptoHandler) { | 578 tempBuffer << m_Buffer; |
| 581 if ((len = pFile->AppendDWord( | 579 CPDF_FlateEncoder encoder(tempBuffer.GetBuffer(), tempBuffer.GetLength(), |
| 582 (uint32_t)(tempBuffer.GetLength() + m_Buffer.GetLength()))) < 0) { | 580 TRUE); |
| 583 return -1; | 581 CPDF_Encryptor encryptor(pCreator->m_pCryptoHandler, m_dwObjNum, |
| 584 } | 582 encoder.m_pData, encoder.m_dwSize); |
| 585 offset += len; | 583 if ((len = pFile->AppendDWord(encryptor.m_dwSize)) < 0) { |
| 586 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 584 return -1; |
| 587 return -1; | |
| 588 } | |
| 589 if (pFile->AppendBlock(tempBuffer.GetBuffer(), tempBuffer.GetLength()) < | |
| 590 0) { | |
| 591 return -1; | |
| 592 } | |
| 593 if (pFile->AppendBlock(m_Buffer.GetBuffer(), m_Buffer.GetLength()) < 0) { | |
| 594 return -1; | |
| 595 } | |
| 596 offset += len + tempBuffer.GetLength() + m_Buffer.GetLength(); | |
| 597 } else { | |
| 598 tempBuffer << m_Buffer; | |
| 599 CPDF_FlateEncoder encoder(tempBuffer.GetBuffer(), tempBuffer.GetLength(), | |
| 600 pCreator->m_bCompress); | |
| 601 CPDF_Encryptor encryptor(pCreator->m_pCryptoHandler, m_dwObjNum, | |
| 602 encoder.m_pData, encoder.m_dwSize); | |
| 603 if ((len = pFile->AppendDWord(encryptor.m_dwSize)) < 0) { | |
| 604 return -1; | |
| 605 } | |
| 606 offset += len; | |
| 607 if (pCreator->m_bCompress) { | |
| 608 if (pFile->AppendString("/Filter /FlateDecode") < 0) { | |
| 609 return -1; | |
| 610 } | |
| 611 offset += 20; | |
| 612 } | |
| 613 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | |
| 614 return -1; | |
| 615 } | |
| 616 if (pFile->AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { | |
| 617 return -1; | |
| 618 } | |
| 619 offset += len + encryptor.m_dwSize; | |
| 620 } | 585 } |
| 586 offset += len; |
| 587 if (pFile->AppendString("/Filter /FlateDecode") < 0) { |
| 588 return -1; |
| 589 } |
| 590 offset += 20; |
| 591 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { |
| 592 return -1; |
| 593 } |
| 594 if (pFile->AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { |
| 595 return -1; |
| 596 } |
| 597 offset += len + encryptor.m_dwSize; |
| 621 if ((len = pFile->AppendString("\r\nendstream\r\nendobj\r\n")) < 0) { | 598 if ((len = pFile->AppendString("\r\nendstream\r\nendobj\r\n")) < 0) { |
| 622 return -1; | 599 return -1; |
| 623 } | 600 } |
| 624 offset += len; | 601 offset += len; |
| 625 return ObjOffset; | 602 return ObjOffset; |
| 626 } | 603 } |
| 627 CPDF_XRefStream::CPDF_XRefStream() | 604 CPDF_XRefStream::CPDF_XRefStream() |
| 628 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} | 605 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} |
| 629 FX_BOOL CPDF_XRefStream::Start() { | 606 FX_BOOL CPDF_XRefStream::Start() { |
| 630 m_IndexArray.clear(); | 607 m_IndexArray.clear(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 FX_CHAR offset_buf[20]; | 779 FX_CHAR offset_buf[20]; |
| 803 FXSYS_memset(offset_buf, 0, sizeof(offset_buf)); | 780 FXSYS_memset(offset_buf, 0, sizeof(offset_buf)); |
| 804 FXSYS_i64toa(m_PrevOffset, offset_buf, 10); | 781 FXSYS_i64toa(m_PrevOffset, offset_buf, 10); |
| 805 int32_t len = (int32_t)FXSYS_strlen(offset_buf); | 782 int32_t len = (int32_t)FXSYS_strlen(offset_buf); |
| 806 if (pFile->AppendBlock(offset_buf, len) < 0) { | 783 if (pFile->AppendBlock(offset_buf, len) < 0) { |
| 807 return FALSE; | 784 return FALSE; |
| 808 } | 785 } |
| 809 offset += len + 6; | 786 offset += len + 6; |
| 810 } | 787 } |
| 811 FX_BOOL bPredictor = TRUE; | 788 FX_BOOL bPredictor = TRUE; |
| 812 CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), | 789 CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), TRUE, |
| 813 pCreator->m_bCompress, bPredictor); | 790 bPredictor); |
| 814 if (pCreator->m_bCompress) { | 791 if (pFile->AppendString("/Filter /FlateDecode") < 0) { |
| 815 if (pFile->AppendString("/Filter /FlateDecode") < 0) { | 792 return FALSE; |
| 793 } |
| 794 offset += 20; |
| 795 if (bPredictor) { |
| 796 if ((len = pFile->AppendString("/DecodeParms<</Columns 7/Predictor 12>>")) < |
| 797 0) { |
| 816 return FALSE; | 798 return FALSE; |
| 817 } | 799 } |
| 818 offset += 20; | 800 offset += len; |
| 819 if (bPredictor) { | |
| 820 if ((len = pFile->AppendString( | |
| 821 "/DecodeParms<</Columns 7/Predictor 12>>")) < 0) { | |
| 822 return FALSE; | |
| 823 } | |
| 824 offset += len; | |
| 825 } | |
| 826 } | 801 } |
| 827 if (pFile->AppendString("/Length ") < 0) { | 802 if (pFile->AppendString("/Length ") < 0) { |
| 828 return FALSE; | 803 return FALSE; |
| 829 } | 804 } |
| 830 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0) { | 805 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0) { |
| 831 return FALSE; | 806 return FALSE; |
| 832 } | 807 } |
| 833 offset += len + 8; | 808 offset += len + 8; |
| 834 if (bEOF) { | 809 if (bEOF) { |
| 835 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, | 810 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, |
| 836 pCreator->m_pIDArray, | 811 pCreator->m_pIDArray)) < 0) { |
| 837 pCreator->m_bCompress)) < 0) { | |
| 838 return FALSE; | 812 return FALSE; |
| 839 } | 813 } |
| 840 offset += len; | 814 offset += len; |
| 841 if (pCreator->m_pEncryptDict) { | 815 if (pCreator->m_pEncryptDict) { |
| 842 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); | 816 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); |
| 843 if (dwEncryptObjNum == 0) { | 817 if (dwEncryptObjNum == 0) { |
| 844 dwEncryptObjNum = pCreator->m_dwEnryptObjNum; | 818 dwEncryptObjNum = pCreator->m_dwEncryptObjNum; |
| 845 } | 819 } |
| 846 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, | 820 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, |
| 847 dwEncryptObjNum, pFile)) < 0) { | 821 dwEncryptObjNum, pFile)) < 0) { |
| 848 return FALSE; | 822 return FALSE; |
| 849 } | 823 } |
| 850 offset += len; | 824 offset += len; |
| 851 } | 825 } |
| 852 } | 826 } |
| 853 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 827 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { |
| 854 return FALSE; | 828 return FALSE; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 if (m_IndexArray.empty()) { | 867 if (m_IndexArray.empty()) { |
| 894 m_IndexArray.push_back({objnum, 1}); | 868 m_IndexArray.push_back({objnum, 1}); |
| 895 return; | 869 return; |
| 896 } | 870 } |
| 897 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; | 871 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; |
| 898 if (objnum == next_objnum) | 872 if (objnum == next_objnum) |
| 899 m_IndexArray.back().count += 1; | 873 m_IndexArray.back().count += 1; |
| 900 else | 874 else |
| 901 m_IndexArray.push_back({objnum, 1}); | 875 m_IndexArray.push_back({objnum, 1}); |
| 902 } | 876 } |
| 903 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) { | 877 |
| 904 m_pDocument = pDoc; | 878 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) |
| 905 m_pParser = (CPDF_Parser*)pDoc->m_pParser; | 879 : m_pDocument(pDoc), |
| 906 m_bCompress = TRUE; | 880 m_pParser(pDoc->GetParser()), |
| 907 if (m_pParser) { | 881 m_bSecurityChanged(FALSE), |
| 908 m_pEncryptDict = m_pParser->GetEncryptDict(); | 882 m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr), |
| 909 m_pCryptoHandler = m_pParser->GetCryptoHandler(); | 883 m_dwEncryptObjNum(0), |
| 910 } else { | 884 m_pCryptoHandler(m_pParser ? m_pParser->GetCryptoHandler() : nullptr), |
| 911 m_pEncryptDict = nullptr; | 885 m_pMetadata(nullptr), |
| 912 m_pCryptoHandler = nullptr; | 886 m_ObjectStreamSize(200), |
| 913 } | 887 m_dwLastObjNum(m_pDocument->GetLastObjNum()), |
| 914 m_bSecurityChanged = FALSE; | 888 m_Offset(0), |
| 915 m_pMetadata = nullptr; | 889 m_iStage(-1), |
| 916 m_bEncryptCloned = FALSE; | 890 m_dwFlags(0), |
| 917 m_bEncryptMetadata = FALSE; | 891 m_Pos(nullptr), |
| 918 m_Offset = 0; | 892 m_XrefStart(0), |
| 919 m_iStage = -1; | 893 m_pIDArray(nullptr), |
| 920 m_dwFlags = 0; | 894 m_FileVersion(0) {} |
| 921 m_Pos = nullptr; | 895 |
| 922 m_XrefStart = 0; | |
| 923 m_pXRefStream = nullptr; | |
| 924 m_ObjectStreamSize = 200; | |
| 925 m_dwLastObjNum = m_pDocument->GetLastObjNum(); | |
| 926 m_pIDArray = nullptr; | |
| 927 m_FileVersion = 0; | |
| 928 m_dwEnryptObjNum = 0; | |
| 929 m_bLocalCryptoHandler = FALSE; | |
| 930 } | |
| 931 CPDF_Creator::~CPDF_Creator() { | 896 CPDF_Creator::~CPDF_Creator() { |
| 932 ResetStandardSecurity(); | 897 ResetStandardSecurity(); |
| 933 if (m_bEncryptCloned && m_pEncryptDict) { | 898 if (m_bEncryptCloned && m_pEncryptDict) { |
| 934 m_pEncryptDict->Release(); | 899 m_pEncryptDict->Release(); |
| 935 m_pEncryptDict = NULL; | 900 m_pEncryptDict = NULL; |
| 936 } | 901 } |
| 937 Clear(); | 902 Clear(); |
| 938 } | 903 } |
| 939 | 904 |
| 940 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 905 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 960 return 1; | 925 return 1; |
| 961 if (pDict->IsSignatureDict()) | 926 if (pDict->IsSignatureDict()) |
| 962 return 1; | 927 return 1; |
| 963 if (pDict->GetStringBy("Type") == "Page") | 928 if (pDict->GetStringBy("Type") == "Page") |
| 964 return 1; | 929 return 1; |
| 965 } | 930 } |
| 966 | 931 |
| 967 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 932 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 968 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 933 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
| 969 return -1; | 934 return -1; |
| 970 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 935 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) |
| 971 return 0; | 936 return 0; |
| 972 if (!m_pXRefStream->End(this)) | 937 if (!m_pXRefStream->End(this)) |
| 973 return -1; | 938 return -1; |
| 974 if (!m_pXRefStream->Start()) | 939 if (!m_pXRefStream->Start()) |
| 975 return -1; | 940 return -1; |
| 976 return 0; | 941 return 0; |
| 977 } | 942 } |
| 978 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, | 943 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, |
| 979 const uint8_t* pBuffer, | 944 const uint8_t* pBuffer, |
| 980 uint32_t dwSize) { | 945 uint32_t dwSize) { |
| 981 if (!m_pXRefStream) { | 946 if (!m_pXRefStream) { |
| 982 return 1; | 947 return 1; |
| 983 } | 948 } |
| 984 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 949 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 985 int32_t iRet = | 950 int32_t iRet = |
| 986 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); | 951 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); |
| 987 if (iRet < 1) { | 952 if (iRet < 1) { |
| 988 return iRet; | 953 return iRet; |
| 989 } | 954 } |
| 990 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 955 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) { |
| 991 return 0; | 956 return 0; |
| 992 } | 957 } |
| 993 if (!m_pXRefStream->End(this)) { | 958 if (!m_pXRefStream->End(this)) { |
| 994 return -1; | 959 return -1; |
| 995 } | 960 } |
| 996 if (!m_pXRefStream->Start()) { | 961 if (!m_pXRefStream->Start()) { |
| 997 return -1; | 962 return -1; |
| 998 } | 963 } |
| 999 return 0; | 964 return 0; |
| 1000 } | 965 } |
| 1001 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { | 966 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { |
| 1002 if (!m_pXRefStream) { | 967 if (!m_pXRefStream) { |
| 1003 return 1; | 968 return 1; |
| 1004 } | 969 } |
| 1005 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 970 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 1006 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 971 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) { |
| 1007 return 0; | 972 return 0; |
| 1008 } | 973 } |
| 1009 if (!m_pXRefStream->End(this)) { | 974 if (!m_pXRefStream->End(this)) { |
| 1010 return -1; | 975 return -1; |
| 1011 } | 976 } |
| 1012 if (!m_pXRefStream->Start()) { | 977 if (!m_pXRefStream->Start()) { |
| 1013 return -1; | 978 return -1; |
| 1014 } | 979 } |
| 1015 return 0; | 980 return 0; |
| 1016 } | 981 } |
| 1017 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, | 982 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, |
| 1018 uint32_t objnum, | 983 uint32_t objnum, |
| 1019 CPDF_CryptoHandler* pCrypto) { | 984 CPDF_CryptoHandler* pCrypto) { |
| 1020 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pStream->AsStream()), | 985 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pStream->AsStream()), |
| 1021 pStream == m_pMetadata ? FALSE : m_bCompress); | 986 pStream != m_pMetadata); |
| 1022 CPDF_Encryptor encryptor(pCrypto, objnum, encoder.m_pData, encoder.m_dwSize); | 987 CPDF_Encryptor encryptor(pCrypto, objnum, encoder.m_pData, encoder.m_dwSize); |
| 1023 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { | 988 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { |
| 1024 encoder.CloneDict(); | 989 encoder.CloneDict(); |
| 1025 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 990 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
| 1026 } | 991 } |
| 1027 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 992 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
| 1028 return -1; | 993 return -1; |
| 1029 } | 994 } |
| 1030 int len = m_File.AppendString("stream\r\n"); | 995 int len = m_File.AppendString("stream\r\n"); |
| 1031 if (len < 0) { | 996 if (len < 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1047 int32_t len = m_File.AppendDWord(objnum); | 1012 int32_t len = m_File.AppendDWord(objnum); |
| 1048 if (len < 0) | 1013 if (len < 0) |
| 1049 return -1; | 1014 return -1; |
| 1050 | 1015 |
| 1051 m_Offset += len; | 1016 m_Offset += len; |
| 1052 if ((len = m_File.AppendString(" 0 obj\r\n")) < 0) | 1017 if ((len = m_File.AppendString(" 0 obj\r\n")) < 0) |
| 1053 return -1; | 1018 return -1; |
| 1054 | 1019 |
| 1055 m_Offset += len; | 1020 m_Offset += len; |
| 1056 if (pObj->IsStream()) { | 1021 if (pObj->IsStream()) { |
| 1057 CPDF_CryptoHandler* pHandler = (pObj == m_pMetadata && !m_bEncryptMetadata) | 1022 CPDF_CryptoHandler* pHandler = |
| 1058 ? nullptr | 1023 pObj != m_pMetadata ? m_pCryptoHandler : nullptr; |
| 1059 : m_pCryptoHandler; | |
| 1060 if (WriteStream(pObj, objnum, pHandler) < 0) | 1024 if (WriteStream(pObj, objnum, pHandler) < 0) |
| 1061 return -1; | 1025 return -1; |
| 1062 } else { | 1026 } else { |
| 1063 if (WriteDirectObj(objnum, pObj) < 0) | 1027 if (WriteDirectObj(objnum, pObj) < 0) |
| 1064 return -1; | 1028 return -1; |
| 1065 } | 1029 } |
| 1066 if ((len = m_File.AppendString("\r\nendobj\r\n")) < 0) | 1030 if ((len = m_File.AppendString("\r\nendobj\r\n")) < 0) |
| 1067 return -1; | 1031 return -1; |
| 1068 | 1032 |
| 1069 m_Offset += len; | 1033 m_Offset += len; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), | 1087 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), |
| 1124 bHex); | 1088 bHex); |
| 1125 if ((len = m_File.AppendString(content.AsStringC())) < 0) { | 1089 if ((len = m_File.AppendString(content.AsStringC())) < 0) { |
| 1126 return -1; | 1090 return -1; |
| 1127 } | 1091 } |
| 1128 m_Offset += len; | 1092 m_Offset += len; |
| 1129 break; | 1093 break; |
| 1130 } | 1094 } |
| 1131 case CPDF_Object::STREAM: { | 1095 case CPDF_Object::STREAM: { |
| 1132 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()), | 1096 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()), |
| 1133 m_bCompress); | 1097 TRUE); |
| 1134 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData, | 1098 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData, |
| 1135 encoder.m_dwSize); | 1099 encoder.m_dwSize); |
| 1136 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != | 1100 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != |
| 1137 encryptor.m_dwSize) { | 1101 encryptor.m_dwSize) { |
| 1138 encoder.CloneDict(); | 1102 encoder.CloneDict(); |
| 1139 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1103 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
| 1140 } | 1104 } |
| 1141 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1105 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
| 1142 return -1; | 1106 return -1; |
| 1143 } | 1107 } |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 if (m_iStage == 0) { | 1435 if (m_iStage == 0) { |
| 1472 if (!m_pParser) { | 1436 if (!m_pParser) { |
| 1473 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1437 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
| 1474 } | 1438 } |
| 1475 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { | 1439 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { |
| 1476 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1440 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
| 1477 } | 1441 } |
| 1478 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 1442 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
| 1479 m_pMetadata = pDict ? pDict->GetDirectObjectBy("Metadata") : NULL; | 1443 m_pMetadata = pDict ? pDict->GetDirectObjectBy("Metadata") : NULL; |
| 1480 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { | 1444 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { |
| 1481 m_pXRefStream = new CPDF_XRefStream; | 1445 m_pXRefStream.reset(new CPDF_XRefStream); |
| 1482 m_pXRefStream->Start(); | 1446 m_pXRefStream->Start(); |
| 1483 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { | 1447 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { |
| 1484 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); | 1448 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); |
| 1485 m_pXRefStream->m_PrevOffset = prev; | 1449 m_pXRefStream->m_PrevOffset = prev; |
| 1486 } | 1450 } |
| 1487 } | 1451 } |
| 1488 m_iStage = 10; | 1452 m_iStage = 10; |
| 1489 } | 1453 } |
| 1490 if (m_iStage == 10) { | 1454 if (m_iStage == 10) { |
| 1491 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { | 1455 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 } | 1556 } |
| 1593 if (m_iStage == 27) { | 1557 if (m_iStage == 27) { |
| 1594 if (NULL != m_pEncryptDict && 0 == m_pEncryptDict->GetObjNum()) { | 1558 if (NULL != m_pEncryptDict && 0 == m_pEncryptDict->GetObjNum()) { |
| 1595 m_dwLastObjNum += 1; | 1559 m_dwLastObjNum += 1; |
| 1596 FX_FILESIZE saveOffset = m_Offset; | 1560 FX_FILESIZE saveOffset = m_Offset; |
| 1597 if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { | 1561 if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { |
| 1598 return -1; | 1562 return -1; |
| 1599 } | 1563 } |
| 1600 m_ObjectOffset.Add(m_dwLastObjNum, 1); | 1564 m_ObjectOffset.Add(m_dwLastObjNum, 1); |
| 1601 m_ObjectOffset[m_dwLastObjNum] = saveOffset; | 1565 m_ObjectOffset[m_dwLastObjNum] = saveOffset; |
| 1602 m_dwEnryptObjNum = m_dwLastObjNum; | 1566 m_dwEncryptObjNum = m_dwLastObjNum; |
| 1603 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { | 1567 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { |
| 1604 m_NewObjNumArray.Add(m_dwLastObjNum); | 1568 m_NewObjNumArray.Add(m_dwLastObjNum); |
| 1605 } | 1569 } |
| 1606 } | 1570 } |
| 1607 m_iStage = 80; | 1571 m_iStage = 80; |
| 1608 } | 1572 } |
| 1609 return m_iStage; | 1573 return m_iStage; |
| 1610 } | 1574 } |
| 1611 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { | 1575 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { |
| 1612 ASSERT(m_iStage >= 80 || m_iStage < 90); | 1576 ASSERT(m_iStage >= 80 || m_iStage < 90); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) { | 1886 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) { |
| 1923 return -1; | 1887 return -1; |
| 1924 } | 1888 } |
| 1925 if (m_File.AppendString("\r\n%%EOF\r\n") < 0) { | 1889 if (m_File.AppendString("\r\n%%EOF\r\n") < 0) { |
| 1926 return -1; | 1890 return -1; |
| 1927 } | 1891 } |
| 1928 m_File.Flush(); | 1892 m_File.Flush(); |
| 1929 return m_iStage = 100; | 1893 return m_iStage = 100; |
| 1930 } | 1894 } |
| 1931 void CPDF_Creator::Clear() { | 1895 void CPDF_Creator::Clear() { |
| 1932 delete m_pXRefStream; | 1896 m_pXRefStream.reset(); |
| 1933 m_pXRefStream = NULL; | |
| 1934 m_File.Clear(); | 1897 m_File.Clear(); |
| 1935 m_NewObjNumArray.RemoveAll(); | 1898 m_NewObjNumArray.RemoveAll(); |
| 1936 if (m_pIDArray) { | 1899 if (m_pIDArray) { |
| 1937 m_pIDArray->Release(); | 1900 m_pIDArray->Release(); |
| 1938 m_pIDArray = NULL; | 1901 m_pIDArray = NULL; |
| 1939 } | 1902 } |
| 1940 } | 1903 } |
| 1941 | 1904 |
| 1942 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { | 1905 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { |
| 1943 m_File.AttachFile(pFile); | 1906 m_File.AttachFile(pFile); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 m_pCryptoHandler = nullptr; | 2008 m_pCryptoHandler = nullptr; |
| 2046 } | 2009 } |
| 2047 void CPDF_Creator::ResetStandardSecurity() { | 2010 void CPDF_Creator::ResetStandardSecurity() { |
| 2048 if (!m_bLocalCryptoHandler) | 2011 if (!m_bLocalCryptoHandler) |
| 2049 return; | 2012 return; |
| 2050 | 2013 |
| 2051 delete m_pCryptoHandler; | 2014 delete m_pCryptoHandler; |
| 2052 m_pCryptoHandler = nullptr; | 2015 m_pCryptoHandler = nullptr; |
| 2053 m_bLocalCryptoHandler = FALSE; | 2016 m_bLocalCryptoHandler = FALSE; |
| 2054 } | 2017 } |
| OLD | NEW |