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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 return -1; | 570 return -1; |
571 } | 571 } |
572 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { | 572 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { |
573 return -1; | 573 return -1; |
574 } | 574 } |
575 if (pFile->AppendString("/Length ") < 0) { | 575 if (pFile->AppendString("/Length ") < 0) { |
576 return -1; | 576 return -1; |
577 } | 577 } |
578 offset += len + 15; | 578 offset += len + 15; |
579 | 579 |
580 if (!pCreator->m_bCompress && !pCreator->m_pCryptoHandler) { | 580 if (!pCreator->m_bCompress && !pCreator->m_pCryptoHandler) { |
Lei Zhang
2016/05/13 06:36:42
This always evals to false.
| |
581 if ((len = pFile->AppendDWord( | 581 if ((len = pFile->AppendDWord( |
582 (uint32_t)(tempBuffer.GetLength() + m_Buffer.GetLength()))) < 0) { | 582 (uint32_t)(tempBuffer.GetLength() + m_Buffer.GetLength()))) < 0) { |
583 return -1; | 583 return -1; |
584 } | 584 } |
585 offset += len; | 585 offset += len; |
586 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 586 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { |
587 return -1; | 587 return -1; |
588 } | 588 } |
589 if (pFile->AppendBlock(tempBuffer.GetBuffer(), tempBuffer.GetLength()) < | 589 if (pFile->AppendBlock(tempBuffer.GetBuffer(), tempBuffer.GetLength()) < |
590 0) { | 590 0) { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 if (bEOF) { | 834 if (bEOF) { |
835 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, | 835 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, |
836 pCreator->m_pIDArray, | 836 pCreator->m_pIDArray, |
837 pCreator->m_bCompress)) < 0) { | 837 pCreator->m_bCompress)) < 0) { |
838 return FALSE; | 838 return FALSE; |
839 } | 839 } |
840 offset += len; | 840 offset += len; |
841 if (pCreator->m_pEncryptDict) { | 841 if (pCreator->m_pEncryptDict) { |
842 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); | 842 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); |
843 if (dwEncryptObjNum == 0) { | 843 if (dwEncryptObjNum == 0) { |
844 dwEncryptObjNum = pCreator->m_dwEnryptObjNum; | 844 dwEncryptObjNum = pCreator->m_dwEncryptObjNum; |
845 } | 845 } |
846 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, | 846 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, |
847 dwEncryptObjNum, pFile)) < 0) { | 847 dwEncryptObjNum, pFile)) < 0) { |
848 return FALSE; | 848 return FALSE; |
849 } | 849 } |
850 offset += len; | 850 offset += len; |
851 } | 851 } |
852 } | 852 } |
853 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 853 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { |
854 return FALSE; | 854 return FALSE; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 if (m_IndexArray.empty()) { | 893 if (m_IndexArray.empty()) { |
894 m_IndexArray.push_back({objnum, 1}); | 894 m_IndexArray.push_back({objnum, 1}); |
895 return; | 895 return; |
896 } | 896 } |
897 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; | 897 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; |
898 if (objnum == next_objnum) | 898 if (objnum == next_objnum) |
899 m_IndexArray.back().count += 1; | 899 m_IndexArray.back().count += 1; |
900 else | 900 else |
901 m_IndexArray.push_back({objnum, 1}); | 901 m_IndexArray.push_back({objnum, 1}); |
902 } | 902 } |
903 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) { | 903 |
904 m_pDocument = pDoc; | 904 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) |
905 m_pParser = (CPDF_Parser*)pDoc->m_pParser; | 905 : m_pDocument(pDoc), |
906 m_bCompress = TRUE; | 906 m_pParser(pDoc->GetParser()), |
907 if (m_pParser) { | 907 m_bCompress(TRUE), |
908 m_pEncryptDict = m_pParser->GetEncryptDict(); | 908 m_bSecurityChanged(FALSE), |
909 m_pCryptoHandler = m_pParser->GetCryptoHandler(); | 909 m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr), |
910 } else { | 910 m_dwEncryptObjNum(0), |
911 m_pEncryptDict = nullptr; | 911 m_pCryptoHandler(m_pParser ? m_pParser->GetCryptoHandler() : nullptr), |
912 m_pCryptoHandler = nullptr; | 912 m_pMetadata(nullptr), |
913 } | 913 m_ObjectStreamSize(200), |
914 m_bSecurityChanged = FALSE; | 914 m_dwLastObjNum(m_pDocument->GetLastObjNum()), |
915 m_pMetadata = nullptr; | 915 m_Offset(0), |
916 m_bEncryptCloned = FALSE; | 916 m_iStage(-1), |
917 m_bEncryptMetadata = FALSE; | 917 m_dwFlags(0), |
Lei Zhang
2016/05/13 06:36:42
I accidentally removed this. It's always false.
Tom Sepez
2016/05/13 20:05:11
Accidentally? Otherwise, agreed its always false.
Lei Zhang
2016/05/14 01:06:33
Accidentally removed in patch set 1. Should have b
| |
918 m_Offset = 0; | 918 m_Pos(nullptr), |
919 m_iStage = -1; | 919 m_XrefStart(0), |
920 m_dwFlags = 0; | 920 m_pIDArray(nullptr), |
921 m_Pos = nullptr; | 921 m_FileVersion(0) {} |
922 m_XrefStart = 0; | 922 |
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() { | 923 CPDF_Creator::~CPDF_Creator() { |
932 ResetStandardSecurity(); | 924 ResetStandardSecurity(); |
933 if (m_bEncryptCloned && m_pEncryptDict) { | 925 if (m_bEncryptCloned && m_pEncryptDict) { |
934 m_pEncryptDict->Release(); | 926 m_pEncryptDict->Release(); |
935 m_pEncryptDict = NULL; | 927 m_pEncryptDict = NULL; |
936 } | 928 } |
937 Clear(); | 929 Clear(); |
938 } | 930 } |
939 | 931 |
940 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 932 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
(...skipping 19 matching lines...) Expand all Loading... | |
960 return 1; | 952 return 1; |
961 if (pDict->IsSignatureDict()) | 953 if (pDict->IsSignatureDict()) |
962 return 1; | 954 return 1; |
963 if (pDict->GetStringBy("Type") == "Page") | 955 if (pDict->GetStringBy("Type") == "Page") |
964 return 1; | 956 return 1; |
965 } | 957 } |
966 | 958 |
967 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 959 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
968 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 960 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
969 return -1; | 961 return -1; |
970 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 962 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) |
971 return 0; | 963 return 0; |
972 if (!m_pXRefStream->End(this)) | 964 if (!m_pXRefStream->End(this)) |
973 return -1; | 965 return -1; |
974 if (!m_pXRefStream->Start()) | 966 if (!m_pXRefStream->Start()) |
975 return -1; | 967 return -1; |
976 return 0; | 968 return 0; |
977 } | 969 } |
978 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, | 970 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, |
979 const uint8_t* pBuffer, | 971 const uint8_t* pBuffer, |
980 uint32_t dwSize) { | 972 uint32_t dwSize) { |
981 if (!m_pXRefStream) { | 973 if (!m_pXRefStream) { |
982 return 1; | 974 return 1; |
983 } | 975 } |
984 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 976 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
985 int32_t iRet = | 977 int32_t iRet = |
986 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); | 978 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); |
987 if (iRet < 1) { | 979 if (iRet < 1) { |
988 return iRet; | 980 return iRet; |
989 } | 981 } |
990 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 982 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) { |
991 return 0; | 983 return 0; |
992 } | 984 } |
993 if (!m_pXRefStream->End(this)) { | 985 if (!m_pXRefStream->End(this)) { |
994 return -1; | 986 return -1; |
995 } | 987 } |
996 if (!m_pXRefStream->Start()) { | 988 if (!m_pXRefStream->Start()) { |
997 return -1; | 989 return -1; |
998 } | 990 } |
999 return 0; | 991 return 0; |
1000 } | 992 } |
1001 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { | 993 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { |
1002 if (!m_pXRefStream) { | 994 if (!m_pXRefStream) { |
1003 return 1; | 995 return 1; |
1004 } | 996 } |
1005 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 997 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
1006 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 998 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) { |
1007 return 0; | 999 return 0; |
1008 } | 1000 } |
1009 if (!m_pXRefStream->End(this)) { | 1001 if (!m_pXRefStream->End(this)) { |
1010 return -1; | 1002 return -1; |
1011 } | 1003 } |
1012 if (!m_pXRefStream->Start()) { | 1004 if (!m_pXRefStream->Start()) { |
1013 return -1; | 1005 return -1; |
1014 } | 1006 } |
1015 return 0; | 1007 return 0; |
1016 } | 1008 } |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1471 if (m_iStage == 0) { | 1463 if (m_iStage == 0) { |
1472 if (!m_pParser) { | 1464 if (!m_pParser) { |
1473 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1465 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1474 } | 1466 } |
1475 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { | 1467 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { |
1476 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1468 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1477 } | 1469 } |
1478 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 1470 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
1479 m_pMetadata = pDict ? pDict->GetDirectObjectBy("Metadata") : NULL; | 1471 m_pMetadata = pDict ? pDict->GetDirectObjectBy("Metadata") : NULL; |
1480 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { | 1472 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { |
1481 m_pXRefStream = new CPDF_XRefStream; | 1473 m_pXRefStream.reset(new CPDF_XRefStream); |
1482 m_pXRefStream->Start(); | 1474 m_pXRefStream->Start(); |
1483 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { | 1475 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { |
1484 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); | 1476 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); |
1485 m_pXRefStream->m_PrevOffset = prev; | 1477 m_pXRefStream->m_PrevOffset = prev; |
1486 } | 1478 } |
1487 } | 1479 } |
1488 m_iStage = 10; | 1480 m_iStage = 10; |
1489 } | 1481 } |
1490 if (m_iStage == 10) { | 1482 if (m_iStage == 10) { |
1491 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { | 1483 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1592 } | 1584 } |
1593 if (m_iStage == 27) { | 1585 if (m_iStage == 27) { |
1594 if (NULL != m_pEncryptDict && 0 == m_pEncryptDict->GetObjNum()) { | 1586 if (NULL != m_pEncryptDict && 0 == m_pEncryptDict->GetObjNum()) { |
1595 m_dwLastObjNum += 1; | 1587 m_dwLastObjNum += 1; |
1596 FX_FILESIZE saveOffset = m_Offset; | 1588 FX_FILESIZE saveOffset = m_Offset; |
1597 if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { | 1589 if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { |
1598 return -1; | 1590 return -1; |
1599 } | 1591 } |
1600 m_ObjectOffset.Add(m_dwLastObjNum, 1); | 1592 m_ObjectOffset.Add(m_dwLastObjNum, 1); |
1601 m_ObjectOffset[m_dwLastObjNum] = saveOffset; | 1593 m_ObjectOffset[m_dwLastObjNum] = saveOffset; |
1602 m_dwEnryptObjNum = m_dwLastObjNum; | 1594 m_dwEncryptObjNum = m_dwLastObjNum; |
1603 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { | 1595 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { |
1604 m_NewObjNumArray.Add(m_dwLastObjNum); | 1596 m_NewObjNumArray.Add(m_dwLastObjNum); |
1605 } | 1597 } |
1606 } | 1598 } |
1607 m_iStage = 80; | 1599 m_iStage = 80; |
1608 } | 1600 } |
1609 return m_iStage; | 1601 return m_iStage; |
1610 } | 1602 } |
1611 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { | 1603 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { |
1612 ASSERT(m_iStage >= 80 || m_iStage < 90); | 1604 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) { | 1914 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) { |
1923 return -1; | 1915 return -1; |
1924 } | 1916 } |
1925 if (m_File.AppendString("\r\n%%EOF\r\n") < 0) { | 1917 if (m_File.AppendString("\r\n%%EOF\r\n") < 0) { |
1926 return -1; | 1918 return -1; |
1927 } | 1919 } |
1928 m_File.Flush(); | 1920 m_File.Flush(); |
1929 return m_iStage = 100; | 1921 return m_iStage = 100; |
1930 } | 1922 } |
1931 void CPDF_Creator::Clear() { | 1923 void CPDF_Creator::Clear() { |
1932 delete m_pXRefStream; | 1924 m_pXRefStream.reset(); |
1933 m_pXRefStream = NULL; | |
1934 m_File.Clear(); | 1925 m_File.Clear(); |
1935 m_NewObjNumArray.RemoveAll(); | 1926 m_NewObjNumArray.RemoveAll(); |
1936 if (m_pIDArray) { | 1927 if (m_pIDArray) { |
1937 m_pIDArray->Release(); | 1928 m_pIDArray->Release(); |
1938 m_pIDArray = NULL; | 1929 m_pIDArray = NULL; |
1939 } | 1930 } |
1940 } | 1931 } |
1941 | 1932 |
1942 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { | 1933 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { |
1943 m_File.AttachFile(pFile); | 1934 m_File.AttachFile(pFile); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2045 m_pCryptoHandler = nullptr; | 2036 m_pCryptoHandler = nullptr; |
2046 } | 2037 } |
2047 void CPDF_Creator::ResetStandardSecurity() { | 2038 void CPDF_Creator::ResetStandardSecurity() { |
2048 if (!m_bLocalCryptoHandler) | 2039 if (!m_bLocalCryptoHandler) |
2049 return; | 2040 return; |
2050 | 2041 |
2051 delete m_pCryptoHandler; | 2042 delete m_pCryptoHandler; |
2052 m_pCryptoHandler = nullptr; | 2043 m_pCryptoHandler = nullptr; |
2053 m_bLocalCryptoHandler = FALSE; | 2044 m_bLocalCryptoHandler = FALSE; |
2054 } | 2045 } |
OLD | NEW |