Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fixed infinite loop and added checks for the sscanf result.
  • Loading branch information
dlemstra committed Jan 25, 2015
1 parent 44c2297 commit 97aa7d7
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions coders/hdr.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 97aa7d7

Please sign in to comment.