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

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

Issue 2517513003: Add unit test for CXFA_FileRead. (Closed)
Patch Set: Created 4 years, 1 month 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 | « core/fpdfapi/parser/cpdf_stream.cpp ('k') | xfa/fxfa/app/xfa_ffapp_unittest.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/parser/cpdf_stream_acc.h" 7 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
8 8
9 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 9 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
10 10
11 CPDF_StreamAcc::CPDF_StreamAcc() 11 CPDF_StreamAcc::CPDF_StreamAcc()
12 : m_pData(nullptr), 12 : m_pData(nullptr),
13 m_dwSize(0), 13 m_dwSize(0),
14 m_bNewBuf(false), 14 m_bNewBuf(false),
15 m_pImageParam(nullptr), 15 m_pImageParam(nullptr),
16 m_pStream(nullptr), 16 m_pStream(nullptr),
17 m_pSrcData(nullptr) {} 17 m_pSrcData(nullptr) {}
18 18
19 void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, 19 void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
20 bool bRawAccess, 20 bool bRawAccess,
21 uint32_t estimated_size, 21 uint32_t estimated_size,
22 bool bImageAcc) { 22 bool bImageAcc) {
23 if (!pStream) 23 if (!pStream)
24 return; 24 return;
25 25
26 m_pStream = pStream; 26 m_pStream = pStream;
27 if (pStream->IsMemoryBased() && 27 if (pStream->IsMemoryBased() && (!pStream->HasFilter() || bRawAccess)) {
28 (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) {
29 m_dwSize = pStream->GetRawSize(); 28 m_dwSize = pStream->GetRawSize();
30 m_pData = pStream->GetRawData(); 29 m_pData = pStream->GetRawData();
31 return; 30 return;
32 } 31 }
33 uint8_t* pSrcData;
34 uint32_t dwSrcSize = pStream->GetRawSize(); 32 uint32_t dwSrcSize = pStream->GetRawSize();
35 if (dwSrcSize == 0) 33 if (dwSrcSize == 0)
36 return; 34 return;
37 35
36 uint8_t* pSrcData;
38 if (!pStream->IsMemoryBased()) { 37 if (!pStream->IsMemoryBased()) {
39 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); 38 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
40 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) 39 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
41 return; 40 return;
42 } else { 41 } else {
43 pSrcData = pStream->GetRawData(); 42 pSrcData = pStream->GetRawData();
44 } 43 }
45 if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) { 44 if (!pStream->HasFilter() || bRawAccess) {
46 m_pData = pSrcData; 45 m_pData = pSrcData;
47 m_dwSize = dwSrcSize; 46 m_dwSize = dwSrcSize;
48 } else { 47 } else if (!PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), m_pData,
49 bool bRet = PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), 48 m_dwSize, m_ImageDecoder, m_pImageParam,
50 m_pData, m_dwSize, m_ImageDecoder, m_pImageParam, 49 estimated_size, bImageAcc)) {
51 estimated_size, bImageAcc); 50 m_pData = pSrcData;
52 if (!bRet) { 51 m_dwSize = dwSrcSize;
53 m_pData = pSrcData;
54 m_dwSize = dwSrcSize;
55 }
56 } 52 }
57 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) 53 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData)
58 FX_Free(pSrcData); 54 FX_Free(pSrcData);
59 m_pSrcData = nullptr; 55 m_pSrcData = nullptr;
60 m_bNewBuf = m_pData != pStream->GetRawData(); 56 m_bNewBuf = m_pData != pStream->GetRawData();
61 } 57 }
62 58
63 CPDF_StreamAcc::~CPDF_StreamAcc() { 59 CPDF_StreamAcc::~CPDF_StreamAcc() {
64 if (m_bNewBuf) 60 if (m_bNewBuf)
65 FX_Free(m_pData); 61 FX_Free(m_pData);
(...skipping 16 matching lines...) Expand all
82 if (m_bNewBuf) { 78 if (m_bNewBuf) {
83 uint8_t* p = m_pData; 79 uint8_t* p = m_pData;
84 m_pData = nullptr; 80 m_pData = nullptr;
85 m_dwSize = 0; 81 m_dwSize = 0;
86 return p; 82 return p;
87 } 83 }
88 uint8_t* p = FX_Alloc(uint8_t, m_dwSize); 84 uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
89 FXSYS_memcpy(p, m_pData, m_dwSize); 85 FXSYS_memcpy(p, m_pData, m_dwSize);
90 return p; 86 return p;
91 } 87 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_stream.cpp ('k') | xfa/fxfa/app/xfa_ffapp_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698