*/
i_img*
i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
- i_img *im;
+ i_img * volatile im = NULL;
#ifdef IMEXIF_ENABLE
int seen_exif = 0;
#endif
jpeg_saved_marker_ptr markerp;
transfer_function_t transfer_f;
int channels;
+ volatile int src_set = 0;
mm_log((1,"i_readjpeg_wiol(data 0x%p, length %d,iptc_itext 0x%p)\n", data, length, iptc_itext));
/* Set error handler */
if (setjmp(jerr.setjmp_buffer)) {
+ if (src_set)
+ wiol_term_source(&cinfo);
jpeg_destroy_decompress(&cinfo);
*iptc_itext=NULL;
*itlength=0;
if (line_buffer)
myfree(line_buffer);
+ if (im)
+ i_img_destroy(im);
return NULL;
}
jpeg_save_markers(&cinfo, JPEG_APP1, 0xFFFF);
jpeg_save_markers(&cinfo, JPEG_COM, 0xFFFF);
jpeg_wiol_src(&cinfo, data, length);
+ src_set = 1;
(void) jpeg_read_header(&cinfo, TRUE);
(void) jpeg_start_decompress(&cinfo);
channels = cinfo.output_components;
switch (cinfo.out_color_space) {
case JCS_GRAYSCALE:
+ if (cinfo.output_components != 1) {
+ mm_log((1, "i_readjpeg: grayscale image with %d channels\n", cinfo.output_components));
+ i_push_errorf(0, "grayscale image with invalid components %d", cinfo.output_components);
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
transfer_f = transfer_gray;
break;
case JCS_RGB:
transfer_f = transfer_rgb;
+ if (cinfo.output_components != 3) {
+ mm_log((1, "i_readjpeg: RGB image with %d channels\n", cinfo.output_components));
+ i_push_errorf(0, "RGB image with invalid components %d", cinfo.output_components);
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
break;
case JCS_CMYK:
markerp = cinfo.marker_list;
while (markerp != NULL) {
if (markerp->marker == JPEG_COM) {
- i_tags_add(&im->tags, "jpeg_comment", 0, markerp->data,
+ i_tags_add(&im->tags, "jpeg_comment", 0, (const char *)markerp->data,
markerp->data_length, 0);
}
#ifdef IMEXIF_ENABLE
jpeg_start_compress(&cinfo, TRUE);
if (i_tags_find(&im->tags, "jpeg_comment", 0, &comment_entry)) {
- jpeg_write_marker(&cinfo, JPEG_COM, im->tags.tags[comment_entry].data,
+ jpeg_write_marker(&cinfo, JPEG_COM,
+ (const JOCTET *)im->tags.tags[comment_entry].data,
im->tags.tags[comment_entry].size);
}