From: dirk Date: Sun, 25 Jan 2015 07:27:09 +0000 (+0000) Subject: Fixed infinite loop and added checks for the sscanf result. X-Git-Tag: 7.0.1-0~1369 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97aa7d7cfd2027f6ba7ce42caf8b798541b9cdc6;p=imagemagick Fixed infinite loop and added checks for the sscanf result. --- diff --git a/coders/hdr.c b/coders/hdr.c index ccea76391..cd07f22e7 100644 --- a/coders/hdr.c +++ b/coders/hdr.c @@ -274,7 +274,7 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception) if (value_expected == MagickFalse) continue; p=value; - while ((c != '\n') && (c != '\0')) + while ((c != '\n') && (c != '\0') && (c != EOF)) { if ((size_t) (p-value) < (MaxTextExtent-1)) *p++=c; @@ -319,18 +319,20 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception) chromaticity[6], white_point[2]; - (void) sscanf(value,"%g %g %g %g %g %g %g %g", - &chromaticity[0],&chromaticity[1],&chromaticity[2], - &chromaticity[3],&chromaticity[4],&chromaticity[5], - &white_point[0],&white_point[1]); - image->chromaticity.red_primary.x=chromaticity[0]; - image->chromaticity.red_primary.y=chromaticity[1]; - image->chromaticity.green_primary.x=chromaticity[2]; - image->chromaticity.green_primary.y=chromaticity[3]; - image->chromaticity.blue_primary.x=chromaticity[4]; - image->chromaticity.blue_primary.y=chromaticity[5]; - image->chromaticity.white_point.x=white_point[0], - image->chromaticity.white_point.y=white_point[1]; + if (sscanf(value,"%g %g %g %g %g %g %g %g",&chromaticity[0], + &chromaticity[1],&chromaticity[2],&chromaticity[3], + &chromaticity[4],&chromaticity[5],&white_point[0], + &white_point[1]) == 8) + { + image->chromaticity.red_primary.x=chromaticity[0]; + image->chromaticity.red_primary.y=chromaticity[1]; + image->chromaticity.green_primary.x=chromaticity[2]; + image->chromaticity.green_primary.y=chromaticity[3]; + image->chromaticity.blue_primary.x=chromaticity[4]; + image->chromaticity.blue_primary.y=chromaticity[5]; + image->chromaticity.white_point.x=white_point[0], + image->chromaticity.white_point.y=white_point[1]; + } break; } (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword); @@ -349,9 +351,11 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception) height, width; - (void) sscanf(value,"%d +X %d",&height,&width); - image->columns=(size_t) width; - image->rows=(size_t) height; + if (sscanf(value,"%d +X %d",&height,&width) == 2) + { + image->columns=(size_t) width; + image->rows=(size_t) height; + } break; } (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword);