diff --git a/albumart.c b/albumart.c index a8f5334..2369d6c 100644 --- a/albumart.c +++ b/albumart.c @@ -181,6 +181,8 @@ check_for_album_file(char * dir) if( access(file, R_OK) == 0 ) { imsrc = image_new_from_jpeg(file, 1, NULL, 0); + if( !imsrc ) + return NULL; width = imsrc->width; height = imsrc->height; if( width > 160 || height > 160 ) diff --git a/image_utils.c b/image_utils.c index 3cf2ad4..dfab925 100644 --- a/image_utils.c +++ b/image_utils.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "image_utils.h" @@ -175,11 +176,13 @@ jpeg_memory_src(j_decompress_ptr cinfo, const unsigned char * buffer, size_t buf src->pub.bytes_in_buffer = bufsize; } +jmp_buf setjmp_buffer; /* Don't exit on error like libjpeg likes to do */ static void libjpeg_error_handler(j_common_ptr cinfo) { cinfo->err->output_message(cinfo); + longjmp(setjmp_buffer, 1); return; } @@ -258,6 +261,13 @@ image_new_from_jpeg(const char * path, int is_file, const char * buf, int size) { jpeg_memory_src(&cinfo, (const unsigned char *)buf, size); } + if( setjmp(setjmp_buffer) ) + { + jpeg_destroy_decompress(&cinfo); + if( is_file && file ) + fclose(file); + return NULL; + } jpeg_read_header(&cinfo, TRUE); cinfo.do_fancy_upsampling = FALSE; cinfo.do_block_smoothing = FALSE; diff --git a/metadata.c b/metadata.c index a82940c..b047743 100644 --- a/metadata.c +++ b/metadata.c @@ -414,6 +414,12 @@ GetImageMetadata(const char * path, char * name) fclose(infile); } + if( !width || !height ) + { + if( m.mime ) + free(m.mime); + return 0; + } if( width <= 640 && height <= 480 ) asprintf(&m.dlna_pn, "JPEG_SM;DLNA.ORG_OP=01;DLNA.ORG_CI=0"); else if( width <= 1024 && height <= 768 ) diff --git a/minidlna.c b/minidlna.c index 12ec468..f6a4f3f 100644 --- a/minidlna.c +++ b/minidlna.c @@ -883,6 +883,7 @@ shutdown: if (sudp >= 0) close(sudp); if (shttpl >= 0) close(shttpl); + if (sbeacon >= 0) close(sbeacon); if(SendSSDPGoodbye(snotify, n_lan_addr) < 0) {