Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp

Issue 2040503002: Fix more bugs found by /analyze tool (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | xfa/fwl/core/cfwl_widgetmgr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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_parser/include/cpdf_stream_acc.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" 9 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
10 10
(...skipping 24 matching lines...) Expand all
35 if (dwSrcSize == 0) 35 if (dwSrcSize == 0)
36 return; 36 return;
37 37
38 if (!pStream->IsMemoryBased()) { 38 if (!pStream->IsMemoryBased()) {
39 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); 39 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
40 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) 40 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
41 return; 41 return;
42 } else { 42 } else {
43 pSrcData = pStream->GetRawData(); 43 pSrcData = pStream->GetRawData();
44 } 44 }
45 uint8_t* pDecryptedData = pSrcData;
46 uint32_t dwDecryptedSize = dwSrcSize;
47 if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) { 45 if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) {
48 m_pData = pDecryptedData; 46 m_pData = pSrcData;
49 m_dwSize = dwDecryptedSize; 47 m_dwSize = dwSrcSize;
50 } else { 48 } else {
51 FX_BOOL bRet = PDF_DataDecode( 49 FX_BOOL bRet = PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(),
52 pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData, 50 m_pData, m_dwSize, m_ImageDecoder,
53 m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc); 51 m_pImageParam, estimated_size, bImageAcc);
54 if (!bRet) { 52 if (!bRet) {
55 m_pData = pDecryptedData; 53 m_pData = pSrcData;
56 m_dwSize = dwDecryptedSize; 54 m_dwSize = dwSrcSize;
57 } 55 }
58 } 56 }
59 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) { 57 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData)
60 FX_Free(pSrcData); 58 FX_Free(pSrcData);
61 }
62 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) {
63 FX_Free(pDecryptedData);
64 }
65 m_pSrcData = nullptr; 59 m_pSrcData = nullptr;
66 m_bNewBuf = m_pData != pStream->GetRawData(); 60 m_bNewBuf = m_pData != pStream->GetRawData();
67 } 61 }
68 62
69 CPDF_StreamAcc::~CPDF_StreamAcc() { 63 CPDF_StreamAcc::~CPDF_StreamAcc() {
70 if (m_bNewBuf) { 64 if (m_bNewBuf)
71 FX_Free(m_pData); 65 FX_Free(m_pData);
72 }
73 FX_Free(m_pSrcData); 66 FX_Free(m_pSrcData);
74 } 67 }
75 68
76 const uint8_t* CPDF_StreamAcc::GetData() const { 69 const uint8_t* CPDF_StreamAcc::GetData() const {
77 if (m_bNewBuf) { 70 if (m_bNewBuf)
78 return m_pData; 71 return m_pData;
79 } 72 return m_pStream ? m_pStream->GetRawData() : nullptr;
80 if (!m_pStream) {
81 return nullptr;
82 }
83 return m_pStream->GetRawData();
84 } 73 }
85 74
86 uint32_t CPDF_StreamAcc::GetSize() const { 75 uint32_t CPDF_StreamAcc::GetSize() const {
87 if (m_bNewBuf) { 76 if (m_bNewBuf)
88 return m_dwSize; 77 return m_dwSize;
89 } 78 return m_pStream ? m_pStream->GetRawSize() : 0;
90 if (!m_pStream) {
91 return 0;
92 }
93 return m_pStream->GetRawSize();
94 } 79 }
95 80
96 uint8_t* CPDF_StreamAcc::DetachData() { 81 uint8_t* CPDF_StreamAcc::DetachData() {
97 if (m_bNewBuf) { 82 if (m_bNewBuf) {
98 uint8_t* p = m_pData; 83 uint8_t* p = m_pData;
99 m_pData = nullptr; 84 m_pData = nullptr;
100 m_dwSize = 0; 85 m_dwSize = 0;
101 return p; 86 return p;
102 } 87 }
103 uint8_t* p = FX_Alloc(uint8_t, m_dwSize); 88 uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
104 FXSYS_memcpy(p, m_pData, m_dwSize); 89 FXSYS_memcpy(p, m_pData, m_dwSize);
105 return p; 90 return p;
106 } 91 }
OLDNEW
« no previous file with comments | « no previous file | xfa/fwl/core/cfwl_widgetmgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698