]> granicus.if.org Git - imagemagick/commitdiff
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5340
authorCristy <urban-warrior@imagemagick.org>
Sun, 4 Feb 2018 19:47:52 +0000 (14:47 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sun, 4 Feb 2018 19:47:52 +0000 (14:47 -0500)
MagickCore/blob.c
coders/sixel.c

index 44de6502c1f52192237ac7e6a3fb972db4532c30..db5dbf227faf48aa7fc4955cd094c5672538d25d 100644 (file)
@@ -4536,36 +4536,31 @@ MagickExport const void *ReadBlobStream(Image *image,const size_t length,
 */
 MagickExport char *ReadBlobString(Image *image,char *string)
 {
-  register const unsigned char
-    *p;
+  int
+    c;
 
   register ssize_t
     i;
 
-  ssize_t
-    count;
-
-  unsigned char
-    buffer[1];
-
   assert(image != (Image *) NULL);
   assert(image->signature == MagickCoreSignature);
   for (i=0; i < (MagickPathExtent-1L); i++)
   {
-    p=(const unsigned char *) ReadBlobStream(image,1,buffer,&count);
-    if (count != 1)
+    c=ReadBlobByte(image);
+    if (c == EOF)
       {
         if (i == 0)
           return((char *) NULL);
-        string[i]='\0';
         break;
       }
-    string[i]=(char) (*p);
-    if ((string[i] == '\r') || (string[i] == '\n'))
-      break;
+    string[i]=c;
+    if (c == '\n')
+      {
+        if ((i > 0) && (string[i-1] == '\r'))
+          i--;
+        break;
+      }
   }
-  if (string[i] == '\r')
-    (void) ReadBlobStream(image,1,buffer,&count);
   string[i]='\0';
   return(string);
 }
index 1e682fd2f6528b0afde5304bb93deeff21ee96d5..c972e05ae32407e65be0d01b6cbf3a6e0043a5a3 100644 (file)
@@ -226,12 +226,14 @@ static unsigned char *get_params(unsigned char *p, int *param, int *len)
 }
 
 /* convert sixel data into indexed pixel bytes and palette data */
-MagickBooleanType sixel_decode(unsigned char              /* in */  *p,         /* sixel bytes */
+MagickBooleanType sixel_decode(Image *image,
+                               unsigned char              /* in */  *p,         /* sixel bytes */
                                unsigned char              /* out */ **pixels,   /* decoded pixels */
                                size_t                     /* out */ *pwidth,    /* image width */
                                size_t                     /* out */ *pheight,   /* image height */
                                unsigned char              /* out */ **palette,  /* ARGB palette */
-                               size_t                     /* out */ *ncolors    /* palette size (<= 256) */)
+                               size_t                     /* out */ *ncolors,    /* palette size (<= 256) */
+  ExceptionInfo *exception)
 {
     int n, i, r, g, b, sixel_vertical_mask, c;
     int posision_x, posision_y;
@@ -259,6 +261,8 @@ MagickBooleanType sixel_decode(unsigned char              /* in */  *p,
 
     imsx = 2048;
     imsy = 2048;
+    if (SetImageExtent(image,imsx,imsy,exception) == MagickFalse)
+      return(MagickFalse);
     imbuf = (unsigned char *) AcquireQuantumMemory(imsx , imsy);
 
     if (imbuf == NULL) {
@@ -360,6 +364,8 @@ MagickBooleanType sixel_decode(unsigned char              /* in */  *p,
             if (imsx < attributed_ph || imsy < attributed_pv) {
                 dmsx = imsx > attributed_ph ? imsx : attributed_ph;
                 dmsy = imsy > attributed_pv ? imsy : attributed_pv;
+                if (SetImageExtent(image,dmsx,dmsy,exception) == MagickFalse)
+                  break;
                 dmbuf = (unsigned char *) AcquireQuantumMemory(dmsx , dmsy);
                 if (dmbuf == (unsigned char *) NULL) {
                     imbuf = (unsigned char *) RelinquishMagickMemory(imbuf);
@@ -436,6 +442,8 @@ MagickBooleanType sixel_decode(unsigned char              /* in */  *p,
 
                 dmsx = nx;
                 dmsy = ny;
+                if (SetImageExtent(image,dmsx,dmsy,exception) == MagickFalse)
+                  break;
                 dmbuf = (unsigned char *) AcquireQuantumMemory(dmsx , dmsy);
                 if (dmbuf == (unsigned char *) NULL) {
                     imbuf = (unsigned char *) RelinquishMagickMemory(imbuf);
@@ -531,6 +539,11 @@ MagickBooleanType sixel_decode(unsigned char              /* in */  *p,
     if (imsx > max_x || imsy > max_y) {
         dmsx = max_x;
         dmsy = max_y;
+        if (SetImageExtent(image,dmsx,dmsy,exception) == MagickFalse)
+          {
+            imbuf = (unsigned char *) RelinquishMagickMemory(imbuf);
+            return (MagickFalse);
+          }
         if ((dmbuf = (unsigned char *) AcquireQuantumMemory(dmsx , dmsy)) == NULL) {
             imbuf = (unsigned char *) RelinquishMagickMemory(imbuf);
             return (MagickFalse);
@@ -1041,7 +1054,7 @@ static Image *ReadSIXELImage(const ImageInfo *image_info,ExceptionInfo *exceptio
   /*
     Decode SIXEL
   */
-  if (sixel_decode((unsigned char *) sixel_buffer,&sixel_pixels,&image->columns,&image->rows,&sixel_palette,&image->colors) == MagickFalse)
+  if (sixel_decode(image,(unsigned char *) sixel_buffer,&sixel_pixels,&image->columns,&image->rows,&sixel_palette,&image->colors,exception) == MagickFalse)
     {
       sixel_buffer=(char *) RelinquishMagickMemory(sixel_buffer);
       ThrowReaderException(CorruptImageError,"CorruptImage");