| 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_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
| 8 #include "../../../include/fxcrt/fx_string.h" | 8 #include "../../../include/fxcrt/fx_string.h" |
| 9 | 9 |
| 10 // static | 10 // static |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 821 } |
| 822 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) | 822 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) |
| 823 : CPDF_Object(PDFOBJ_STREAM) { | 823 : CPDF_Object(PDFOBJ_STREAM) { |
| 824 m_pDict = pDict; | 824 m_pDict = pDict; |
| 825 m_dwSize = size; | 825 m_dwSize = size; |
| 826 m_GenNum = (FX_DWORD)-1; | 826 m_GenNum = (FX_DWORD)-1; |
| 827 m_pDataBuf = pData; | 827 m_pDataBuf = pData; |
| 828 m_pCryptoHandler = NULL; | 828 m_pCryptoHandler = NULL; |
| 829 } | 829 } |
| 830 CPDF_Stream::~CPDF_Stream() { | 830 CPDF_Stream::~CPDF_Stream() { |
| 831 if (m_GenNum == (FX_DWORD)-1 && m_pDataBuf != NULL) { | 831 if (m_GenNum == (FX_DWORD)-1) { |
| 832 FX_Free(m_pDataBuf); | 832 FX_Free(m_pDataBuf); |
| 833 } | 833 } |
| 834 if (m_pDict) { | 834 if (m_pDict) { |
| 835 m_pDict->Release(); | 835 m_pDict->Release(); |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 void CPDF_Stream::InitStream(CPDF_Dictionary* pDict) { | 838 void CPDF_Stream::InitStream(CPDF_Dictionary* pDict) { |
| 839 if (pDict) { | 839 if (pDict) { |
| 840 if (m_pDict) { | 840 if (m_pDict) { |
| 841 m_pDict->Release(); | 841 m_pDict->Release(); |
| 842 } | 842 } |
| 843 m_pDict = pDict; | 843 m_pDict = pDict; |
| 844 } | 844 } |
| 845 if (m_GenNum == (FX_DWORD)-1) { | 845 if (m_GenNum == (FX_DWORD)-1) { |
| 846 if (m_pDataBuf) { | |
| 847 FX_Free(m_pDataBuf); | 846 FX_Free(m_pDataBuf); |
| 848 } | |
| 849 } | 847 } |
| 850 m_GenNum = 0; | 848 m_GenNum = 0; |
| 851 m_pFile = NULL; | 849 m_pFile = NULL; |
| 852 m_pCryptoHandler = NULL; | 850 m_pCryptoHandler = NULL; |
| 853 m_FileOffset = 0; | 851 m_FileOffset = 0; |
| 854 } | 852 } |
| 855 void CPDF_Stream::InitStream(uint8_t* pData, | 853 void CPDF_Stream::InitStream(uint8_t* pData, |
| 856 FX_DWORD size, | 854 FX_DWORD size, |
| 857 CPDF_Dictionary* pDict) { | 855 CPDF_Dictionary* pDict) { |
| 858 InitStream(pDict); | 856 InitStream(pDict); |
| 859 m_GenNum = (FX_DWORD)-1; | 857 m_GenNum = (FX_DWORD)-1; |
| 860 m_pDataBuf = FX_Alloc(uint8_t, size); | 858 m_pDataBuf = FX_Alloc(uint8_t, size); |
| 861 if (pData) { | 859 if (pData) { |
| 862 FXSYS_memcpy(m_pDataBuf, pData, size); | 860 FXSYS_memcpy(m_pDataBuf, pData, size); |
| 863 } | 861 } |
| 864 m_dwSize = size; | 862 m_dwSize = size; |
| 865 if (m_pDict) { | 863 if (m_pDict) { |
| 866 m_pDict->SetAtInteger(FX_BSTRC("Length"), size); | 864 m_pDict->SetAtInteger(FX_BSTRC("Length"), size); |
| 867 } | 865 } |
| 868 } | 866 } |
| 869 void CPDF_Stream::SetData(const uint8_t* pData, | 867 void CPDF_Stream::SetData(const uint8_t* pData, |
| 870 FX_DWORD size, | 868 FX_DWORD size, |
| 871 FX_BOOL bCompressed, | 869 FX_BOOL bCompressed, |
| 872 FX_BOOL bKeepBuf) { | 870 FX_BOOL bKeepBuf) { |
| 873 if (m_GenNum == (FX_DWORD)-1) { | 871 if (m_GenNum == (FX_DWORD)-1) { |
| 874 if (m_pDataBuf) { | |
| 875 FX_Free(m_pDataBuf); | 872 FX_Free(m_pDataBuf); |
| 876 } | |
| 877 } else { | 873 } else { |
| 878 m_GenNum = (FX_DWORD)-1; | 874 m_GenNum = (FX_DWORD)-1; |
| 879 m_pCryptoHandler = NULL; | 875 m_pCryptoHandler = NULL; |
| 880 } | 876 } |
| 881 if (bKeepBuf) { | 877 if (bKeepBuf) { |
| 882 m_pDataBuf = (uint8_t*)pData; | 878 m_pDataBuf = (uint8_t*)pData; |
| 883 } else { | 879 } else { |
| 884 m_pDataBuf = FX_Alloc(uint8_t, size); | 880 m_pDataBuf = FX_Alloc(uint8_t, size); |
| 885 if (pData) { | 881 if (pData) { |
| 886 FXSYS_memcpy(m_pDataBuf, pData, size); | 882 FXSYS_memcpy(m_pDataBuf, pData, size); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 if (pSrcData != pStream->m_pDataBuf && pSrcData != m_pData) { | 1059 if (pSrcData != pStream->m_pDataBuf && pSrcData != m_pData) { |
| 1064 FX_Free(pSrcData); | 1060 FX_Free(pSrcData); |
| 1065 } | 1061 } |
| 1066 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) { | 1062 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) { |
| 1067 FX_Free(pDecryptedData); | 1063 FX_Free(pDecryptedData); |
| 1068 } | 1064 } |
| 1069 m_pSrcData = NULL; | 1065 m_pSrcData = NULL; |
| 1070 m_bNewBuf = m_pData != pStream->m_pDataBuf; | 1066 m_bNewBuf = m_pData != pStream->m_pDataBuf; |
| 1071 } | 1067 } |
| 1072 CPDF_StreamAcc::~CPDF_StreamAcc() { | 1068 CPDF_StreamAcc::~CPDF_StreamAcc() { |
| 1073 if (m_bNewBuf && m_pData) { | 1069 if (m_bNewBuf) { |
| 1074 FX_Free(m_pData); | 1070 FX_Free(m_pData); |
| 1075 } | 1071 } |
| 1076 if (m_pSrcData) { | |
| 1077 FX_Free(m_pSrcData); | 1072 FX_Free(m_pSrcData); |
| 1078 } | |
| 1079 } | 1073 } |
| 1080 const uint8_t* CPDF_StreamAcc::GetData() const { | 1074 const uint8_t* CPDF_StreamAcc::GetData() const { |
| 1081 if (m_bNewBuf) { | 1075 if (m_bNewBuf) { |
| 1082 return m_pData; | 1076 return m_pData; |
| 1083 } | 1077 } |
| 1084 if (!m_pStream) { | 1078 if (!m_pStream) { |
| 1085 return NULL; | 1079 return NULL; |
| 1086 } | 1080 } |
| 1087 return m_pStream->m_pDataBuf; | 1081 return m_pStream->m_pDataBuf; |
| 1088 } | 1082 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 } | 1206 } |
| 1213 pObj->m_ObjNum = objnum; | 1207 pObj->m_ObjNum = objnum; |
| 1214 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | 1208 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
| 1215 if (m_LastObjNum < objnum) { | 1209 if (m_LastObjNum < objnum) { |
| 1216 m_LastObjNum = objnum; | 1210 m_LastObjNum = objnum; |
| 1217 } | 1211 } |
| 1218 } | 1212 } |
| 1219 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { | 1213 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { |
| 1220 return m_LastObjNum; | 1214 return m_LastObjNum; |
| 1221 } | 1215 } |
| OLD | NEW |