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

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_clippath.cpp

Issue 1998583002: Fix leak in CPDF_StreamContentParser::AddTextObject(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: More vectors, fix leak Created 4 years, 7 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
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_page/include/cpdf_clippath.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h"
8 8
9 #include <utility>
10
9 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" 11 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
10 12
11 #define FPDF_CLIPPATH_MAX_TEXTS 1024 13 #define FPDF_CLIPPATH_MAX_TEXTS 1024
12 14
13 CFX_FloatRect CPDF_ClipPath::GetClipBox() const { 15 CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
14 CFX_FloatRect rect; 16 CFX_FloatRect rect;
15 FX_BOOL bStarted = FALSE; 17 FX_BOOL bStarted = FALSE;
16 int count = GetPathCount(); 18 int count = GetPathCount();
17 if (count) { 19 if (count) {
18 rect = GetPath(0).GetBoundingBox(); 20 rect = GetPath(0).GetBoundingBox();
(...skipping 23 matching lines...) Expand all
42 bLayerStarted = TRUE; 44 bLayerStarted = TRUE;
43 } else { 45 } else {
44 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr))); 46 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
45 } 47 }
46 } 48 }
47 } 49 }
48 } 50 }
49 return rect; 51 return rect;
50 } 52 }
51 53
52 void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) { 54 void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
53 CPDF_ClipPathData* pData = GetModify(); 55 CPDF_ClipPathData* pData = GetModify();
54 if (pData->m_PathCount && bAutoMerge) { 56 if (!pData->m_PathList.empty() && bAutoMerge) {
55 CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1]; 57 CPDF_Path old_path = pData->m_PathList.back();
56 if (old_path.IsRect()) { 58 if (old_path.IsRect()) {
57 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0), 59 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
58 old_path.GetPointX(2), old_path.GetPointY(2)); 60 old_path.GetPointX(2), old_path.GetPointY(2));
59 CFX_FloatRect new_rect = path.GetBoundingBox(); 61 CFX_FloatRect new_rect = path.GetBoundingBox();
60 if (old_rect.Contains(new_rect)) { 62 if (old_rect.Contains(new_rect)) {
61 pData->m_PathCount--; 63 pData->m_PathList.back().SetNull();
Tom Sepez 2016/05/19 18:32:03 Doesn't the dtor invoked by pop_back on the next l
Lei Zhang 2016/05/19 20:44:26 Done.
62 pData->m_pPathList[pData->m_PathCount].SetNull(); 64 pData->m_PathList.pop_back();
63 } 65 }
64 } 66 }
65 } 67 }
66 if (pData->m_PathCount % 8 == 0) { 68 pData->m_PathList.push_back(path);
Tom Sepez 2016/05/19 18:32:03 you don't suppose we could have a single vector<st
Lei Zhang 2016/05/19 20:44:26 Done.
67 CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8]; 69 pData->m_TypeList.push_back(type);
68 for (int i = 0; i < pData->m_PathCount; i++) {
69 pNewPath[i] = pData->m_pPathList[i];
70 }
71 delete[] pData->m_pPathList;
72 uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8);
73 FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount);
74 FX_Free(pData->m_pTypeList);
75 pData->m_pPathList = pNewPath;
76 pData->m_pTypeList = pNewType;
77 }
78 pData->m_pPathList[pData->m_PathCount] = path;
79 pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type;
80 pData->m_PathCount++;
81 } 70 }
82 71
83 void CPDF_ClipPath::DeletePath(int index) { 72 void CPDF_ClipPath::AppendTexts(
Lei Zhang 2016/05/19 17:28:45 Dead code.
73 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) {
84 CPDF_ClipPathData* pData = GetModify(); 74 CPDF_ClipPathData* pData = GetModify();
85 if (index >= pData->m_PathCount) { 75 if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) {
86 return; 76 for (size_t i = 0; i < pTexts->size(); i++)
77 pData->m_TextList.push_back(std::move((*pTexts)[i]));
78 pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>());
87 } 79 }
88 pData->m_pPathList[index].SetNull(); 80 pTexts->clear();
89 for (int i = index; i < pData->m_PathCount - 1; i++) {
90 pData->m_pPathList[i] = pData->m_pPathList[i + 1];
91 }
92 pData->m_pPathList[pData->m_PathCount - 1].SetNull();
93 FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1,
94 pData->m_PathCount - index - 1);
95 pData->m_PathCount--;
96 }
97
98 void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) {
99 CPDF_ClipPathData* pData = GetModify();
100 if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) {
101 for (int i = 0; i < count; i++) {
102 delete pTexts[i];
103 }
104 return;
105 }
106 CPDF_TextObject** pNewList =
107 FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1);
108 if (pData->m_pTextList) {
109 FXSYS_memcpy(pNewList, pData->m_pTextList,
110 pData->m_TextCount * sizeof(CPDF_TextObject*));
111 FX_Free(pData->m_pTextList);
112 }
113 pData->m_pTextList = pNewList;
114 for (int i = 0; i < count; i++) {
115 pData->m_pTextList[pData->m_TextCount + i] = pTexts[i];
116 }
117 pData->m_pTextList[pData->m_TextCount + count] = NULL;
118 pData->m_TextCount += count + 1;
119 } 81 }
120 82
121 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) { 83 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
122 CPDF_ClipPathData* pData = GetModify(); 84 CPDF_ClipPathData* pData = GetModify();
123 int i; 85 for (auto& path : pData->m_PathList)
124 for (i = 0; i < pData->m_PathCount; i++) { 86 path.Transform(&matrix);
125 pData->m_pPathList[i].Transform(&matrix); 87 for (auto& text : pData->m_TextList) {
88 if (text)
89 text->Transform(matrix);
126 } 90 }
127 for (i = 0; i < pData->m_TextCount; i++)
128 if (pData->m_pTextList[i]) {
129 pData->m_pTextList[i]->Transform(matrix);
130 }
131 } 91 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_clippathdata.h » ('j') | core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698