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

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

Issue 2253423002: openjpeg: Prevent an integer overflow in opj_jp2_apply_pclr. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 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 | « third_party/libopenjpeg20/README.pdfium ('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 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 pcol = cmap[i].pcol; cmp = cmap[i].cmp; 983 pcol = cmap[i].pcol; cmp = cmap[i].cmp;
984 984
985 /* Direct use */ 985 /* Direct use */
986 if(cmap[i].mtyp == 0){ 986 if(cmap[i].mtyp == 0){
987 assert( pcol == 0 ); 987 assert( pcol == 0 );
988 new_comps[i] = old_comps[cmp]; 988 new_comps[i] = old_comps[cmp];
989 } else { 989 } else {
990 assert( i == pcol ); // probably wrong? 990 assert( i == pcol ); // probably wrong?
991 new_comps[i] = old_comps[cmp]; 991 new_comps[i] = old_comps[cmp];
992 } 992 }
993 993 /* Prevent integer overflow */
994 if (old_comps[cmp].h == 0 || old_comps[cmp].w > UINT_MAX / sizeof(OPJ_IN T32) / old_comps[cmp].h) {
995 for (j = 0; j < i; ++j) {
996 if (new_comps[j].data) {
997 opj_free(new_comps[j].data);
998 }
999 }
1000 opj_free(new_comps);
1001 new_comps = NULL;
1002 return;
1003 }
1004
994 /* Palette mapping: */ 1005 /* Palette mapping: */
995 new_comps[i].data = (OPJ_INT32*) 1006 new_comps[i].data = (OPJ_INT32*)
996 opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32)); 1007 opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
997 if (!new_comps[i].data) { 1008 if (!new_comps[i].data) {
998 opj_free(new_comps); 1009 opj_free(new_comps);
999 new_comps = NULL; 1010 new_comps = NULL;
1000 /* FIXME no error code for opj_jp2_apply_pclr */ 1011 /* FIXME no error code for opj_jp2_apply_pclr */
1001 /* FIXME event manager error callback */ 1012 /* FIXME event manager error callback */
1002 return; 1013 return;
1003 } 1014 }
1004 new_comps[i].prec = channel_size[i]; 1015 new_comps[i].prec = channel_size[i];
1005 new_comps[i].sgnd = channel_sign[i]; 1016 new_comps[i].sgnd = channel_sign[i];
1006 } 1017 }
1007 1018
1008 top_k = color->jp2_pclr->nr_entries - 1; 1019 top_k = color->jp2_pclr->nr_entries - 1;
1009 1020
1010 for(i = 0; i < nr_channels; ++i) { 1021 for(i = 0; i < nr_channels; ++i) {
1011 /* Palette mapping: */ 1022 /* Palette mapping: */
1012 cmp = cmap[i].cmp; pcol = cmap[i].pcol; 1023 cmp = cmap[i].cmp; pcol = cmap[i].pcol;
1013 src = old_comps[cmp].data; 1024 src = old_comps[cmp].data;
1014 assert( src ); 1025
1026 /* Prevent null pointer access */
1027 if (!old_comps[cmp].data || !new_comps[i].data) {
1028 for (j = 0; j < nr_channels; ++j) {
Oliver Chang 2016/08/23 16:52:40 these lines are very similar to 995-1000. maybe co
1029 if (new_comps[j].data) {
1030 opj_free(new_comps[j].data);
1031 }
1032 }
1033 opj_free(new_comps);
1034 new_comps = NULL;
1035 return;
1036 }
1037
1015 max = new_comps[i].w * new_comps[i].h; 1038 max = new_comps[i].w * new_comps[i].h;
1016 1039
1017 /* Direct use: */ 1040 /* Direct use: */
1018 if(cmap[i].mtyp == 0) { 1041 if(cmap[i].mtyp == 0) {
1019 assert( cmp == 0 ); // probably wrong. 1042 assert( cmp == 0 ); // probably wrong.
1020 dst = new_comps[i].data; 1043 dst = new_comps[i].data;
1021 assert( dst ); 1044
1022 for(j = 0; j < max; ++j) { 1045 for(j = 0; j < max; ++j) {
1023 dst[j] = src[j]; 1046 dst[j] = src[j];
1024 } 1047 }
1025 } 1048 }
1026 else { 1049 else {
1027 assert( i == pcol ); // probably wrong? 1050 assert( i == pcol ); // probably wrong?
1028 dst = new_comps[i].data; 1051 dst = new_comps[i].data;
1029 assert( dst ); 1052
1030 for(j = 0; j < max; ++j) { 1053 for(j = 0; j < max; ++j) {
1031 /* The index */ 1054 /* The index */
1032 if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; 1055 if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
1033 1056
1034 /* The colour */ 1057 /* The colour */
1035 dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol]; 1058 dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol];
1036 } 1059 }
1037 } 1060 }
1038 } 1061 }
1039 1062
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3154 len = opj_stream_tell(cio)-lenp; 3177 len = opj_stream_tell(cio)-lenp;
3155 opj_stream_skip(cio, lenp, p_manager); 3178 opj_stream_skip(cio, lenp, p_manager);
3156 opj_write_bytes(l_data_header,len,4);/* L */ 3179 opj_write_bytes(l_data_header,len,4);/* L */
3157 opj_stream_write_data(cio,l_data_header,4,p_manager); 3180 opj_stream_write_data(cio,l_data_header,4,p_manager);
3158 opj_stream_seek(cio, lenp+len,p_manager); 3181 opj_stream_seek(cio, lenp+len,p_manager);
3159 3182
3160 return len; 3183 return len;
3161 } 3184 }
3162 #endif 3185 #endif
3163 #endif /* USE_JPIP */ 3186 #endif /* USE_JPIP */
OLDNEW
« no previous file with comments | « third_party/libopenjpeg20/README.pdfium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698