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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp

Issue 439693002: Fix use-after-free in CPDF_Color::~CPDF_Color (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 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/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_page.h" 7 #include "../../../include/fpdfapi/fpdf_page.h"
8 #include "pageint.h" 8 #include "pageint.h"
9
10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix)
11 {
12 m_pPatternObj = NULL;
Tom Sepez 2014/08/05 17:34:15 nit: these can (and should) occur as part of a : -
jun_fang 2014/08/05 18:21:40 OK. I will update them in the next patch.
13 m_PatternType = PATTERN_TILING;
14 m_pDocument = NULL;
15 m_pColor = NULL;
16
17 if (pParentMatrix) {
18 m_ParentMatrix = *pParentMatrix;
19 }
20 }
21
22 CPDF_Pattern::~CPDF_Pattern()
23 {
24 if (m_pColor) {
25 m_pColor->SetValue(NULL, NULL, 0);
26 m_pColor = NULL;
Tom Sepez 2014/08/05 17:34:14 Do we leak m_pColor here? Who owns this memory?
jun_fang 2014/08/05 18:21:39 No. m_pColor refers to the object of CPDF_Color by
27 }
28 }
9 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatter nObj, const CFX_AffineMatrix* parentMatrix) : 29 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatter nObj, const CFX_AffineMatrix* parentMatrix) :
10 CPDF_Pattern(parentMatrix) 30 CPDF_Pattern(parentMatrix)
11 { 31 {
12 m_PatternType = PATTERN_TILING; 32 m_PatternType = PATTERN_TILING;
13 m_pPatternObj = pPatternObj; 33 m_pPatternObj = pPatternObj;
14 m_pDocument = pDoc; 34 m_pDocument = pDoc;
35 m_pColor = NULL;
Tom Sepez 2014/08/05 17:34:14 m_pColor is nulled in the parent class constructor
jun_fang 2014/08/05 18:21:40 I will update it in the next patch.
15 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 36 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
16 ASSERT(pDict != NULL); 37 ASSERT(pDict != NULL);
17 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); 38 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix"));
18 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; 39 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
19 if (parentMatrix) { 40 if (parentMatrix) {
20 m_Pattern2Form.Concat(*parentMatrix); 41 m_Pattern2Form.Concat(*parentMatrix);
21 } 42 }
22 m_pForm = NULL; 43 m_pForm = NULL;
23 } 44 }
24 CPDF_TilingPattern::~CPDF_TilingPattern() 45 CPDF_TilingPattern::~CPDF_TilingPattern()
25 { 46 {
26 if (m_pForm) { 47 if (m_pForm) {
27 delete m_pForm; 48 delete m_pForm;
49 m_pForm = NULL;
28 } 50 }
29 } 51 }
30 FX_BOOL CPDF_TilingPattern::Load() 52 FX_BOOL CPDF_TilingPattern::Load()
31 { 53 {
32 if (m_pForm != NULL) { 54 if (m_pForm != NULL) {
33 return TRUE; 55 return TRUE;
34 } 56 }
35 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 57 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
36 if (pDict == NULL) { 58 if (pDict == NULL) {
37 return FALSE; 59 return FALSE;
38 } 60 }
39 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; 61 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
40 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); 62 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep")));
41 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); 63 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep")));
42 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) { 64 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) {
43 return FALSE; 65 return FALSE;
44 } 66 }
45 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj; 67 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj;
46 m_pForm = FX_NEW CPDF_Form(m_pDocument, NULL, pStream); 68 m_pForm = FX_NEW CPDF_Form(m_pDocument, NULL, pStream);
47 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); 69 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL);
48 m_BBox = pDict->GetRect(FX_BSTRC("BBox")); 70 m_BBox = pDict->GetRect(FX_BSTRC("BBox"));
49 return TRUE; 71 return TRUE;
50 } 72 }
51 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatt ernObj, FX_BOOL bShading, const CFX_AffineMatrix* parentMatrix) : CPDF_Pattern(p arentMatrix) 73 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatt ernObj, FX_BOOL bShading, const CFX_AffineMatrix* parentMatrix) : CPDF_Pattern(p arentMatrix)
52 { 74 {
53 m_PatternType = PATTERN_SHADING; 75 m_PatternType = PATTERN_SHADING;
54 m_pPatternObj = bShading ? NULL : pPatternObj; 76 m_pPatternObj = bShading ? NULL : pPatternObj;
55 m_pDocument = pDoc; 77 m_pDocument = pDoc;
78 m_pColor = NULL;
56 m_bShadingObj = bShading; 79 m_bShadingObj = bShading;
57 if (!bShading) { 80 if (!bShading) {
58 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 81 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
59 ASSERT(pDict != NULL); 82 ASSERT(pDict != NULL);
60 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); 83 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix"));
61 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); 84 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading"));
62 if (parentMatrix) { 85 if (parentMatrix) {
63 m_Pattern2Form.Concat(*parentMatrix); 86 m_Pattern2Form.Concat(*parentMatrix);
64 } 87 }
65 } else { 88 } else {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 292 }
270 } 293 }
271 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * color _count); 294 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * color _count);
272 if (bGouraud) { 295 if (bGouraud) {
273 stream.m_BitStream.ByteAlign(); 296 stream.m_BitStream.ByteAlign();
274 } 297 }
275 } 298 }
276 rect.Transform(pMatrix); 299 rect.Transform(pMatrix);
277 return rect; 300 return rect;
278 } 301 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698