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

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

Issue 1534323002: Fix the JBIG2 decoding regressions from commit bc4b82e and 8a9ce57. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years 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/fxcodec/jbig2/JBig2_Context.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 "JBig2_HuffmanTable.h" 7 #include "JBig2_HuffmanTable.h"
8 8
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 unsigned char cTemp; 96 unsigned char cTemp;
97 if (pStream->read1Byte(&cTemp) == -1) 97 if (pStream->read1Byte(&cTemp) == -1)
98 return FALSE; 98 return FALSE;
99 99
100 HTOOB = cTemp & 0x01; 100 HTOOB = cTemp & 0x01;
101 unsigned char HTPS = ((cTemp >> 1) & 0x07) + 1; 101 unsigned char HTPS = ((cTemp >> 1) & 0x07) + 1;
102 unsigned char HTRS = ((cTemp >> 4) & 0x07) + 1; 102 unsigned char HTRS = ((cTemp >> 4) & 0x07) + 1;
103 FX_DWORD HTLOW; 103 FX_DWORD HTLOW;
104 FX_DWORD HTHIGH; 104 FX_DWORD HTHIGH;
105 if (pStream->readInteger(&HTLOW) == -1 || 105 if (pStream->readInteger(&HTLOW) == -1 ||
106 pStream->readInteger(&HTHIGH) == -1 || HTLOW > HTHIGH) { 106 pStream->readInteger(&HTHIGH) == -1) {
107 return FALSE; 107 return FALSE;
108 } 108 }
109 109
110 const int low = static_cast<int>(HTLOW);
Tom Sepez 2015/12/18 23:10:50 do you want int32_t here?
111 const int high = static_cast<int>(HTHIGH);
112 if (low > high)
113 return false;
114
110 FX_DWORD nSize = 16; 115 FX_DWORD nSize = 16;
111 PREFLEN = FX_Alloc(int, nSize); 116 PREFLEN = FX_Alloc(int, nSize);
112 RANGELEN = FX_Alloc(int, nSize); 117 RANGELEN = FX_Alloc(int, nSize);
113 RANGELOW = FX_Alloc(int, nSize); 118 RANGELOW = FX_Alloc(int, nSize);
114 FX_DWORD CURRANGELOW = HTLOW; 119 int cur_low = low;
115 NTEMP = 0; 120 NTEMP = 0;
116 do { 121 do {
117 HT_CHECK_MEMORY_ADJUST 122 HT_CHECK_MEMORY_ADJUST
118 if ((pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) || 123 if ((pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) ||
119 (pStream->readNBits(HTRS, &RANGELEN[NTEMP]) == -1)) { 124 (pStream->readNBits(HTRS, &RANGELEN[NTEMP]) == -1)) {
120 return FALSE; 125 return FALSE;
121 } 126 }
122 RANGELOW[NTEMP] = CURRANGELOW; 127 RANGELOW[NTEMP] = cur_low;
123 CURRANGELOW = CURRANGELOW + (1 << RANGELEN[NTEMP]); 128 cur_low += (1 << RANGELEN[NTEMP]);
124 NTEMP = NTEMP + 1; 129 NTEMP = NTEMP + 1;
125 } while (CURRANGELOW < HTHIGH); 130 } while (cur_low < high);
126 HT_CHECK_MEMORY_ADJUST 131 HT_CHECK_MEMORY_ADJUST
127 if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) 132 if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1)
128 return FALSE; 133 return FALSE;
129 134
130 RANGELEN[NTEMP] = 32; 135 RANGELEN[NTEMP] = 32;
131 RANGELOW[NTEMP] = HTLOW - 1; 136 RANGELOW[NTEMP] = low - 1;
132 ++NTEMP; 137 ++NTEMP;
133 HT_CHECK_MEMORY_ADJUST 138 HT_CHECK_MEMORY_ADJUST
134 if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) 139 if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1)
135 return FALSE; 140 return FALSE;
136 141
137 RANGELEN[NTEMP] = 32; 142 RANGELEN[NTEMP] = 32;
138 RANGELOW[NTEMP] = HTHIGH; 143 RANGELOW[NTEMP] = high;
139 NTEMP = NTEMP + 1; 144 NTEMP = NTEMP + 1;
140 if (HTOOB) { 145 if (HTOOB) {
141 HT_CHECK_MEMORY_ADJUST 146 HT_CHECK_MEMORY_ADJUST
142 if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) 147 if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1)
143 return FALSE; 148 return FALSE;
144 149
145 ++NTEMP; 150 ++NTEMP;
146 } 151 }
147 CODES = FX_Alloc(int, NTEMP); 152 CODES = FX_Alloc(int, NTEMP);
148 int LENMAX = 0; 153 int LENMAX = 0;
(...skipping 10 matching lines...) Expand all
159 for (int i = 1; i <= LENMAX; ++i) { 164 for (int i = 1; i <= LENMAX; ++i) {
160 FIRSTCODE[i] = (FIRSTCODE[i - 1] + LENCOUNT[i - 1]) << 1; 165 FIRSTCODE[i] = (FIRSTCODE[i - 1] + LENCOUNT[i - 1]) << 1;
161 int CURCODE = FIRSTCODE[i]; 166 int CURCODE = FIRSTCODE[i];
162 for (FX_DWORD j = 0; j < NTEMP; ++j) { 167 for (FX_DWORD j = 0; j < NTEMP; ++j) {
163 if (PREFLEN[j] == i) 168 if (PREFLEN[j] == i)
164 CODES[j] = CURCODE++; 169 CODES[j] = CURCODE++;
165 } 170 }
166 } 171 }
167 return TRUE; 172 return TRUE;
168 } 173 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_Context.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698