From 1fc5f599f1e15e76e7bdf378bc994e6fed38e1fa Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Mon, 22 Aug 2011 18:24:19 +0000 Subject: [PATCH] * Fix a crash when scanning images without read access. (SF bug #3395670) --- image_utils.c | 2 +- metadata.c | 29 ++++++++++++++++------------- scanner.c | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/image_utils.c b/image_utils.c index 79b4625..c6b9abd 100644 --- a/image_utils.c +++ b/image_utils.c @@ -482,7 +482,7 @@ image_new_from_jpeg(const char * path, int is_file, const char * buf, int size, if(cinfo.output_components == 3) { ofs = 0; - if((ptr = (unsigned char *)malloc(w * 3 * cinfo.rec_outbuf_height + 8)) == NULL) + if((ptr = (unsigned char *)malloc(w * 3 * cinfo.rec_outbuf_height + 16)) == NULL) { DPRINTF(E_WARN, L_METADATA, "malloc failed\n"); image_free(vimage); diff --git a/metadata.c b/metadata.c index ef419ae..0f698d0 100644 --- a/metadata.c +++ b/metadata.c @@ -592,19 +592,22 @@ no_exifdata: if( image_get_jpeg_resolution(path, &width, &height) != 0 || !width || !height ) { infile = fopen(path, "r"); - cinfo.err = jpeg_std_error(&jerr); - jerr.error_exit = libjpeg_error_handler; - jpeg_create_decompress(&cinfo); - if( setjmp(setjmp_buffer) ) - goto error; - jpeg_stdio_src(&cinfo, infile); - jpeg_read_header(&cinfo, TRUE); - jpeg_start_decompress(&cinfo); - width = cinfo.output_width; - height = cinfo.output_height; - error: - jpeg_destroy_decompress(&cinfo); - fclose(infile); + if( infile ) + { + cinfo.err = jpeg_std_error(&jerr); + jerr.error_exit = libjpeg_error_handler; + jpeg_create_decompress(&cinfo); + if( setjmp(setjmp_buffer) ) + goto error; + jpeg_stdio_src(&cinfo, infile); + jpeg_read_header(&cinfo, TRUE); + jpeg_start_decompress(&cinfo); + width = cinfo.output_width; + height = cinfo.output_height; + error: + jpeg_destroy_decompress(&cinfo); + fclose(infile); + } } //DEBUG DPRINTF(E_DEBUG, L_METADATA, " * resolution: %dx%d\n", width, height); diff --git a/scanner.c b/scanner.c index 594d9d9..6dabe49 100644 --- a/scanner.c +++ b/scanner.c @@ -779,7 +779,7 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type) sprintf(parent_id, "%s$%X", (parent ? parent:""), i+startID); ScanDirectory(full_path, parent_id, dir_type); } - else if( type == TYPE_FILE ) + else if( type == TYPE_FILE && (access(full_path, R_OK|X_OK) == 0) ) { if( insert_file(name, full_path, (parent ? parent:""), i+startID) == 0 ) fileno++;