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

Side by Side Diff: core/src/fxcodec/codec/fx_codec_jpx_opj.cpp

Issue 1521473003: Merge to XFA: Fix integer and bounds issues in sycc4{22,44}_to_rgb. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
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
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 *out_g = g; 158 *out_g = g;
159 b = y + (int)(1.772 * (float)cb); 159 b = y + (int)(1.772 * (float)cb);
160 if (b < 0) { 160 if (b < 0) {
161 b = 0; 161 b = 0;
162 } else if (b > upb) { 162 } else if (b > upb) {
163 b = upb; 163 b = upb;
164 } 164 }
165 *out_b = b; 165 *out_b = b;
166 } 166 }
167 static void sycc444_to_rgb(opj_image_t* img) { 167 static void sycc444_to_rgb(opj_image_t* img) {
168 int prec = img->comps[0].prec;
169 int offset = 1 << (prec - 1);
170 int upb = (1 << prec) - 1;
171 OPJ_UINT32 maxw =
172 std::min(std::min(img->comps[0].w, img->comps[1].w), img->comps[2].w);
173 OPJ_UINT32 maxh =
174 std::min(std::min(img->comps[0].h, img->comps[1].h), img->comps[2].h);
175 FX_SAFE_SIZE_T max_size = maxw;
176 max_size *= maxh;
177 if (!max_size.IsValid())
178 return;
179
180 const int* y = img->comps[0].data;
181 const int* cb = img->comps[1].data;
182 const int* cr = img->comps[2].data;
168 int *d0, *d1, *d2, *r, *g, *b; 183 int *d0, *d1, *d2, *r, *g, *b;
169 const int *y, *cb, *cr; 184 d0 = r = FX_Alloc(int, max_size.ValueOrDie());
170 int maxw, maxh, max, i, offset, upb; 185 d1 = g = FX_Alloc(int, max_size.ValueOrDie());
171 i = (int)img->comps[0].prec; 186 d2 = b = FX_Alloc(int, max_size.ValueOrDie());
172 offset = 1 << (i - 1); 187 for (size_t i = 0; i < max_size.ValueOrDie(); ++i) {
173 upb = (1 << i) - 1;
174 maxw = (int)img->comps[0].w;
175 maxh = (int)img->comps[0].h;
176 max = maxw * maxh;
177 y = img->comps[0].data;
178 cb = img->comps[1].data;
179 cr = img->comps[2].data;
180 d0 = r = FX_Alloc(int, (size_t)max);
181 d1 = g = FX_Alloc(int, (size_t)max);
182 d2 = b = FX_Alloc(int, (size_t)max);
183 for (i = 0; i < max; ++i) {
184 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); 188 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
185 ++y; 189 ++y;
186 ++cb; 190 ++cb;
187 ++cr; 191 ++cr;
188 ++r; 192 ++r;
189 ++g; 193 ++g;
190 ++b; 194 ++b;
191 } 195 }
192 FX_Free(img->comps[0].data); 196 FX_Free(img->comps[0].data);
193 img->comps[0].data = d0; 197 img->comps[0].data = d0;
194 FX_Free(img->comps[1].data); 198 FX_Free(img->comps[1].data);
195 img->comps[1].data = d1; 199 img->comps[1].data = d1;
196 FX_Free(img->comps[2].data); 200 FX_Free(img->comps[2].data);
197 img->comps[2].data = d2; 201 img->comps[2].data = d2;
198 } 202 }
199 static void sycc422_to_rgb(opj_image_t* img) { 203 static void sycc422_to_rgb(opj_image_t* img) {
204 int prec = img->comps[0].prec;
205 int offset = 1 << (prec - 1);
206 int upb = (1 << prec) - 1;
207 OPJ_UINT32 maxw =
208 std::min(std::min(img->comps[0].w, img->comps[1].w), img->comps[2].w);
209 OPJ_UINT32 maxh =
210 std::min(std::min(img->comps[0].h, img->comps[1].h), img->comps[2].h);
211 FX_SAFE_SIZE_T max_size = maxw;
212 max_size *= maxh;
213 if (!max_size.IsValid())
214 return;
215
216 const int* y = img->comps[0].data;
217 const int* cb = img->comps[1].data;
218 const int* cr = img->comps[2].data;
200 int *d0, *d1, *d2, *r, *g, *b; 219 int *d0, *d1, *d2, *r, *g, *b;
201 const int *y, *cb, *cr; 220 d0 = r = FX_Alloc(int, max_size.ValueOrDie());
202 int maxw, maxh, max, offset, upb; 221 d1 = g = FX_Alloc(int, max_size.ValueOrDie());
203 int i, j; 222 d2 = b = FX_Alloc(int, max_size.ValueOrDie());
204 i = (int)img->comps[0].prec; 223 for (uint32_t i = 0; i < maxh; ++i) {
205 offset = 1 << (i - 1); 224 OPJ_UINT32 j;
206 upb = (1 << i) - 1; 225 for (j = 0; j < (maxw & ~static_cast<OPJ_UINT32>(1)); j += 2) {
207 maxw = (int)img->comps[0].w;
208 maxh = (int)img->comps[0].h;
209 max = maxw * maxh;
210 y = img->comps[0].data;
211 cb = img->comps[1].data;
212 cr = img->comps[2].data;
213 d0 = r = FX_Alloc(int, (size_t)max);
214 d1 = g = FX_Alloc(int, (size_t)max);
215 d2 = b = FX_Alloc(int, (size_t)max);
216 for (i = 0; i < maxh; ++i) {
217 for (j = 0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2) {
218 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); 226 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
219 ++y; 227 ++y;
220 ++r; 228 ++r;
221 ++g; 229 ++g;
222 ++b; 230 ++b;
223 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); 231 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
224 ++y; 232 ++y;
225 ++r; 233 ++r;
226 ++g; 234 ++g;
227 ++b; 235 ++b;
(...skipping 13 matching lines...) Expand all
241 FX_Free(img->comps[0].data); 249 FX_Free(img->comps[0].data);
242 img->comps[0].data = d0; 250 img->comps[0].data = d0;
243 FX_Free(img->comps[1].data); 251 FX_Free(img->comps[1].data);
244 img->comps[1].data = d1; 252 img->comps[1].data = d1;
245 FX_Free(img->comps[2].data); 253 FX_Free(img->comps[2].data);
246 img->comps[2].data = d2; 254 img->comps[2].data = d2;
247 img->comps[1].w = maxw; 255 img->comps[1].w = maxw;
248 img->comps[1].h = maxh; 256 img->comps[1].h = maxh;
249 img->comps[2].w = maxw; 257 img->comps[2].w = maxw;
250 img->comps[2].h = maxh; 258 img->comps[2].h = maxh;
251 img->comps[1].w = (OPJ_UINT32)maxw;
252 img->comps[1].h = (OPJ_UINT32)maxh;
253 img->comps[2].w = (OPJ_UINT32)maxw;
254 img->comps[2].h = (OPJ_UINT32)maxh;
255 img->comps[1].dx = img->comps[0].dx; 259 img->comps[1].dx = img->comps[0].dx;
256 img->comps[2].dx = img->comps[0].dx; 260 img->comps[2].dx = img->comps[0].dx;
257 img->comps[1].dy = img->comps[0].dy; 261 img->comps[1].dy = img->comps[0].dy;
258 img->comps[2].dy = img->comps[0].dy; 262 img->comps[2].dy = img->comps[0].dy;
259 } 263 }
260 static bool sycc420_size_is_valid(OPJ_UINT32 y, OPJ_UINT32 cbcr) { 264 static bool sycc420_size_is_valid(OPJ_UINT32 y, OPJ_UINT32 cbcr) {
261 if (!y || !cbcr) 265 if (!y || !cbcr)
262 return false; 266 return false;
263 267
264 return (cbcr == y / 2) || ((y & 1) && (cbcr == y / 2 + 1)); 268 return (cbcr == y / 2) || ((y & 1) && (cbcr == y / 2 + 1));
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, 880 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder,
877 uint8_t* dest_data, 881 uint8_t* dest_data,
878 int pitch, 882 int pitch,
879 const std::vector<uint8_t>& offsets) { 883 const std::vector<uint8_t>& offsets) {
880 return pDecoder->Decode(dest_data, pitch, offsets); 884 return pDecoder->Decode(dest_data, pitch, offsets);
881 } 885 }
882 886
883 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { 887 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) {
884 delete pDecoder; 888 delete pDecoder;
885 } 889 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_loadimage_embeddertest.cpp ('k') | testing/resources/bug_557223.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698