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

Side by Side Diff: third_party/libopenjpeg20/tcd.c

Issue 2182683002: Fix an integer overflow in opj_tcd_get_decoded_tile_size(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: another Created 4 years, 5 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 | « third_party/libopenjpeg20/j2k.c ('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 /* 1 /*
2 * The copyright in this software is being made available under the 2-clauses 2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third 3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights 4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license. 5 * are granted under this license.
6 * 6 *
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq 8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens 9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren 10 * Copyright (c) 2002-2003, Yannick Verschueren
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 } 1143 }
1144 1144
1145 OPJ_UINT32 opj_tcd_get_decoded_tile_size ( opj_tcd_t *p_tcd ) 1145 OPJ_UINT32 opj_tcd_get_decoded_tile_size ( opj_tcd_t *p_tcd )
1146 { 1146 {
1147 OPJ_UINT32 i; 1147 OPJ_UINT32 i;
1148 OPJ_UINT32 l_data_size = 0; 1148 OPJ_UINT32 l_data_size = 0;
1149 opj_image_comp_t * l_img_comp = 00; 1149 opj_image_comp_t * l_img_comp = 00;
1150 opj_tcd_tilecomp_t * l_tile_comp = 00; 1150 opj_tcd_tilecomp_t * l_tile_comp = 00;
1151 opj_tcd_resolution_t * l_res = 00; 1151 opj_tcd_resolution_t * l_res = 00;
1152 OPJ_UINT32 l_size_comp, l_remaining; 1152 OPJ_UINT32 l_size_comp, l_remaining;
1153 OPJ_UINT32 l_temp;
Lei Zhang 2016/07/25 21:24:59 Can we declare this inside the for-loop, since it'
Oliver Chang 2016/07/25 21:37:17 The style of openjpeg seems to be to declare all v
1153 1154
1154 l_tile_comp = p_tcd->tcd_image->tiles->comps; 1155 l_tile_comp = p_tcd->tcd_image->tiles->comps;
1155 l_img_comp = p_tcd->image->comps; 1156 l_img_comp = p_tcd->image->comps;
1156 1157
1157 for (i=0;i<p_tcd->image->numcomps;++i) { 1158 for (i=0;i<p_tcd->image->numcomps;++i) {
1158 l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/ 1159 l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
1159 l_remaining = l_img_comp->prec & 7; /* (%8) */ 1160 l_remaining = l_img_comp->prec & 7; /* (%8) */
1160 1161
1161 if(l_remaining) { 1162 if(l_remaining) {
1162 ++l_size_comp; 1163 ++l_size_comp;
1163 } 1164 }
1164 1165
1165 if (l_size_comp == 3) { 1166 if (l_size_comp == 3) {
1166 l_size_comp = 4; 1167 l_size_comp = 4;
1167 } 1168 }
1168 1169
1169 l_res = l_tile_comp->resolutions + l_tile_comp->minimum_num_reso lutions - 1; 1170 l_res = l_tile_comp->resolutions + l_tile_comp->minimum_num_reso lutions - 1;
1170 l_data_size += l_size_comp * (OPJ_UINT32)((l_res->x1 - l_res->x0 ) * (l_res->y1 - l_res->y0)); 1171 l_temp = (OPJ_UINT32)((l_res->x1 - l_res->x0) * (l_res->y1 - l_r es->y0)); /* x1*y1 can't overflow */
1172
1173 if (l_size_comp && ((OPJ_UINT32)-1) / l_size_comp < l_temp) {
1174 return (OPJ_UINT32)-1;
1175 }
1176 l_temp *= l_size_comp;
1177
1178 if (l_temp > ((OPJ_UINT32)-1) - l_data_size) {
1179 return (OPJ_UINT32)-1;
1180 }
1181 l_data_size += l_temp;
1182
1171 ++l_img_comp; 1183 ++l_img_comp;
1172 ++l_tile_comp; 1184 ++l_tile_comp;
1173 } 1185 }
1174 1186
1175 return l_data_size; 1187 return l_data_size;
1176 } 1188 }
1177 1189
1178 OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd, 1190 OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
1179 OPJ_UINT32 p_tile_no, 1191 OPJ_UINT32 p_tile_no,
1180 OPJ_BYTE *p_dest, 1192 OPJ_BYTE *p_dest,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 ) 1367 )
1356 { 1368 {
1357 OPJ_UINT32 i,j,k,l_data_size = 0; 1369 OPJ_UINT32 i,j,k,l_data_size = 0;
1358 opj_image_comp_t * l_img_comp = 00; 1370 opj_image_comp_t * l_img_comp = 00;
1359 opj_tcd_tilecomp_t * l_tilec = 00; 1371 opj_tcd_tilecomp_t * l_tilec = 00;
1360 opj_tcd_resolution_t * l_res; 1372 opj_tcd_resolution_t * l_res;
1361 OPJ_UINT32 l_size_comp, l_remaining; 1373 OPJ_UINT32 l_size_comp, l_remaining;
1362 OPJ_UINT32 l_stride, l_width,l_height; 1374 OPJ_UINT32 l_stride, l_width,l_height;
1363 1375
1364 l_data_size = opj_tcd_get_decoded_tile_size(p_tcd); 1376 l_data_size = opj_tcd_get_decoded_tile_size(p_tcd);
1365 if (l_data_size > p_dest_length) { 1377 if (l_data_size == (OPJ_UINT32)-1 || l_data_size > p_dest_length) {
1366 return OPJ_FALSE; 1378 return OPJ_FALSE;
1367 } 1379 }
1368 1380
1369 l_tilec = p_tcd->tcd_image->tiles->comps; 1381 l_tilec = p_tcd->tcd_image->tiles->comps;
1370 l_img_comp = p_tcd->image->comps; 1382 l_img_comp = p_tcd->image->comps;
1371 1383
1372 for (i=0;i<p_tcd->image->numcomps;++i) { 1384 for (i=0;i<p_tcd->image->numcomps;++i) {
1373 l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/ 1385 l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
1374 l_remaining = l_img_comp->prec & 7; /* (%8) */ 1386 l_remaining = l_img_comp->prec & 7; /* (%8) */
1375 l_res = l_tilec->resolutions + l_img_comp->resno_decoded; 1387 l_res = l_tilec->resolutions + l_img_comp->resno_decoded;
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 } 2215 }
2204 break; 2216 break;
2205 } 2217 }
2206 2218
2207 ++l_img_comp; 2219 ++l_img_comp;
2208 ++l_tilec; 2220 ++l_tilec;
2209 } 2221 }
2210 2222
2211 return OPJ_TRUE; 2223 return OPJ_TRUE;
2212 } 2224 }
OLDNEW
« no previous file with comments | « third_party/libopenjpeg20/j2k.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698