Control: tag -1 patch pending

Attaching imported patch with DEP-3 header.
Description: Segmentation Fault: vips 7.28.5-1 with jpeg compression
 commit 996f26ec7011f6eb1aad4c204100d0f0970e2cad
 Author: John Cupitt <jcup...@gmail.com>
 Date:   Fri Dec 13 15:03:16 2013 +0000
 
     fix a tiff write crash
     
     see
     
     http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=714984
     https://github.com/jcupitt/libvips/issues/88
Bug-Debian: http://bugs.debian.org/714984
Reviewed-by: Mathieu Malaterre <ma...@debian.org>

Index: vips-7.28.5/ChangeLog
===================================================================
--- vips-7.28.5.orig/ChangeLog	2012-05-06 13:29:26.000000000 +0200
+++ vips-7.28.5/ChangeLog	2013-12-14 10:47:03.610487401 +0100
@@ -1,3 +1,6 @@
+13/12/13 started 7.28.5-1
+- fix jpeg tiff write, see https://github.com/jcupitt/libvips/issues/88
+
 19/4/12 started 7.28.5
 - ifthenelse blend mode was broken
 - small blend speedup
Index: vips-7.28.5/libvips/foreign/vips2tiff.c
===================================================================
--- vips-7.28.5.orig/libvips/foreign/vips2tiff.c	2012-05-06 13:29:26.000000000 +0200
+++ vips-7.28.5/libvips/foreign/vips2tiff.c	2013-12-14 10:47:03.610487401 +0100
@@ -126,6 +126,8 @@
  * 2/12/11
  * 	- make into a simple function call ready to be wrapped as a new-style
  * 	  VipsForeign class
+ * 7/8/12
+ * 	- be more cautious enabling YCbCr mode
  */
 
 /*
@@ -452,15 +454,9 @@
 	TIFFSetField( tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT );
 	TIFFSetField( tif, TIFFTAG_COMPRESSION, tw->compression );
 
-	if( tw->compression == COMPRESSION_JPEG ) {
+	if( tw->compression == COMPRESSION_JPEG ) 
 		TIFFSetField( tif, TIFFTAG_JPEGQUALITY, tw->jpqual );
 
-		/* Enable rgb->ycbcr conversion in the jpeg write. See also
-		 * the photometric selection below.
-		 */
-		TIFFSetField( tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );
-	}
-
 	if( tw->predictor != -1 ) 
 		TIFFSetField( tif, TIFFTAG_PREDICTOR, tw->predictor );
 
@@ -518,12 +514,17 @@
 					TIFFTAG_INKSET, INKSET_CMYK );
 			}
 			else if( tw->compression == COMPRESSION_JPEG &&
-				tw->im->Bands == 3 ) 
+				tw->im->Bands == 3 &&
+				tw->im->BandFmt == VIPS_FORMAT_UCHAR ) { 
 				/* This signals to libjpeg that it can do
 				 * YCbCr chrominance subsampling from RGB, not
 				 * that we will supply the image as YCbCr.
 				 */
 				photometric = PHOTOMETRIC_YCBCR;
+				TIFFSetField( tif, 
+					TIFFTAG_JPEGCOLORMODE, 
+					JPEGCOLORMODE_RGB );
+			}
 			else
 				photometric = PHOTOMETRIC_RGB;
 
@@ -1340,9 +1341,27 @@
 	/* TIFFTAG_JPEGQUALITY is a pesudo-tag, so we can't copy it.
 	 * Set explicitly from TiffWrite.
 	 */
-	if( tw->compression == COMPRESSION_JPEG ) 
+	if( tw->compression == COMPRESSION_JPEG ) {
 		TIFFSetField( out, TIFFTAG_JPEGQUALITY, tw->jpqual );
 
+		/* Only for three-band, 8-bit images.
+		 */
+		if( tw->im->Bands == 3 &&
+			tw->im->BandFmt == VIPS_FORMAT_UCHAR ) { 
+			/* Enable rgb->ycbcr conversion in the jpeg write. 
+			 */
+			TIFFSetField( out, 
+				TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );
+
+			/* And we want ycbcr expanded to rgb on read. 
+			 * Otherwise TIFFTileSize() will give us the size of 
+			 * a chrominance subsampled tile.
+			 */
+			TIFFSetField( in, 
+				TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );
+		   }
+	}
+
 	/* We can't copy profiles :( Set again from TiffWrite.
 	 */
 	if( embed_profile( tw, out ) )

Reply via email to