From 01acd32f8d40268116f0ffd7b8e2fdc5333dc8e1 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 21 Apr 2018 11:25:03 -0400 Subject: [PATCH] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7901 --- MagickCore/color.c | 184 ++++++++++++++++++++++----------------------- MagickCore/draw.c | 6 +- 2 files changed, 93 insertions(+), 97 deletions(-) diff --git a/MagickCore/color.c b/MagickCore/color.c index 12fedcbb2..59abad320 100644 --- a/MagickCore/color.c +++ b/MagickCore/color.c @@ -2402,7 +2402,7 @@ MagickExport MagickBooleanType QueryColorCompliance(const char *name, color->depth=8; } SetGeometryInfo(&geometry_info); - if (i >= strlen(name)) + if (i >= (ssize_t) strlen(name)) flags=ParseGeometry(name,&geometry_info); else flags=ParseGeometry(name+i+1,&geometry_info); @@ -2414,117 +2414,113 @@ MagickExport MagickBooleanType QueryColorCompliance(const char *name, ColorspaceType colorspaceType; + MagickBooleanType + status; + colorspaceType=color->colorspace; - if (i >= strlen(name)) + if (i >= (ssize_t) strlen(name)) colorname=AcquireString(name); else colorname=AcquireString(name+i+1); (void) SubstituteString(&colorname,")",""); - (void) QueryColorCompliance(colorname,AllCompliance,color,exception); + status=QueryColorCompliance(colorname,AllCompliance,color,exception); colorname=DestroyString(colorname); color->colorspace=colorspaceType; + return(status); } - else + if ((flags & PercentValue) != 0) + scale=(double) (QuantumRange/100.0); + if ((flags & RhoValue) != 0) + color->red=(double) ClampToQuantum((MagickRealType) (scale* + geometry_info.rho)); + if ((flags & SigmaValue) != 0) + color->green=(double) ClampToQuantum((MagickRealType) (scale* + geometry_info.sigma)); + if ((flags & XiValue) != 0) + color->blue=(double) ClampToQuantum((MagickRealType) (scale* + geometry_info.xi)); + color->alpha=(double) OpaqueAlpha; + if ((flags & PsiValue) != 0) + { + if (color->colorspace == CMYKColorspace) + color->black=(double) ClampToQuantum((MagickRealType) (scale* + geometry_info.psi)); + else + if (color->alpha_trait != UndefinedPixelTrait) + color->alpha=(double) ClampToQuantum(QuantumRange* + geometry_info.psi); + } + if (((flags & ChiValue) != 0) && + (color->alpha_trait != UndefinedPixelTrait)) + color->alpha=(double) ClampToQuantum(QuantumRange*geometry_info.chi); + if (color->colorspace == LabColorspace) { - if ((flags & PercentValue) != 0) - scale=(double) (QuantumRange/100.0); - if ((flags & RhoValue) != 0) - color->red=(double) ClampToQuantum((MagickRealType) (scale* - geometry_info.rho)); if ((flags & SigmaValue) != 0) - color->green=(double) ClampToQuantum((MagickRealType) (scale* - geometry_info.sigma)); + color->green=(MagickRealType) ClampToQuantum((MagickRealType) + (scale*geometry_info.sigma+(QuantumRange+1)/2.0)); if ((flags & XiValue) != 0) - color->blue=(double) ClampToQuantum((MagickRealType) (scale* - geometry_info.xi)); - color->alpha=(double) OpaqueAlpha; - if ((flags & PsiValue) != 0) - { - if (color->colorspace == CMYKColorspace) - color->black=(double) ClampToQuantum((MagickRealType) ( - scale*geometry_info.psi)); - else - if (color->alpha_trait != UndefinedPixelTrait) - color->alpha=(double) ClampToQuantum(QuantumRange* - geometry_info.psi); - } - if (((flags & ChiValue) != 0) && + color->blue=(MagickRealType) ClampToQuantum((MagickRealType) + (scale*geometry_info.xi+(QuantumRange+1)/2.0)); + } + if (LocaleCompare(colorspace,"gray") == 0) + { + color->green=color->red; + color->blue=color->red; + if (((flags & SigmaValue) != 0) && (color->alpha_trait != UndefinedPixelTrait)) color->alpha=(double) ClampToQuantum(QuantumRange* - geometry_info.chi); - if (color->colorspace == LabColorspace) + geometry_info.sigma); + if ((icc_color == MagickFalse) && + (color->colorspace == LinearGRAYColorspace)) { - if ((flags & SigmaValue) != 0) - color->green=(MagickRealType) ClampToQuantum((MagickRealType) - (scale*geometry_info.sigma+(QuantumRange+1)/2.0)); - if ((flags & XiValue) != 0) - color->blue=(MagickRealType) ClampToQuantum((MagickRealType) - (scale*geometry_info.xi+(QuantumRange+1)/2.0)); + color->colorspace=GRAYColorspace; + color->depth=8; } - if (LocaleCompare(colorspace,"gray") == 0) - { - color->green=color->red; - color->blue=color->red; - if (((flags & SigmaValue) != 0) && - (color->alpha_trait != UndefinedPixelTrait)) - color->alpha=(double) ClampToQuantum(QuantumRange* - geometry_info.sigma); - if ((icc_color == MagickFalse) && - (color->colorspace == LinearGRAYColorspace)) - { - color->colorspace=GRAYColorspace; - color->depth=8; - } - } - if ((LocaleCompare(colorspace,"HCL") == 0) || - (LocaleCompare(colorspace,"HSB") == 0) || - (LocaleCompare(colorspace,"HSL") == 0) || - (LocaleCompare(colorspace,"HWB") == 0)) - { - double - blue, - green, - red; + } + if ((LocaleCompare(colorspace,"HCL") == 0) || + (LocaleCompare(colorspace,"HSB") == 0) || + (LocaleCompare(colorspace,"HSL") == 0) || + (LocaleCompare(colorspace,"HWB") == 0)) + { + double + blue, + green, + red; - if (LocaleCompare(colorspace,"HCL") == 0) - color->colorspace=HCLColorspace; + if (LocaleCompare(colorspace,"HCL") == 0) + color->colorspace=HCLColorspace; + else + if (LocaleCompare(colorspace,"HSB") == 0) + color->colorspace=HSBColorspace; + else + if (LocaleCompare(colorspace,"HSL") == 0) + color->colorspace=HSLColorspace; else - if (LocaleCompare(colorspace,"HSB") == 0) - color->colorspace=HSBColorspace; - else - if (LocaleCompare(colorspace,"HSL") == 0) - color->colorspace=HSLColorspace; - else - if (LocaleCompare(colorspace,"HWB") == 0) - color->colorspace=HWBColorspace; - scale=1.0/255.0; - if ((flags & PercentValue) != 0) - scale=1.0/100.0; - geometry_info.sigma*=scale; - geometry_info.xi*=scale; - if (LocaleCompare(colorspace,"HCL") == 0) - ConvertHCLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0, - 360.0)/360.0,geometry_info.sigma,geometry_info.xi,&red, - &green,&blue); + if (LocaleCompare(colorspace,"HWB") == 0) + color->colorspace=HWBColorspace; + scale=1.0/255.0; + if ((flags & PercentValue) != 0) + scale=1.0/100.0; + geometry_info.sigma*=scale; + geometry_info.xi*=scale; + if (LocaleCompare(colorspace,"HCL") == 0) + ConvertHCLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/ + 360.0,geometry_info.sigma,geometry_info.xi,&red,&green,&blue); + else + if (LocaleCompare(colorspace,"HSB") == 0) + ConvertHSBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/ + 360.0,geometry_info.sigma,geometry_info.xi,&red,&green,&blue); + else + if (LocaleCompare(colorspace,"HSL") == 0) + ConvertHSLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/ + 360.0,geometry_info.sigma,geometry_info.xi,&red,&green,&blue); else - if (LocaleCompare(colorspace,"HSB") == 0) - ConvertHSBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0, - 360.0)/360.0,geometry_info.sigma,geometry_info.xi,&red, - &green,&blue); - else - if (LocaleCompare(colorspace,"HSL") == 0) - ConvertHSLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0, - 360.0)/360.0,geometry_info.sigma,geometry_info.xi,&red, - &green,&blue); - else - ConvertHWBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0, - 360.0)/360.0,geometry_info.sigma,geometry_info.xi,&red, - &green,&blue); - color->colorspace=sRGBColorspace; - color->red=(MagickRealType) red; - color->green=(MagickRealType) green; - color->blue=(MagickRealType) blue; - } + ConvertHWBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/ + 360.0,geometry_info.sigma,geometry_info.xi,&red,&green,&blue); + color->colorspace=sRGBColorspace; + color->red=(MagickRealType) red; + color->green=(MagickRealType) green; + color->blue=(MagickRealType) blue; } return(MagickTrue); } diff --git a/MagickCore/draw.c b/MagickCore/draw.c index 0fddf8ec7..3e229e9fc 100644 --- a/MagickCore/draw.c +++ b/MagickCore/draw.c @@ -2058,7 +2058,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, if (LocaleCompare("border-color",keyword) == 0) { GetNextToken(q,&q,extent,token); - (void) QueryColorCompliance(token,AllCompliance, + status&=QueryColorCompliance(token,AllCompliance, &graphic_context[n]->border_color,exception); break; } @@ -2768,7 +2768,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, break; } GetNextToken(q,&q,extent,token); - (void) QueryColorCompliance(token,AllCompliance,&stop_color, + status&=QueryColorCompliance(token,AllCompliance,&stop_color, exception); stops[number_stops-1].color=stop_color; GetNextToken(q,&q,extent,token); @@ -2972,7 +2972,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, if (LocaleCompare("text-undercolor",keyword) == 0) { GetNextToken(q,&q,extent,token); - (void) QueryColorCompliance(token,AllCompliance, + status&=QueryColorCompliance(token,AllCompliance, &graphic_context[n]->undercolor,exception); break; } -- 2.40.0