Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 OPJ_UINT16 i, nr_channels, cmp, pcol; | 965 OPJ_UINT16 i, nr_channels, cmp, pcol; |
| 966 OPJ_INT32 k, top_k; | 966 OPJ_INT32 k, top_k; |
| 967 | 967 |
| 968 channel_size = color->jp2_pclr->channel_size; | 968 channel_size = color->jp2_pclr->channel_size; |
| 969 channel_sign = color->jp2_pclr->channel_sign; | 969 channel_sign = color->jp2_pclr->channel_sign; |
| 970 entries = color->jp2_pclr->entries; | 970 entries = color->jp2_pclr->entries; |
| 971 cmap = color->jp2_pclr->cmap; | 971 cmap = color->jp2_pclr->cmap; |
| 972 nr_channels = color->jp2_pclr->nr_channels; | 972 nr_channels = color->jp2_pclr->nr_channels; |
| 973 | 973 |
| 974 old_comps = image->comps; | 974 old_comps = image->comps; |
| 975 /* Overflow check: prevent integer overflow */ | |
| 976 for (i = 0; i < nr_channels; ++i) { | |
|
Oliver Chang
2016/08/25 01:02:20
I know indentation is all over the place in this f
| |
| 977 cmp = cmap[i].cmp; | |
| 978 if (old_comps[cmp].h == 0 || old_comps[cmp].w > UINT_MAX / sizeof(OPJ_IN T32) / old_comps[cmp].h) { | |
|
Oliver Chang
2016/08/25 01:02:20
let's be explicit here and use ((OPJ_UINT32)-1) in
| |
| 979 return; | |
| 980 } | |
| 981 } | |
| 982 | |
| 975 new_comps = (opj_image_comp_t*) | 983 new_comps = (opj_image_comp_t*) |
| 976 opj_malloc(nr_channels * sizeof(opj_image_comp_t)); | 984 opj_malloc(nr_channels * sizeof(opj_image_comp_t)); |
| 977 if (!new_comps) { | 985 if (!new_comps) { |
| 978 /* FIXME no error code for opj_jp2_apply_pclr */ | 986 /* FIXME no error code for opj_jp2_apply_pclr */ |
| 979 /* FIXME event manager error callback */ | 987 /* FIXME event manager error callback */ |
| 980 return; | 988 return; |
| 981 } | 989 } |
| 982 for(i = 0; i < nr_channels; ++i) { | 990 for(i = 0; i < nr_channels; ++i) { |
| 983 pcol = cmap[i].pcol; cmp = cmap[i].cmp; | 991 pcol = cmap[i].pcol; cmp = cmap[i].cmp; |
| 984 | 992 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1004 new_comps[i].prec = channel_size[i]; | 1012 new_comps[i].prec = channel_size[i]; |
| 1005 new_comps[i].sgnd = channel_sign[i]; | 1013 new_comps[i].sgnd = channel_sign[i]; |
| 1006 } | 1014 } |
| 1007 | 1015 |
| 1008 top_k = color->jp2_pclr->nr_entries - 1; | 1016 top_k = color->jp2_pclr->nr_entries - 1; |
| 1009 | 1017 |
| 1010 for(i = 0; i < nr_channels; ++i) { | 1018 for(i = 0; i < nr_channels; ++i) { |
| 1011 /* Palette mapping: */ | 1019 /* Palette mapping: */ |
| 1012 cmp = cmap[i].cmp; pcol = cmap[i].pcol; | 1020 cmp = cmap[i].cmp; pcol = cmap[i].pcol; |
| 1013 src = old_comps[cmp].data; | 1021 src = old_comps[cmp].data; |
| 1014 assert( src ); | 1022 dst = new_comps[i].data; |
| 1015 max = new_comps[i].w * new_comps[i].h; | 1023 max = new_comps[i].w * new_comps[i].h; |
| 1016 | 1024 |
| 1025 /* Prevent null pointer access */ | |
| 1026 if (!src || !dst) { | |
| 1027 for (j = 0; j < nr_channels; ++j) { | |
| 1028 if (new_comps[j].data) { | |
|
Oliver Chang
2016/08/25 01:02:20
you don't need to check if the pointer is null bef
| |
| 1029 opj_free(new_comps[j].data); | |
| 1030 } | |
| 1031 } | |
| 1032 opj_free(new_comps); | |
| 1033 new_comps = NULL; | |
| 1034 return; | |
| 1035 } | |
| 1036 | |
| 1017 /* Direct use: */ | 1037 /* Direct use: */ |
| 1018 if(cmap[i].mtyp == 0) { | 1038 if(cmap[i].mtyp == 0) { |
| 1019 assert( cmp == 0 ); // probably wrong. | 1039 assert( cmp == 0 ); // probably wrong. |
| 1020 dst = new_comps[i].data; | |
| 1021 assert( dst ); | |
| 1022 for(j = 0; j < max; ++j) { | 1040 for(j = 0; j < max; ++j) { |
| 1023 dst[j] = src[j]; | 1041 dst[j] = src[j]; |
| 1024 } | 1042 } |
| 1025 } | 1043 } |
| 1026 else { | 1044 else { |
| 1027 assert( i == pcol ); // probably wrong? | 1045 assert( i == pcol ); // probably wrong? |
| 1028 dst = new_comps[i].data; | |
| 1029 assert( dst ); | |
| 1030 for(j = 0; j < max; ++j) { | 1046 for(j = 0; j < max; ++j) { |
| 1031 /* The index */ | 1047 /* The index */ |
| 1032 if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; | 1048 if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; |
| 1033 | 1049 |
| 1034 /* The colour */ | 1050 /* The colour */ |
| 1035 dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol]; | 1051 dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol]; |
| 1036 } | 1052 } |
| 1037 } | 1053 } |
| 1038 } | 1054 } |
| 1039 | 1055 |
| (...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3154 len = opj_stream_tell(cio)-lenp; | 3170 len = opj_stream_tell(cio)-lenp; |
| 3155 opj_stream_skip(cio, lenp, p_manager); | 3171 opj_stream_skip(cio, lenp, p_manager); |
| 3156 opj_write_bytes(l_data_header,len,4);/* L */ | 3172 opj_write_bytes(l_data_header,len,4);/* L */ |
| 3157 opj_stream_write_data(cio,l_data_header,4,p_manager); | 3173 opj_stream_write_data(cio,l_data_header,4,p_manager); |
| 3158 opj_stream_seek(cio, lenp+len,p_manager); | 3174 opj_stream_seek(cio, lenp+len,p_manager); |
| 3159 | 3175 |
| 3160 return len; | 3176 return len; |
| 3161 } | 3177 } |
| 3162 #endif | 3178 #endif |
| 3163 #endif /* USE_JPIP */ | 3179 #endif /* USE_JPIP */ |
| OLD | NEW |