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