From 6ff1d5320b111a526224f4ade070b8e65313f4cf Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 20 Jan 2015 16:55:35 +0000 Subject: [PATCH] don't call jpeg_finish_decompress() all it does is verify the trailing bytes in the file see https://github.com/lovell/sharp/issues/151 --- libvips/foreign/jpeg2vips.c | 24 +++++++----------------- libvips/foreign/vips2tiff.c | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index da4f4028..a5fb2610 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -61,6 +61,9 @@ * - support "none" as a resolution unit * 16/10/14 * - add "autorotate" option + * 20/1/15 + * - don't call jpeg_finish_decompress(), all it does is read and check + * the tail of the file */ /* @@ -153,10 +156,6 @@ typedef struct _ReadJpeg { ErrorManager eman; gboolean invert_pels; - /* Set if we need to finish the decompress. - */ - gboolean decompressing; - /* Track the y pos during a read with this. */ int y_pos; @@ -191,14 +190,10 @@ readjpeg_free( ReadJpeg *jpeg ) jpeg->eman.pub.num_warnings = 0; } - if( jpeg->decompressing ) { - /* jpeg_finish_decompress() can fail ... catch any errors. - */ - if( !setjmp( jpeg->eman.jmp ) ) - jpeg_finish_decompress( &jpeg->cinfo ); - - jpeg->decompressing = FALSE; - } + /* Don't call jpeg_finish_decompress(). It just checks the tail of the + * file and who cares about that. All mem is freed in + * jpeg_destroy_decompress(). + */ VIPS_FREEF( fclose, jpeg->eman.fp ); VIPS_FREE( jpeg->filename ); @@ -231,7 +226,6 @@ readjpeg_new( VipsImage *out, jpeg->fail = fail; jpeg->readbehind = readbehind; jpeg->filename = NULL; - jpeg->decompressing = FALSE; jpeg->cinfo.err = jpeg_std_error( &jpeg->eman.pub ); jpeg->eman.pub.error_exit = vips__new_error_exit; jpeg->eman.pub.output_message = vips__new_output_message; @@ -1024,11 +1018,7 @@ read_jpeg_image( ReadJpeg *jpeg, VipsImage *out ) if( read_jpeg_header( jpeg, t[0] ) ) return( -1 ); - /* Set decompressing to make readjpeg_free() call - * jpeg_stop_decompress(). - */ jpeg_start_decompress( cinfo ); - jpeg->decompressing = TRUE; #ifdef DEBUG printf( "read_jpeg_image: starting decompress\n" ); diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index c0003807..986cfc60 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -1496,7 +1496,7 @@ tiff_copy( TiffWrite *tw, TIFF *out, TIFF *in ) /* Enable rgb->ycbcr conversion in the jpeg write. */ if( !tw->rgbjpeg && - tw->jpqual >= 90 ) + tw->jpqual < 90 ) TIFFSetField( out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );