]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Sun, 5 Aug 2018 21:29:37 +0000 (17:29 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sun, 5 Aug 2018 21:29:37 +0000 (17:29 -0400)
coders/xbm.c

index bae47c8e59f5583a07412f0bd2c47dd369aa86c6..0cc82339f1a5b37a5fe8c6aae62076dcb0e41c6a 100644 (file)
@@ -180,6 +180,10 @@ static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   int
     c;
 
+  long
+    height,
+    width;
+
   MagickBooleanType
     status;
 
@@ -206,11 +210,9 @@ static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     bit,
     byte,
     bytes_per_line,
-    height,
     length,
     padding,
-    version,
-    width;
+    version;
 
   /*
     Open image file.
@@ -236,17 +238,19 @@ static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   height=0;
   *name='\0';
   while (ReadBlobString(image,buffer) != (char *) NULL)
-    if (sscanf(buffer,"#define %1024s %u",name,&width) == 2)
+    if (sscanf(buffer,"#define %1024s %ld",name,&width) == 2)
       if ((strlen(name) >= 6) &&
           (LocaleCompare(name+strlen(name)-6,"_width") == 0))
         break;
   while (ReadBlobString(image,buffer) != (char *) NULL)
-    if (sscanf(buffer,"#define %1024s %u",name,&height) == 2)
+    if (sscanf(buffer,"#define %1024s %ld",name,&height) == 2)
       if ((strlen(name) >= 7) &&
           (LocaleCompare(name+strlen(name)-7,"_height") == 0))
         break;
-  image->columns=width;
-  image->rows=height;
+  if ((width <= 0) || (height <= 0) || (EOFBlob(image) != MagickFalse))
+    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+  image->columns=(size_t) width;
+  image->rows=(size_t) height;
   image->depth=8;
   image->storage_class=PseudoClass;
   image->colors=2;
@@ -274,9 +278,6 @@ static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     if (LocaleCompare("bits[]",(char *) p) == 0)
       break;
   }
-  if ((image->columns == 0) || (image->rows == 0) ||
-      (EOFBlob(image) != MagickFalse))
-    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   /*
     Initialize image structure.
   */