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