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

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

Issue 2250533002: Fix stack overflow in object Clone() functions (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase again Created 4 years, 4 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 | « core/fpdfapi/fpdf_parser/cpdf_reference.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_string.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.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
11 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" 11 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
12 #include "third_party/base/stl_util.h"
12 13
13 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) 14 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict)
14 : m_pDict(pDict), 15 : m_pDict(pDict),
15 m_dwSize(size), 16 m_dwSize(size),
16 m_GenNum(kMemoryBasedGenNum), 17 m_GenNum(kMemoryBasedGenNum),
17 m_pDataBuf(pData) {} 18 m_pDataBuf(pData) {}
18 19
19 CPDF_Stream::~CPDF_Stream() { 20 CPDF_Stream::~CPDF_Stream() {
21 m_ObjNum = kInvalidObjNum;
20 if (IsMemoryBased()) 22 if (IsMemoryBased())
21 FX_Free(m_pDataBuf); 23 FX_Free(m_pDataBuf);
22 24
23 if (m_pDict) 25 if (m_pDict)
24 m_pDict->Release(); 26 m_pDict->Release();
25 } 27 }
26 28
27 CPDF_Object::Type CPDF_Stream::GetType() const { 29 CPDF_Object::Type CPDF_Stream::GetType() const {
28 return STREAM; 30 return STREAM;
29 } 31 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 m_GenNum = kMemoryBasedGenNum; 66 m_GenNum = kMemoryBasedGenNum;
65 m_pDataBuf = FX_Alloc(uint8_t, size); 67 m_pDataBuf = FX_Alloc(uint8_t, size);
66 if (pData) 68 if (pData)
67 FXSYS_memcpy(m_pDataBuf, pData, size); 69 FXSYS_memcpy(m_pDataBuf, pData, size);
68 70
69 m_dwSize = size; 71 m_dwSize = size;
70 if (m_pDict) 72 if (m_pDict)
71 m_pDict->SetAtInteger("Length", size); 73 m_pDict->SetAtInteger("Length", size);
72 } 74 }
73 75
74 CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const { 76 CPDF_Object* CPDF_Stream::Clone() const {
77 return CloneObjectNonCyclic(false);
78 }
79
80 CPDF_Object* CPDF_Stream::CloneNonCyclic(
81 bool bDirect,
82 std::set<const CPDF_Object*>* pVisited) const {
83 pVisited->insert(this);
75 CPDF_StreamAcc acc; 84 CPDF_StreamAcc acc;
76 acc.LoadAllData(this, TRUE); 85 acc.LoadAllData(this, TRUE);
77 uint32_t streamSize = acc.GetSize(); 86 uint32_t streamSize = acc.GetSize();
78 CPDF_Dictionary* pDict = GetDict(); 87 CPDF_Dictionary* pDict = GetDict();
79 if (pDict) 88 if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) {
80 pDict = ToDictionary(pDict->Clone(bDirect)); 89 pDict = ToDictionary(
90 static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited));
91 }
81 92
82 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); 93 return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
83 } 94 }
84 95
85 void CPDF_Stream::SetData(const uint8_t* pData, 96 void CPDF_Stream::SetData(const uint8_t* pData,
86 uint32_t size, 97 uint32_t size,
87 FX_BOOL bCompressed, 98 FX_BOOL bCompressed,
88 FX_BOOL bKeepBuf) { 99 FX_BOOL bKeepBuf) {
89 if (IsMemoryBased()) 100 if (IsMemoryBased())
90 FX_Free(m_pDataBuf); 101 FX_Free(m_pDataBuf);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (m_pDict) 139 if (m_pDict)
129 m_pDict->SetAtInteger("Length", m_dwSize); 140 m_pDict->SetAtInteger("Length", m_dwSize);
130 } 141 }
131 142
132 CFX_WideString CPDF_Stream::GetUnicodeText() const { 143 CFX_WideString CPDF_Stream::GetUnicodeText() const {
133 CPDF_StreamAcc stream; 144 CPDF_StreamAcc stream;
134 stream.LoadAllData(this, FALSE); 145 stream.LoadAllData(this, FALSE);
135 return PDF_DecodeText(stream.GetData(), stream.GetSize()); 146 return PDF_DecodeText(stream.GetData(), stream.GetSize());
136 } 147 }
137 148
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_reference.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_string.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698