]> granicus.if.org Git - imagemagick/commitdiff
Don't update the nexus region on exception
authorCristy <urban-warrior@imagemagick.org>
Fri, 28 Dec 2018 18:31:26 +0000 (13:31 -0500)
committerCristy <urban-warrior@imagemagick.org>
Fri, 28 Dec 2018 18:31:26 +0000 (13:31 -0500)
MagickCore/cache.c

index 13bc7191f6bf41c6c5f68dce35b48ea290606eae..cd68535024773db39685c57b859e1d910647c536 100644 (file)
@@ -2706,7 +2706,7 @@ static inline MagickModulo VirtualPixelModulo(const ssize_t offset,
     normal default truncated modulo division.
   */
   modulo.quotient=offset/(ssize_t) extent;
-  if ((offset < 0L) && (modulo.quotient != INT64_MIN))
+  if ((offset < 0L) && (modulo.quotient > (ssize_t) (-SSIZE_MAX)))
     modulo.quotient--;
   modulo.remainder=(ssize_t) (offset-(double) modulo.quotient*extent);
   return(modulo);
@@ -5021,13 +5021,6 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info,
   assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->type == UndefinedCache)
     return((Quantum *) NULL);
-  if ((region->width == 0) || (region->height == 0))
-    return((Quantum *) NULL);
-  nexus_info->region=(*region);
-  number_pixels=(MagickSizeType) nexus_info->region.width*
-    nexus_info->region.height;
-  if (number_pixels == 0)
-    return((Quantum *) NULL);
   if (((cache_info->type == MemoryCache) || (cache_info->type == MapCache)) &&
       (buffered == MagickFalse))
     {
@@ -5035,14 +5028,12 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info,
         x,
         y;
 
-      x=nexus_info->region.x+(ssize_t) nexus_info->region.width-1;
-      y=nexus_info->region.y+(ssize_t) nexus_info->region.height-1;
-      if (((nexus_info->region.x >= 0) && (nexus_info->region.y >= 0) &&
-           (y < (ssize_t) cache_info->rows)) &&
-          (((nexus_info->region.x == 0) &&
-            (nexus_info->region.width == cache_info->columns)) ||
-           ((nexus_info->region.height == 1) &&
-            (x < (ssize_t) cache_info->columns))))
+      x=(ssize_t) region->width+region->x-1;
+      y=(ssize_t) region->height+region->y-1;
+      if (((region->x >= 0) &&
+           (region->y >= 0) && (y < (ssize_t) cache_info->rows)) &&
+          (((region->x == 0) && (region->width == cache_info->columns)) ||
+           ((region->height == 1) && (x < (ssize_t) cache_info->columns))))
         {
           MagickOffsetType
             offset;
@@ -5050,14 +5041,14 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info,
           /*
             Pixels are accessed directly from memory.
           */
-          offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+
-            nexus_info->region.x;
+          offset=(MagickOffsetType) region->y*cache_info->columns+region->x;
           nexus_info->pixels=cache_info->pixels+cache_info->number_channels*
             offset;
           nexus_info->metacontent=(void *) NULL;
           if (cache_info->metacontent_extent != 0)
             nexus_info->metacontent=(unsigned char *) cache_info->metacontent+
               offset*cache_info->metacontent_extent;
+          nexus_info->region=(*region);
           nexus_info->authentic_pixel_cache=MagickTrue;
           PrefetchPixelCacheNexusPixels(nexus_info,mode);
           return(nexus_info->pixels);
@@ -5066,14 +5057,19 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info,
   /*
     Pixels are stored in a staging region until they are synced to the cache.
   */
-  length=number_pixels*cache_info->number_channels*sizeof(*nexus_info->pixels);
+  number_pixels=(MagickSizeType) region->width*region->height;
+  length=MagickMax(number_pixels,cache_info->columns)*
+    cache_info->number_channels*sizeof(*nexus_info->pixels);
   if (cache_info->metacontent_extent != 0)
     length+=number_pixels*cache_info->metacontent_extent;
   if (nexus_info->cache == (Quantum *) NULL)
     {
       status=AcquireCacheNexusPixels(cache_info,length,nexus_info,exception);
       if (status == MagickFalse)
-        return((Quantum *) NULL);
+        {
+          (void) memset(&nexus_info->region,0,sizeof(nexus_info->region));
+          return((Quantum *) NULL);
+        }
     }
   else
     if (nexus_info->length < length)
@@ -5081,13 +5077,17 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info,
         RelinquishCacheNexusPixels(nexus_info);
         status=AcquireCacheNexusPixels(cache_info,length,nexus_info,exception);
         if (status == MagickFalse)
-          return((Quantum *) NULL);
+          {
+            (void) memset(&nexus_info->region,0,sizeof(nexus_info->region));
+            return((Quantum *) NULL);
+          }
       }
   nexus_info->pixels=nexus_info->cache;
   nexus_info->metacontent=(void *) NULL;
   if (cache_info->metacontent_extent != 0)
     nexus_info->metacontent=(void *) (nexus_info->pixels+
       cache_info->number_channels*number_pixels);
+  nexus_info->region=(*region);
   nexus_info->authentic_pixel_cache=cache_info->type == PingCache ?
     MagickTrue : MagickFalse;
   PrefetchPixelCacheNexusPixels(nexus_info,mode);