7c98bb
Using an array to clamp translated YCbCr values is insecure, because if the
7c98bb
TIFF file contains bogus ReferenceBlackWhite parameters, the computed RGB
7c98bb
values could be very far out of range (much further than the current array
7c98bb
size, anyway), possibly resulting in SIGSEGV.  Just drop the whole idea in
7c98bb
favor of using a comparison-based macro to clamp.  See RH bug #583081.
7c98bb
7c98bb
Filed upstream at http://bugzilla.maptools.org/show_bug.cgi?id=2208
7c98bb
7c98bb
7c98bb
diff -Naur tiff-3.9.2.orig/libtiff/tif_color.c tiff-3.9.2/libtiff/tif_color.c
7c98bb
--- tiff-3.9.2.orig/libtiff/tif_color.c	2006-02-09 10:42:20.000000000 -0500
7c98bb
+++ tiff-3.9.2/libtiff/tif_color.c	2010-06-10 15:53:24.000000000 -0400
7c98bb
@@ -183,13 +183,18 @@
7c98bb
 TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr,
7c98bb
 	       uint32 *r, uint32 *g, uint32 *b)
7c98bb
 {
7c98bb
+	int32 i;
7c98bb
+
7c98bb
 	/* XXX: Only 8-bit YCbCr input supported for now */
7c98bb
 	Y = HICLAMP(Y, 255), Cb = CLAMP(Cb, 0, 255), Cr = CLAMP(Cr, 0, 255);
7c98bb
 
7c98bb
-	*r = ycbcr->clamptab[ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr]];
7c98bb
-	*g = ycbcr->clamptab[ycbcr->Y_tab[Y]
7c98bb
-	    + (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT)];
7c98bb
-	*b = ycbcr->clamptab[ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb]];
7c98bb
+	i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr];
7c98bb
+	*r = CLAMP(i, 0, 255);
7c98bb
+	i = ycbcr->Y_tab[Y]
7c98bb
+	    + (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT);
7c98bb
+	*g = CLAMP(i, 0, 255);
7c98bb
+	i = ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb];
7c98bb
+	*b = CLAMP(i, 0, 255);
7c98bb
 }
7c98bb
 
7c98bb
 /*