From 77ec00b49563e14df247d5416f423e9cec56988a Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 11 Dec 2012 12:28:25 +0000 Subject: [PATCH] check for NaN etc. in XYZ2sRGB we were not checking for Inf, NaN etc. and this could cause array indexes to go out of range --- libvips/colour/LabQ2sRGB.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libvips/colour/LabQ2sRGB.c b/libvips/colour/LabQ2sRGB.c index c536b64a..06d9a6a1 100644 --- a/libvips/colour/LabQ2sRGB.c +++ b/libvips/colour/LabQ2sRGB.c @@ -264,6 +264,19 @@ vips_col_XYZ2sRGB( int range, int *lut, int Yi; float v; + /* XYZ can be Nan, Inf etc. Throw those values out, they will break + * our clipping. + */ + if( !isnormal( X ) || + !isnormal( Y ) || + !isnormal( Z ) ) { + *r = 0; + *g = 0; + *b = 0; + + return( -1 ); + } + /* Multiply through the matrix to get luminosity values. */ Yr = vips_mat_XYZ2RGB[0][0] * X +