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

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_GsidProc.cpp

Issue 1394933002: Fix a malloc/delete mismatch introduced in commit 8a9ce57. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 2 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 | core/src/fxcodec/jbig2/JBig2_List.h » ('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 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 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 "JBig2_GsidProc.h" 7 #include "JBig2_GsidProc.h"
8 8
9 #include "../../../../third_party/base/nonstd_unique_ptr.h" 9 #include "../../../../third_party/base/nonstd_unique_ptr.h"
10 #include "../../../include/fxcrt/fx_basic.h" 10 #include "../../../include/fxcrt/fx_basic.h"
11 #include "JBig2_BitStream.h" 11 #include "JBig2_BitStream.h"
12 #include "JBig2_GrdProc.h" 12 #include "JBig2_GrdProc.h"
13 #include "JBig2_Image.h" 13 #include "JBig2_Image.h"
14 #include "JBig2_List.h"
14 15
15 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, 16 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
16 JBig2ArithCtx* gbContext, 17 JBig2ArithCtx* gbContext,
17 IFX_Pause* pPause) { 18 IFX_Pause* pPause) {
18 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); 19 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
19 pGRD->MMR = GSMMR; 20 pGRD->MMR = GSMMR;
20 pGRD->GBW = GSW; 21 pGRD->GBW = GSW;
21 pGRD->GBH = GSH; 22 pGRD->GBH = GSH;
22 pGRD->GBTEMPLATE = GSTEMPLATE; 23 pGRD->GBTEMPLATE = GSTEMPLATE;
23 pGRD->TPGDON = 0; 24 pGRD->TPGDON = 0;
24 pGRD->USESKIP = GSUSESKIP; 25 pGRD->USESKIP = GSUSESKIP;
25 pGRD->SKIP = GSKIP; 26 pGRD->SKIP = GSKIP;
26 if (GSTEMPLATE <= 1) { 27 if (GSTEMPLATE <= 1) {
27 pGRD->GBAT[0] = 3; 28 pGRD->GBAT[0] = 3;
28 } else { 29 } else {
29 pGRD->GBAT[0] = 2; 30 pGRD->GBAT[0] = 2;
30 } 31 }
31 pGRD->GBAT[1] = -1; 32 pGRD->GBAT[1] = -1;
32 if (pGRD->GBTEMPLATE == 0) { 33 if (pGRD->GBTEMPLATE == 0) {
33 pGRD->GBAT[2] = -3; 34 pGRD->GBAT[2] = -3;
34 pGRD->GBAT[3] = -1; 35 pGRD->GBAT[3] = -1;
35 pGRD->GBAT[4] = 2; 36 pGRD->GBAT[4] = 2;
36 pGRD->GBAT[5] = -2; 37 pGRD->GBAT[5] = -2;
37 pGRD->GBAT[6] = -2; 38 pGRD->GBAT[6] = -2;
38 pGRD->GBAT[7] = -2; 39 pGRD->GBAT[7] = -2;
39 } 40 }
40 41
41 nonstd::unique_ptr<CJBig2_Image*, FxFreeDeleter> GSPLANES( 42 CJBig2_List<CJBig2_Image> GSPLANES(GSBPP);
42 FX_Alloc(CJBig2_Image*, GSBPP)); 43 CJBig2_Image* pImage = nullptr;
Tom Sepez 2015/10/08 19:57:34 nit: maybe fold this into the for loop below, the
Lei Zhang 2015/10/08 22:14:19 Done.
43 JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP); 44 FXCODEC_STATUS status =
44 FXCODEC_STATUS status = pGRD->Start_decode_Arith( 45 pGRD->Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr);
45 &GSPLANES.get()[GSBPP - 1], pArithDecoder, gbContext, nullptr); 46 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
46 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
47 pGRD->Continue_decode(pPause); 47 pGRD->Continue_decode(pPause);
48 } 48
49 if (!GSPLANES.get()[GSBPP - 1]) 49 if (!pImage)
50 return nullptr; 50 return nullptr;
51 51
52 int32_t J = GSBPP - 2; 52 GSPLANES.set(GSBPP - 1, pImage);
53 while (J >= 0) { 53 for (int32_t i = GSBPP - 2; i >= 0; --i) {
54 FXCODEC_STATUS status = pGRD->Start_decode_Arith( 54 pImage = nullptr;
55 &GSPLANES.get()[J], pArithDecoder, gbContext, nullptr); 55 FXCODEC_STATUS status =
56 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 56 pGRD->Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr);
57 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
57 pGRD->Continue_decode(pPause); 58 pGRD->Continue_decode(pPause);
58 } 59
59 if (!GSPLANES.get()[J]) { 60 if (!pImage)
60 for (int32_t K = GSBPP - 1; K > J; --K) { 61 return nullptr;
61 delete GSPLANES.get()[K]; 62
62 return nullptr; 63 GSPLANES.set(i, pImage);
63 } 64 pImage->composeFrom(0, 0, GSPLANES.get(i + 1), JBIG2_COMPOSE_XOR);
64 }
65 GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1],
66 JBIG2_COMPOSE_XOR);
67 J = J - 1;
68 } 65 }
69 nonstd::unique_ptr<FX_DWORD, FxFreeDeleter> GSVALS( 66 nonstd::unique_ptr<FX_DWORD, FxFreeDeleter> GSVALS(
70 FX_Alloc2D(FX_DWORD, GSW, GSH)); 67 FX_Alloc2D(FX_DWORD, GSW, GSH));
71 JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH); 68 JBIG2_memset(GSVALS.get(), 0, sizeof(FX_DWORD) * GSW * GSH);
72 for (FX_DWORD y = 0; y < GSH; ++y) { 69 for (FX_DWORD y = 0; y < GSH; ++y) {
73 for (FX_DWORD x = 0; x < GSW; ++x) { 70 for (FX_DWORD x = 0; x < GSW; ++x) {
74 for (J = 0; J < GSBPP; ++J) { 71 for (int32_t i = 0; i < GSBPP; ++i) {
75 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; 72 GSVALS.get()[y * GSW + x] |= GSPLANES.get(i)->getPixel(x, y) << i;
76 } 73 }
77 } 74 }
78 } 75 }
79 for (J = 0; J < GSBPP; ++J) {
80 delete GSPLANES.get()[J];
81 }
82 return GSVALS.release(); 76 return GSVALS.release();
83 } 77 }
84 78
85 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, 79 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream,
86 IFX_Pause* pPause) { 80 IFX_Pause* pPause) {
87 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); 81 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
88 pGRD->MMR = GSMMR; 82 pGRD->MMR = GSMMR;
89 pGRD->GBW = GSW; 83 pGRD->GBW = GSW;
90 pGRD->GBH = GSH; 84 pGRD->GBH = GSH;
91 85
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 for (J = 0; J < GSBPP; ++J) { 121 for (J = 0; J < GSBPP; ++J) {
128 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; 122 GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J;
129 } 123 }
130 } 124 }
131 } 125 }
132 for (J = 0; J < GSBPP; ++J) { 126 for (J = 0; J < GSBPP; ++J) {
133 delete GSPLANES.get()[J]; 127 delete GSPLANES.get()[J];
134 } 128 }
135 return GSVALS.release(); 129 return GSVALS.release();
136 } 130 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fxcodec/jbig2/JBig2_List.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698